35 lines
839 B
Plaintext
35 lines
839 B
Plaintext
class Vector
|
|
declare x
|
|
declare y
|
|
|
|
def Vector(x, y)
|
|
this.x = float(x)
|
|
this.y = float(y)
|
|
end
|
|
|
|
def operator+(other)
|
|
return new(Vector, this.x + other.x, this.y + other.y)
|
|
end
|
|
|
|
def operator-(other)
|
|
return new(Vector, this.x - other.x, this.y - other.y)
|
|
end
|
|
|
|
def operator/(val)
|
|
return new(Vector, this.x / val, this.y / val)
|
|
end
|
|
|
|
def operator*(val)
|
|
return new(Vector, this.x * val, this.y * val)
|
|
end
|
|
|
|
def toString()
|
|
return format("[%s, %s]", this.x, this.y)
|
|
end
|
|
end
|
|
|
|
println new(Vector, 5, 7) + new(Vector, 2, 3)
|
|
println new(Vector, 5, 7) - new(Vector, 2, 3)
|
|
println new(Vector, 5, 7) * 11
|
|
println new(Vector, 5, 7) / 2
|