added Rect

This commit is contained in:
Djeeberjr 2022-03-04 00:58:35 +01:00
parent 1aa3b43d8c
commit bddb80c42d

33
src/util/Rect.hx Normal file
View File

@ -0,0 +1,33 @@
package util;
import util.Vec.Vec2;
class Rect {
private final tr:Vec2<Int>;
private final bl:Vec2<Int>;
public function new(p1: Vec2<Int>,p2:Vec2<Int>) {
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<Int>): Bool {
return (p.x >= bl.x && p.x <= tr.x) && (p.y >= bl.y && p.y <= tr.y);
}
public function isOutside(p: Vec2<Int>): Bool {
return !this.isInside(p);
}
}