diff --git a/joml-geometry/src/main/java/org/terasology/joml/geom/Rectangled.java b/joml-geometry/src/main/java/org/terasology/joml/geom/Rectangled.java
index b694a15..cedcd76 100644
--- a/joml-geometry/src/main/java/org/terasology/joml/geom/Rectangled.java
+++ b/joml-geometry/src/main/java/org/terasology/joml/geom/Rectangled.java
@@ -91,6 +91,28 @@ public Rectangled(double minX, double minY, double maxX, double maxY) {
this.maxY = maxY;
}
+ /**
+ * Create a new {@link Rectangled} of size zero at the given point.
+ *
+ * @param x the x coordinate of both minimum and maximum corner
+ * @param y the y coordinate of both minimum and maximum corner
+ */
+ public Rectangled(double x, double y) {
+ this.minX = x;
+ this.minY = y;
+ this.maxX = x;
+ this.maxY = y;
+ }
+
+ /**
+ * Create a new {@link Rectangled} of size zero at the given point.
+ *
+ * @param point the coordinate of both minimum and maximum corner
+ */
+ public Rectangled(Vector2dc point) {
+ this(point.x(), point.y());
+ }
+
@Override
public double minX() {
return this.minX;
@@ -170,6 +192,31 @@ public Rectangled set(Rectangled source){
return this;
}
+ /**
+ * Set this rectangle to the given point (x, y)
with zero size.
+ *
+ * @param x the x coordinate of both minimum and maximum corner
+ * @param y the y coordinate of both minimum and maximum corner
+ * @return this
+ */
+ public Rectangled set(double x, double y) {
+ this.minX = x;
+ this.minY = y;
+ this.maxX = x;
+ this.maxY = y;
+ return this;
+ }
+
+ /**
+ * Set this rectangle to the given point
with zero size.
+ *
+ * @param point the coordinate of both minimum and maximum corner
+ * @return this
+ */
+ public Rectangled set(Vector2fc point) {
+ return set(point.x(), point.y());
+ }
+
/**
* Set the minimum corner coordinates.
*
diff --git a/joml-geometry/src/main/java/org/terasology/joml/geom/Rectanglef.java b/joml-geometry/src/main/java/org/terasology/joml/geom/Rectanglef.java
index 62df84a..52f1ea0 100644
--- a/joml-geometry/src/main/java/org/terasology/joml/geom/Rectanglef.java
+++ b/joml-geometry/src/main/java/org/terasology/joml/geom/Rectanglef.java
@@ -48,8 +48,7 @@ public Rectanglef() {
/**
* Create a new {@link Rectanglef} as a copy of the given source
.
*
- * @param source
- * the {@link Rectanglef} to copy from
+ * @param source the {@link Rectanglef} to copy from
*/
public Rectanglef(Rectanglef source) {
this.minX = source.minX;
@@ -61,10 +60,8 @@ public Rectanglef(Rectanglef source) {
/**
* Create a new {@link Rectanglef} with the given min
and max
corner coordinates.
*
- * @param min
- * the minimum coordinates
- * @param max
- * the maximum coordinates
+ * @param min the minimum coordinates
+ * @param max the maximum coordinates
*/
public Rectanglef(Vector2fc min, Vector2fc max) {
this.minX = min.x();
@@ -76,14 +73,10 @@ public Rectanglef(Vector2fc min, Vector2fc max) {
/**
* Create a new {@link Rectanglef} with the given minimum and maximum corner coordinates.
*
- * @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
+ * @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
*/
public Rectanglef(float minX, float minY, float maxX, float maxY) {
this.minX = minX;
@@ -92,6 +85,28 @@ public Rectanglef(float minX, float minY, float maxX, float maxY) {
this.maxY = maxY;
}
+ /**
+ * Create a new {@link Rectanglef} of size zero at the given point.
+ *
+ * @param x the x coordinate of both minimum and maximum corner
+ * @param y the y coordinate of both minimum and maximum corner
+ */
+ public Rectanglef(float x, float y) {
+ this.minX = x;
+ this.minY = y;
+ this.maxX = x;
+ this.maxY = y;
+ }
+
+ /**
+ * Create a new {@link Rectanglef} of size zero at the given point.
+ *
+ * @param point the coordinate of both minimum and maximum corner
+ */
+ public Rectanglef(Vector2fc point) {
+ this(point.x(), point.y());
+ }
+
@Override
public float minX() {
return this.minX;
@@ -114,28 +129,27 @@ public float maxY() {
public boolean containsRectangle(Rectangledc rectangle) {
return rectangle.minX() >= minX() && rectangle.maxX() <= maxX() &&
- rectangle.minY() >= minY() && rectangle.maxY() <= maxY();
+ rectangle.minY() >= minY() && rectangle.maxY() <= maxY();
}
public boolean containsRectangle(Rectanglefc rectangle) {
return rectangle.minX() >= minX() && rectangle.maxX() <= maxX() &&
- rectangle.minY() >= minY() && rectangle.maxY() <= maxY();
+ rectangle.minY() >= minY() && rectangle.maxY() <= maxY();
}
public boolean containsRectangle(Rectanglei rectangle) {
return rectangle.minX >= minX() && rectangle.maxX <= maxX() &&
- rectangle.minY >= minY() && rectangle.maxY <= maxY();
+ rectangle.minY >= minY() && rectangle.maxY <= maxY();
}
/**
- * Set this {@link Rectanglei} to be a clone of source
.
+ * Set this rectangle to be a clone of source
.
*
- * @param source
- * the {@link Rectanglei} to copy from
+ * @param source the {@link Rectanglei} to copy from
* @return this
*/
- public Rectanglef set(Rectanglef source){
+ public Rectanglef set(Rectanglef source) {
this.minX = source.minX;
this.minY = source.minY;
this.maxX = source.maxX;
@@ -143,13 +157,36 @@ public Rectanglef set(Rectanglef source){
return this;
}
+ /**
+ * Set this rectangle to the given point (x, y)
with zero size.
+ *
+ * @param x the x coordinate of both minimum and maximum corner
+ * @param y the y coordinate of both minimum and maximum corner
+ * @return this
+ */
+ public Rectanglef set(float x, float y) {
+ this.minX = x;
+ this.minY = y;
+ this.maxX = x;
+ this.maxY = y;
+ return this;
+ }
+
+ /**
+ * Set this rectangle to the given point
with zero size.
+ *
+ * @param point the coordinate of both minimum and maximum corner
+ * @return this
+ */
+ public Rectanglef set(Vector2fc point) {
+ return set(point.x(), point.y());
+ }
+
/**
* Set the minimum corner coordinates.
*
- * @param minX
- * the x coordinate of the minimum corner
- * @param minY
- * the y coordinate of the minimum corner
+ * @param minX the x coordinate of the minimum corner
+ * @param minY the y coordinate of the minimum corner
* @return this
*/
public Rectanglef setMin(float minX, float minY) {
@@ -161,8 +198,7 @@ public Rectanglef setMin(float minX, float minY) {
/**
* Set the minimum corner coordinates.
*
- * @param min
- * the minimum coordinates
+ * @param min the minimum coordinates
* @return this
*/
public Rectanglef setMin(Vector2fc min) {
@@ -175,10 +211,8 @@ public Rectanglef setMin(Vector2fc min) {
/**
* Set the maximum corner coordinates.
*
- * @param maxX
- * the x coordinate of the maximum corner
- * @param maxY
- * the y coordinate of the maximum corner
+ * @param maxX the x coordinate of the maximum corner
+ * @param maxY the y coordinate of the maximum corner
* @return this
*/
public Rectanglef setMax(float maxX, float maxY) {
@@ -190,8 +224,7 @@ public Rectanglef setMax(float maxX, float maxY) {
/**
* Set the maximum corner coordinates.
*
- * @param max
- * the maximum coordinates
+ * @param max the maximum coordinates
* @return this
*/
public Rectanglef setMax(Vector2fc max) {
@@ -276,10 +309,8 @@ public float area() {
/**
* Set this
to the union of this
and the given point p
.
*
- * @param x
- * the x coordinate of the point
- * @param y
- * the y coordinate of the point
+ * @param x the x coordinate of the point
+ * @param y the y coordinate of the point
* @return this
*/
public Rectanglef union(float x, float y) {
@@ -289,8 +320,7 @@ public Rectanglef union(float x, float y) {
/**
* Set this
to the union of this
and the given point p
.
*
- * @param p
- * the point
+ * @param p the point
* @return this
*/
public Rectanglef union(Vector2fc p) {
@@ -314,8 +344,7 @@ public Rectanglef union(Vector2ic p, Rectanglef dest) {
/**
* Set this
to the union of this
and other
.
*
- * @param other
- * the other {@link Rectanglef}
+ * @param other the other {@link Rectanglef}
* @return this
*/
public Rectanglef union(Rectanglef other) {
@@ -334,33 +363,31 @@ public Rectanglef union(Rectanglef other, Rectanglef dest) {
/**
* Check if this and the given rectangle intersect.
*
- * @param other
- * the other rectangle
+ * @param other the other rectangle
* @return true
iff both rectangles intersect; false
otherwise
*/
@Override
public boolean intersectsRectangle(Rectangled other) {
return minX < other.maxX && maxX > other.minX &&
- maxY > other.minY && minY < other.maxY;
+ maxY > other.minY && minY < other.maxY;
}
/**
* Check if this and the given rectangle intersect.
*
- * @param other
- * the other rectangle
+ * @param other the other rectangle
* @return true
iff both rectangles intersect; false
otherwise
*/
@Override
public boolean intersectsRectangle(Rectanglef other) {
return minX < other.maxX && maxX > other.minX &&
- maxY > other.minY && minY < other.maxY;
+ maxY > other.minY && minY < other.maxY;
}
@Override
public boolean intersectsRectangle(Rectanglei other) {
return minX < other.maxX && maxX > other.minX &&
- maxY > other.minY && minY < other.maxY;
+ maxY > other.minY && minY < other.maxY;
}
private Rectanglef validate() {
@@ -380,11 +407,9 @@ public boolean isValid() {
/**
* Compute the rectangle of intersection between this
and the given rectangle.
*
- * If the two rectangles do not intersect, then {@link Float#NaN} is stored in each component
- * of dest
.
+ * If the two rectangles do not intersect, then {@link Float#NaN} is stored in each component of dest
.
*
- * @param other
- * the other rectangle
+ * @param other the other rectangle
* @return this
*/
public Rectanglef intersection(Rectanglef other) {
@@ -394,11 +419,9 @@ public Rectanglef intersection(Rectanglef other) {
/**
* Compute the rectangle of intersection between this
and the given rectangle.
*
- * If the two rectangles do not intersect, then {@link Float#NaN} is stored in each component
- * of dest
.
+ * If the two rectangles do not intersect, then {@link Float#NaN} is stored in each component of dest
.
*
- * @param other
- * the other rectangle
+ * @param other the other rectangle
* @return this
*/
public Rectanglef intersection(Rectanglei other) {
@@ -426,8 +449,7 @@ public Rectanglef intersection(Rectanglei other, Rectanglef dest) {
/**
* Return the length of this rectangle in the X and Y dimensions and store the result in dest
.
*
- * @param dest
- * will hold the result
+ * @param dest will hold the result
* @return dest
* @deprecated use {@link #getSize(Vector2f)}
*/
@@ -448,8 +470,7 @@ public boolean containsPoint(float x, float y) {
/**
* Translate this
by the given vector xy
.
*
- * @param xy
- * the vector to translate by
+ * @param xy the vector to translate by
* @return this
*/
public Rectanglef translate(Vector2fc xy) {
@@ -464,10 +485,8 @@ public Rectanglef translate(Vector2fc xy, Rectanglef dest) {
/**
* Translate this
by the vector (x, y)
.
*
- * @param x
- * the x coordinate to translate by
- * @param y
- * the y coordinate to translate by
+ * @param x the x coordinate to translate by
+ * @param y the y coordinate to translate by
* @return this
*/
public Rectanglef translate(float x, float y) {
@@ -487,8 +506,7 @@ public Rectanglef translate(float x, float y, Rectanglef dest) {
/**
* Scale this
about the origin.
*
- * @param sf
- * the scaling factor in the x and y axis
+ * @param sf the scaling factor in the x and y axis
* @return this
*/
public Rectanglef scale(float sf) {
@@ -505,12 +523,9 @@ public Rectanglef scale(float sf, Rectanglef dest) {
*
* This is equivalent to translate(-ax, -ay).scale(sf).translate(ax, ay)
*
- * @param sf
- * the scaling factor in the x and y axis
- * @param ax
- * the x coordinate of the anchor
- * @param ay
- * the y coordinate of the anchor
+ * @param sf the scaling factor in the x and y axis
+ * @param ax the x coordinate of the anchor
+ * @param ay the y coordinate of the anchor
* @return this
*/
public Rectanglef scale(float sf, float ax, float ay) {
@@ -527,10 +542,8 @@ public Rectanglef scale(float sf, float ax, float ay, Rectanglef dest) {
*
* This is equivalent to translate(anchor.negate()).scale(sf).translate(anchor.negate())
*
- * @param sf
- * the scaling factor in the x and y axis
- * @param anchor
- * the location of the anchor
+ * @param sf the scaling factor in the x and y axis
+ * @param anchor the location of the anchor
* @return this
*/
public Rectanglef scale(float sf, Vector2fc anchor) {
@@ -545,10 +558,8 @@ public Rectanglef scale(float sf, Vector2fc anchor, Rectanglef dest) {
/**
* Scale this
about the origin.
*
- * @param sx
- * the scaling factor on the x axis
- * @param sy
- * the scaling factor on the y axis
+ * @param sx the scaling factor on the x axis
+ * @param sy the scaling factor on the y axis
* @return this
*/
public Rectanglef scale(float sx, float sy) {
@@ -565,14 +576,10 @@ public Rectanglef scale(float sx, float sy, Rectanglef dest) {
*
* This is equivalent to translate(-ax, -ay).scale(sx, sy).translate(ax, ay)
*
- * @param sx
- * the scaling factor on the x axis
- * @param sy
- * the scaling factor on the y axis
- * @param ax
- * the x coordinate of the anchor
- * @param ay
- * the y coordinate of the anchor
+ * @param sx the scaling factor on the x axis
+ * @param sy the scaling factor on the y axis
+ * @param ax the x coordinate of the anchor
+ * @param ay the y coordinate of the anchor
* @return this
*/
public Rectanglef scale(float sx, float sy, float ax, float ay) {
@@ -588,12 +595,9 @@ public Rectanglef scale(float sx, float sy, float ax, float ay) {
*
* This is equivalent to translate(anchor.negate()).scale(sx, sy).translate(anchor.negate())
*
- * @param sx
- * the scaling factor on the x axis
- * @param sy
- * the scaling factor on the y axis
- * @param anchor
- * the location of the anchor
+ * @param sx the scaling factor on the x axis
+ * @param sy the scaling factor on the y axis
+ * @param anchor the location of the anchor
* @return this
*/
public Rectanglef scale(float sx, float sy, Vector2fc anchor) {
@@ -647,7 +651,8 @@ public boolean equals(Object obj) {
/**
* Return a string representation of this rectangle.
*
- * This method creates a new {@link DecimalFormat} on every invocation with the format string "0.000E0;-
".
+ * This method creates a new {@link DecimalFormat} on every invocation with the format string
+ * "0.000E0;-
".
*
* @return the string representation
*/
@@ -656,15 +661,15 @@ public String toString() {
}
/**
- * Return a string representation of this rectangle by formatting the vector components with the given {@link NumberFormat}.
+ * Return a string representation of this rectangle by formatting the vector components with the given {@link
+ * NumberFormat}.
*
- * @param formatter
- * the {@link NumberFormat} used to format the vector components with
+ * @param formatter the {@link NumberFormat} used to format the vector components with
* @return the string representation
*/
public String toString(NumberFormat formatter) {
return "(" + Runtime.format(minX, formatter) + " " + Runtime.format(minY, formatter) + ") < "
- + "(" + Runtime.format(maxX, formatter) + " " + Runtime.format(maxY, formatter) + ")";
+ + "(" + Runtime.format(maxX, formatter) + " " + Runtime.format(maxY, formatter) + ")";
}
public void writeExternal(ObjectOutput out) throws IOException {
diff --git a/joml-geometry/src/test/java/org/terasology/joml/geom/RectangledTest.java b/joml-geometry/src/test/java/org/terasology/joml/geom/RectangledTest.java
index fe3f542..68633c1 100644
--- a/joml-geometry/src/test/java/org/terasology/joml/geom/RectangledTest.java
+++ b/joml-geometry/src/test/java/org/terasology/joml/geom/RectangledTest.java
@@ -58,4 +58,11 @@ public void testZeroSizeRectangle() {
Rectangled rect = new Rectangled(0, 0, 0, 0);
assertFalse(rect.isValid());
}
+
+ @Test
+ public void testRectangleFromPoint() {
+ Rectangled rect = new Rectangled(1,1);
+ assertFalse(rect.isValid());
+ assertFalse(rect.containsPoint(1,1));
+ }
}
diff --git a/joml-geometry/src/test/java/org/terasology/joml/geom/RectanglefTest.java b/joml-geometry/src/test/java/org/terasology/joml/geom/RectanglefTest.java
index 54b96a0..824aef9 100644
--- a/joml-geometry/src/test/java/org/terasology/joml/geom/RectanglefTest.java
+++ b/joml-geometry/src/test/java/org/terasology/joml/geom/RectanglefTest.java
@@ -60,4 +60,11 @@ public void testZeroSizeRectangle() {
Rectanglef rect = new Rectanglef(0, 0, 0, 0);
assertFalse(rect.isValid());
}
+
+ @Test
+ public void testRectangleFromPoint() {
+ Rectanglef rect = new Rectanglef(1,1);
+ assertFalse(rect.isValid());
+ assertFalse(rect.containsPoint(1,1));
+ }
}