motion/joybox-ios/common/cg_point.rb in joybox-1.0.0 vs motion/joybox-ios/common/cg_point.rb in joybox-1.1.0
- old
+ new
@@ -1,44 +1,74 @@
class CGPoint
- 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)
+ def ==(other)
+ other.is_a?(CGPoint) && CGPointEqualToPoint(self, other)
end
+ def +(other)
+ case other
+ when Numeric
+ return CGPointMake(self.x + other, self.y + other)
+ when 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 CGPoint
+ return CGPointMake(self.x * other.x, self.y * other.y)
+ end
+ end
- def - (point)
-
- CGPointMake(self.x - point.x, self.y - point.y)
+ def /(other)
+ case other
+ when Numeric
+ return CGPointMake(self.x / other, self.y / other)
+ when CGPoint
+ return CGPointMake(self.x / other.x, self.y / other.y)
+ end
end
+ def half
+ self / 2
+ end
+
end
\ No newline at end of file