lib/vector3.rb in gmath3D-0.2.1 vs lib/vector3.rb in gmath3D-0.2.2

- old
+ new

@@ -35,13 +35,22 @@ # [Input] # _rhs_ should be Vector3. # [Output] # return true if rhs equals myself. def ==(rhs) + return false if( !rhs.kind_of?(Vector3) ) equals_inner(rhs) end + # For using Vector3 as hash key + def hash + [@x.to_f, @y.to_f, @z.to_f].hash + end + def eql?(rhs) + equals_inner(rhs) + end + # [Input] # _rhs_ should be Vector3. # [Output] # return added result as Vector3. def +(rhs) @@ -167,10 +176,9 @@ return Matrix.column_vector([x,y,z]) end private def equals_inner(rhs) - return false if( !rhs.kind_of?(Vector3) ) return false if((self.x - rhs.x).abs > @tolerance) return false if((self.y - rhs.y).abs > @tolerance) return false if((self.z - rhs.z).abs > @tolerance) true end