diff --git a/src/util/Rect.hx b/src/util/Rect.hx new file mode 100644 index 0000000..d7a848d --- /dev/null +++ b/src/util/Rect.hx @@ -0,0 +1,33 @@ +package util; + +import util.Vec.Vec2; + +class Rect { + + private final tr:Vec2; + private final bl:Vec2; + + public function new(p1: Vec2,p2:Vec2) { + this.tr = { + x: MathI.max(p1.x,p2.x), + y: MathI.max(p1.y,p2.y) + }; + + this.bl = { + x: MathI.min(p1.x,p2.x), + y: MathI.min(p1.y,p2.y) + }; + } + + public function getSize(): Int { + return (tr.x - bl.x) * (tr.y - bl.y); + } + + public function isInside(p: Vec2): Bool { + return (p.x >= bl.x && p.x <= tr.x) && (p.y >= bl.y && p.y <= tr.y); + } + + public function isOutside(p: Vec2): Bool { + return !this.isInside(p); + } +}