CabinGame/Luxe/math/vector.wren

81 lines
1.2 KiB
Text
Raw Normal View History

2020-08-16 13:59:43 +00:00
class Vector {
x{_x}
x=(val){_x = val}
y{_y}
y=(val){_y = val}
list{[x, y]}
construct new(x, y){
_x = x
_y = y
}
construct new(list){
_x = list.x
_y = list.x
}
construct new(){
_x = 0
_y = 0
}
invert_x(){
_x = -_x
return this
}
invert_y(){
_y = -_y
return this
}
or_lt(one, other){
return one.x < other.x || one.y < other.y
}
or_gt(one, other){
return one.x > other.x || one.y > other.y
}
+(other){
if(other is Vector) {
return Vector.new(x + other.x, y + other.y)
}
}
-(other){
return Vector.new(x - other.x, y - other.y)
}
*(other){
if(other is Vector){
return Vector.new(x * other.x, y * other.y)
}
if(other is Num) {
return Vector.new(x * other, y * other)
}
}
/(other){
if(other is Vector) {
return Vector.new(x / other.x, y / other.y)
}
if(other is Num) {
return Vector.new(x / other, y / other)
}
}
<(other){
return x < other.x && y < other.y
}
>(other){
return x > other.x && y > other.y
}
}