Replaced Vertex struct with Vector class

This commit is contained in:
2019-02-20 11:00:42 -06:00
parent 7b903fbdb9
commit a6e175d9e0
6 changed files with 59 additions and 10 deletions

52
lib/math/vector.rb Normal file
View File

@@ -0,0 +1,52 @@
class IMICFPS
class Vector
attr_accessor :x, :y, :z, :weight
def initialize(x = 0, y = 0, z = 0, weight = 0)
@x, @y, @z, @weight = x, y, z, weight
end
def ==(other)
@x == other.x &&
@y == other.y &&
@z == other.z &&
@weight == other.weight
end
def +(other)
@x += other.x
@y += other.y
@z += other.z
@weight += other.weight
end
def -(other)
@x -= other.x
@y -= other.y
@z -= other.z
@weight -= other.weight
end
def *(other)
@x *= other.x
@y *= other.y
@z *= other.z
@weight *= other.weight
end
def /(other)
@x /= other.x
@y /= other.y
@z /= other.z
@weight /= other.weight
end
def to_a
[@x, @y, @z, @weight]
end
def to_s
"X: #{@x}, Y: #{@y}, Z: #{@z}, Weight: #{@weight}"
end
end
end