|
@@ -1,25 +1,31 @@
|
|
|
package h2d.col;
|
|
|
|
|
|
class Bounds {
|
|
|
-
|
|
|
+
|
|
|
public var xMin : Float;
|
|
|
public var yMin : Float;
|
|
|
|
|
|
public var xMax : Float;
|
|
|
public var yMax : Float;
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
+ public var x(get, set) : Float;
|
|
|
+ public var y(get, set) : Float;
|
|
|
+ public var width(get, set) : Float;
|
|
|
+ public var height(get, set) : Float;
|
|
|
+
|
|
|
public inline function new() {
|
|
|
empty();
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public inline function collide( b : Bounds ) {
|
|
|
return !(xMin > b.xMax || yMin > b.yMax || xMax < b.xMin || yMax < b.yMin);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public inline function include( p : Point ) {
|
|
|
return p.x >= xMin && p.x < xMax && p.y >= yMin && p.y < yMax;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public inline function add( b : Bounds ) {
|
|
|
if( b.xMin < xMin ) xMin = b.xMin;
|
|
|
if( b.xMax > xMax ) xMax = b.xMax;
|
|
@@ -33,7 +39,7 @@ class Bounds {
|
|
|
if( p.y < yMin ) yMin = p.y;
|
|
|
if( p.y > yMax ) yMax = p.y;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public inline function setMin( p : Point ) {
|
|
|
xMin = p.x;
|
|
|
yMin = p.y;
|
|
@@ -43,14 +49,14 @@ class Bounds {
|
|
|
xMax = p.x;
|
|
|
yMax = p.y;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public function load( b : Bounds ) {
|
|
|
xMin = b.xMin;
|
|
|
yMin = b.yMin;
|
|
|
xMax = b.xMax;
|
|
|
yMax = b.yMax;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public function scaleCenter( v : Float ) {
|
|
|
var dx = (xMax - xMin) * 0.5 * v;
|
|
|
var dy = (yMax - yMin) * 0.5 * v;
|
|
@@ -61,18 +67,18 @@ class Bounds {
|
|
|
xMax = mx + dx * v;
|
|
|
yMax = my + dy * v;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public inline function offset( dx : Float, dy : Float ) {
|
|
|
xMin += dx;
|
|
|
xMax += dx;
|
|
|
yMin += dy;
|
|
|
yMax += dy;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public inline function getMin() {
|
|
|
return new Point(xMin, yMin);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public inline function getCenter() {
|
|
|
return new Point((xMin + xMax) * 0.5, (yMin + yMax) * 0.5);
|
|
|
}
|
|
@@ -80,11 +86,11 @@ class Bounds {
|
|
|
public inline function getSize() {
|
|
|
return new Point(xMax - xMin, yMax - yMin);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public inline function getMax() {
|
|
|
return new Point(xMax, yMax);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public inline function empty() {
|
|
|
xMin = 1e20;
|
|
|
yMin = 1e20;
|
|
@@ -98,7 +104,7 @@ class Bounds {
|
|
|
xMax = 1e20;
|
|
|
yMax = 1e20;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public inline function clone() {
|
|
|
var b = new Bounds();
|
|
|
b.xMin = xMin;
|
|
@@ -107,7 +113,41 @@ class Bounds {
|
|
|
b.yMax = yMax;
|
|
|
return b;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
+ inline function get_x() {
|
|
|
+ return xMin;
|
|
|
+ }
|
|
|
+
|
|
|
+ inline function get_y() {
|
|
|
+ return yMin;
|
|
|
+ }
|
|
|
+
|
|
|
+ inline function set_x(x) {
|
|
|
+ return xMin = x;
|
|
|
+ }
|
|
|
+
|
|
|
+ inline function set_y(y) {
|
|
|
+ return yMin = y;
|
|
|
+ }
|
|
|
+
|
|
|
+ inline function get_width() {
|
|
|
+ return xMax - xMin;
|
|
|
+ }
|
|
|
+
|
|
|
+ inline function get_height() {
|
|
|
+ return yMax - yMin;
|
|
|
+ }
|
|
|
+
|
|
|
+ inline function set_width(w) {
|
|
|
+ xMax = xMin + w;
|
|
|
+ return w;
|
|
|
+ }
|
|
|
+
|
|
|
+ inline function set_height(h) {
|
|
|
+ yMax = yMin + h;
|
|
|
+ return h;
|
|
|
+ }
|
|
|
+
|
|
|
public function toString() {
|
|
|
return "{" + getMin() + "," + getMax() + "}";
|
|
|
}
|
|
@@ -120,12 +160,12 @@ class Bounds {
|
|
|
b.yMax = y0 + height;
|
|
|
return b;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public static inline function fromPoints( min : Point, max : Point ) {
|
|
|
var b = new Bounds();
|
|
|
b.setMin(min);
|
|
|
b.setMax(max);
|
|
|
return b;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
}
|