|
@@ -66,6 +66,22 @@ class Bounds {
|
|
|
return p.x >= xMin && p.x < xMax && p.y >= yMin && p.y < yMax;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Same as distance but does not perform sqrt
|
|
|
+ */
|
|
|
+ public inline function distanceSq( p : Point ) {
|
|
|
+ var dx = p.x < xMin ? xMin - p.x : p.x > xMax ? p.x - xMax : 0.;
|
|
|
+ var dy = p.y < yMin ? yMin - p.y : p.y > yMax ? p.y - yMax : 0.;
|
|
|
+ return dx * dx + dy * dy;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Returns the distance betwen the point and the bounds. Or 0 if the point is inside the bounds.
|
|
|
+ */
|
|
|
+ public inline function distance( p : Point ) {
|
|
|
+ return Math.sqrt(distanceSq(p));
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
Adds Bounds `b` to the Bounds, expanding min/max when necessary.
|
|
|
**/
|