Sha256: 7a38ef59402c5093f5ea12f6b5eb8c7cf4a6c16cdf0982ea1ab7d340fde7b7ab

Contents?: true

Size: 1.42 KB

Versions: 2

Compression:

Stored size: 1.42 KB

Contents

# We need this class to help the framework recognize 
# CGPointMake
CGPoint = ATSPoint

class ATSPoint

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

  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 /(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 half
    self / 2
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
joybox-1.1.1 motion/joybox-osx/common/ats_point.rb
joybox-1.1.0 motion/joybox-osx/common/ats_point.rb