From bddb80c42d122fc4d7ef5a0c38b65108a75b1fd5 Mon Sep 17 00:00:00 2001 From: Djeeberjr Date: Fri, 4 Mar 2022 00:58:35 +0100 Subject: [PATCH] added Rect --- src/util/Rect.hx | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/util/Rect.hx 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); + } +}