Sha256: e0c1386eb939476a9d36c207b4f441816db2cb0f696350da22a95746cb486829

Contents?: true

Size: 1.3 KB

Versions: 2

Compression:

Stored size: 1.3 KB

Contents

class CGPoint

  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_local_coordinates(node)
    node.convertToWorldSpace(self)
  end

  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 -@
    CGPointMake(-x, -y)   
  end

  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 /(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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
joybox-1.1.1 motion/joybox-ios/common/cg_point.rb
joybox-1.1.0 motion/joybox-ios/common/cg_point.rb