motion/joybox-osx/common/ats_point.rb in joybox-1.0.0 vs motion/joybox-osx/common/ats_point.rb in joybox-1.1.0
- old
+ new
@@ -1,48 +1,78 @@
# We need this class to help the framework recognize
# CGPointMake
-class CGPoint; end
+CGPoint = ATSPoint
class ATSPoint
- def to_opengl_coordinates
+ def coerce(other)
+ [self, other]
+ end
+ def to_opengl_coordinates
Joybox.director.convertToGL(self)
end
-
def from_opengl_coordinates
-
Joybox.director.convertToUI(self)
end
+ def from_pixel_coordinates
+ CGPointMake(self.x.from_pixels, self.y.from_pixels)
+ end
def to_pixel_coordinates
-
CGPointMake(self.x.to_pixels, self.y.to_pixels)
end
+ def to_local_coordinates(node)
+ node.convertToNodeSpace(self)
+ end
- def from_pixel_coordinates
-
- CGPointMake(self.x.from_pixels, self.y.from_pixels)
+ def from_local_coordinates(node)
+ node.convertToWorldSpace(self)
end
-
def == (point)
-
- point.is_a?(CGPoint) && CGPointEqualToPoint(self, point)
+ point.is_a?(ATSPoint) && CGPointEqualToPoint(self, point)
end
+ def +(other)
+ case other
+ when Numeric
+ return CGPointMake(self.x + other, self.y + other)
+ when ATSPoint || CGPoint
+ return CGPointMake(self.x + other.x, self.y + other.y)
+ end
+ end
- def + (point)
+ def -@
+ CGPointMake(-x, -y)
+ end
- CGPointMake(self.x + point.x, self.y + point.y)
+ def -(other)
+ self.+(-other)
end
+ def *(other)
+ case other
+ when Numeric
+ return CGPointMake(self.x * other, self.y * other)
+ when ATSPoint || CGPoint
+ return CGPointMake(self.x * other.x, self.y * other.y)
+ end
+ end
- def - (point)
+ def /(other)
+ case other
+ when Numeric
+ return CGPointMake(self.x / other, self.y / other)
+ when ATSPoint || CGPoint
+ return CGPointMake(self.x / other.x, self.y / other.y)
+ end
+ end
- CGPointMake(self.x - point.x, self.y - point.y)
+ def half
+ self / 2
end
end
\ No newline at end of file