63 lines
1.1 KiB
Text
63 lines
1.1 KiB
Text
|
|
import "math/vector" for Vector
|
||
|
|
|
||
|
|
class AABB{
|
||
|
|
x{_x}
|
||
|
|
y{_y}
|
||
|
|
|
||
|
|
x=(val){_x = val}
|
||
|
|
y=(val){_y = val}
|
||
|
|
|
||
|
|
width {_width}
|
||
|
|
height {_height}
|
||
|
|
|
||
|
|
width=(val){_width = val}
|
||
|
|
height=(val){_height = val}
|
||
|
|
|
||
|
|
min_x{_x}
|
||
|
|
min_y{_y}
|
||
|
|
max_x{_x + _width}
|
||
|
|
max_y{_y + _height}
|
||
|
|
|
||
|
|
|
||
|
|
min{Vector.new(min_x, min_y)}
|
||
|
|
max{Vector.new(max_x, max_y)}
|
||
|
|
|
||
|
|
center{(min + max) / 2}
|
||
|
|
pos{min}
|
||
|
|
pos=(val){
|
||
|
|
_x = val.x
|
||
|
|
_y = val.y
|
||
|
|
}
|
||
|
|
size{Vector.new(_width, _height)}
|
||
|
|
|
||
|
|
pos_size_list{[x, y, width, height]}
|
||
|
|
min_max_list{[min_x, min_y, max_x, max_y]}
|
||
|
|
|
||
|
|
construct new(){}
|
||
|
|
|
||
|
|
construct new(x, y, width, height){
|
||
|
|
_x = x
|
||
|
|
_y = y
|
||
|
|
_width = width
|
||
|
|
_height = height
|
||
|
|
}
|
||
|
|
|
||
|
|
construct min_max(min, max){
|
||
|
|
min_max(min.x, min.y, max.x, max.y)
|
||
|
|
}
|
||
|
|
|
||
|
|
construct min_max(min_x, min_y, max_x, max_y){
|
||
|
|
_x = min_x
|
||
|
|
_y = min_y
|
||
|
|
_width = max_x - min_x
|
||
|
|
_height = max_y - min_y
|
||
|
|
}
|
||
|
|
|
||
|
|
static intersects(one, other){
|
||
|
|
return one.max > other.min && one.min < other.max
|
||
|
|
}
|
||
|
|
|
||
|
|
static contains(one, other){
|
||
|
|
return one.max > other.max && one.min < other.min
|
||
|
|
}
|
||
|
|
}
|