Tidied javadocs, generated double implementation.

This commit is contained in:
Michael Bayne
2011-12-20 19:09:19 -08:00
parent 15224b8185
commit c9c336309b
2 changed files with 51 additions and 10 deletions
@@ -30,4 +30,42 @@ public class Rectangles
double y2 = Math.max(src1.maxY(), src2.maxY());
dst.setBounds(x1, y1, x2 - x1, y2 - y1);
}
/**
* Computes the point inside the bounds of the rectangle that's closest to the given point,
* writing the result into {@code out}.
* @return {@code out} for call chaining convenience.
*/
public static Point closestInteriorPoint (IRectangle r, IPoint p, Point out) {
out.set(MathUtil.clamp(p.x(), r.minX(), r.maxX()),
MathUtil.clamp(p.y(), r.minY(), r.maxY()));
return out;
}
/**
* Computes and returns the point inside the bounds of the rectangle that's closest to the
* given point.
*/
public static Point closestInteriorPoint (IRectangle r, IPoint p) {
return closestInteriorPoint(r, p, new Point());
}
/**
* Returns the squared Euclidean distance between the given point and the nearest point inside
* the bounds of the given rectangle. If the supplied point is inside the rectangle, the
* distance will be zero.
*/
public static double pointRectDistanceSq (IRectangle r, IPoint p) {
Point p2 = closestInteriorPoint(r, p);
return Points.distanceSq(p.x(), p.y(), p2.x, p2.y);
}
/**
* Returns the Euclidean distance between the given point and the nearest point inside the
* bounds of the given rectangle. If the supplied point is inside the rectangle, the distance
* will be zero.
*/
public static double pointRectDistance (IRectangle r, IPoint p) {
return Math.sqrt(pointRectDistanceSq(r, p));
}
}
+13 -10
View File
@@ -30,28 +30,30 @@ public class Rectangles
float y2 = Math.max(src1.maxY(), src2.maxY());
dst.setBounds(x1, y1, x2 - x1, y2 - y1);
}
/**
* Computes the Point on the rectangle that's closest to the given point, writing
the result int {@code out}
* Computes the point inside the bounds of the rectangle that's closest to the given point,
* writing the result into {@code out}.
* @return {@code out} for call chaining convenience.
*/
public static Point closestInteriorPoint (IRectangle r, IPoint p, Point out)
{
public static Point closestInteriorPoint (IRectangle r, IPoint p, Point out) {
out.set(MathUtil.clamp(p.x(), r.minX(), r.maxX()),
MathUtil.clamp(p.y(), r.minY(), r.maxY()));
return out;
}
/**
* Computes the Point on the rectangle that's closest to the given point
* Computes and returns the point inside the bounds of the rectangle that's closest to the
* given point.
*/
public static Point closestInteriorPoint (IRectangle r, IPoint p) {
return closestInteriorPoint(r, p, new Point());
}
/**
* Returns the squared Euclidean distance between the given point and the nearest point on the
* given rectangle.
* Returns the squared Euclidean distance between the given point and the nearest point inside
* the bounds of the given rectangle. If the supplied point is inside the rectangle, the
* distance will be zero.
*/
public static float pointRectDistanceSq (IRectangle r, IPoint p) {
Point p2 = closestInteriorPoint(r, p);
@@ -59,8 +61,9 @@ public class Rectangles
}
/**
* Returns the Euclidean distance between the given point and the nearest point on the
* given rectangle.
* Returns the Euclidean distance between the given point and the nearest point inside the
* bounds of the given rectangle. If the supplied point is inside the rectangle, the distance
* will be zero.
*/
public static float pointRectDistance (IRectangle r, IPoint p) {
return FloatMath.sqrt(pointRectDistanceSq(r, p));