Skip to content

Commit

Permalink
Add documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
mbastian committed Jun 12, 2024
1 parent a33dc12 commit 64dd136
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 1 deletion.
55 changes: 54 additions & 1 deletion src/main/java/org/gephi/graph/api/Rect2D.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,39 @@ public Rect2D(float minX, float minY, float maxX, float maxY) {
this.maxY = maxY;
}

/**
* Return the rectangle's width.
*
* @return the rectangle's width
*/
public float width() {
return maxX - minX;
}

/**
* Return the rectangle's height.
*
* @return the rectangle's height
*/
public float height() {
return maxY - minY;
}

/**
* Return the rectangle's center, as an array where the first element is the x
* coordinate and the second element is the y coordinate.
*
* @return the rectangle's center
*/
public float[] center() {
return new float[] { (maxX + minX) / 2, (maxY + minY) / 2 };
}

/**
* Return the rectangle's radius.
*
* @return the rectangle's radius
*/
public float radius() {
float width = width();
float height = height();
Expand All @@ -92,11 +113,17 @@ public String toString() {
return toString(FORMAT);
}

public String toString(NumberFormat formatter) {
private String toString(NumberFormat formatter) {
return "(" + formatter.format(minX) + " " + formatter.format(minY) + ") < " + "(" + formatter
.format(maxX) + " " + formatter.format(maxY) + ")";
}

/**
* Returns true if this rectangle contains the given rectangle.
*
* @param rect the rectangle to check
* @return true if this rectangle contains, false otherwise
*/
public boolean contains(Rect2D rect) {
if (rect == this) {
return true;
Expand All @@ -105,6 +132,12 @@ public boolean contains(Rect2D rect) {
return contains(rect.minX, rect.minY, rect.maxX, rect.maxY);
}

/**
* Returns true if this rectangle intersects the given rectangle.
*
* @param rect the rectangle to check
* @return true if this rectangle intersects, false otherwise
*/
public boolean intersects(Rect2D rect) {
if (rect == this) {
return true;
Expand All @@ -113,10 +146,30 @@ public boolean intersects(Rect2D rect) {
return intersects(rect.minX, rect.minY, rect.maxX, rect.maxY);
}

/**
* Returns true if this rectangle contains the given rectangle.
*
* @param minX the x coordinate of the minimum corner
* @param minY the y coordinate of the minimum corner
* @param maxX the x coordinate of the maximum corner
* @param maxY the y coordinate of the maximum corner
*
* @return true if this rectangle contains, false otherwise
*/
public boolean contains(float minX, float minY, float maxX, float maxY) {
return this.minX <= minX && this.minY <= minY && this.maxX >= maxX && this.maxY >= maxY;
}

/**
* Returns true if this rectangle intersects the given rectangle.
*
* @param minX the x coordinate of the minimum corner
* @param minY the y coordinate of the minimum corner
* @param maxX the x coordinate of the maximum corner
* @param maxY the y coordinate of the maximum corner
*
* @return true if this rectangle intersects, false otherwise
*/
public boolean intersects(float minX, float minY, float maxX, float maxY) {
return this.minX <= maxX && minX <= this.maxX && this.maxY >= minY && maxY >= this.minY;
}
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/org/gephi/graph/api/SpatialIndex.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,19 @@
*/
public interface SpatialIndex {

/**
* Returns the nodes in the given area.
*
* @param rect area to query
* @return nodes in the area
*/
NodeIterable getNodesInArea(Rect2D rect);

/**
* Returns the edges in the given area.
*
* @param rect area to query
* @return edges in the area
*/
EdgeIterable getEdgesInArea(Rect2D rect);
}

0 comments on commit 64dd136

Please sign in to comment.