CabinGame/Luxe/math/vector.wren

111 lines
1.7 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(arg){
if(arg is Num){
_x = arg
_y = arg
} else {
_x = arg.x
_y = arg.y
}
2020-08-16 13:59:43 +00:00
}
construct new(){
_x = 0
_y = 0
}
floor(){
_x = _x.floor
_y = _y.floor
return this
}
2020-08-16 13:59:43 +00:00
invert_x(){
_x = -_x
return this
}
invert_y(){
_y = -_y
return this
}
2020-08-18 21:16:04 +00:00
static or_lt(one, other){
2020-08-16 13:59:43 +00:00
return one.x < other.x || one.y < other.y
}
2020-08-18 21:16:04 +00:00
static or_gt(one, other){
2020-08-16 13:59:43 +00:00
return one.x > other.x || one.y > other.y
}
y0(){
_y = 0
return this
}
x0(){
_x = 0
return this
}
2020-08-16 13:59:43 +00:00
+(other){
if(other is Num) {
return Vector.new(x + other, y + other)
2020-08-16 13:59:43 +00:00
}
return Vector.new(x + other.x, y + other.y)
2020-08-16 13:59:43 +00:00
}
-(other){
return Vector.new(x - other.x, y - other.y)
}
*(other){
2020-08-18 21:16:04 +00:00
if(other is Vector || other is List){
2020-08-16 13:59:43 +00:00
return Vector.new(x * other.x, y * other.y)
}
if(other is Num) {
return Vector.new(x * other, y * other)
}
}
/(other){
2020-08-18 21:16:04 +00:00
if(other is Vector || other is List) {
2020-08-16 13:59:43 +00:00
return Vector.new(x / other.x, y / other.y)
}
if(other is Num) {
return Vector.new(x / other, y / other)
}
}
2020-08-18 21:16:04 +00:00
%(other){
if(other is Vector || other is List) {
return Vector.new(x % other.x, y % other.y)
}
if(other is Num) {
return Vector.new(x % other, y % other)
}
}
2020-08-16 13:59:43 +00:00
<(other){
return x < other.x && y < other.y
}
>(other){
return x > other.x && y > other.y
}
}