added Rect
This commit is contained in:
parent
1aa3b43d8c
commit
bddb80c42d
33
src/util/Rect.hx
Normal file
33
src/util/Rect.hx
Normal 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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user