class CGPoint
Public Class Methods
make(options = {})
click to toggle source
CGPoint.make
(x: 10, y: 30)
# File lib/geomotion/cg_point.rb, line 4 def self.make(options = {}) CGPoint.new(options[:x] || 0, options[:y] || 0) end
Public Instance Methods
*(scale)
click to toggle source
Calls superclass method
# File lib/geomotion/cg_point.rb, line 65 def *(scale) case scale when Numeric return CGPoint.new(self.x * scale, self.y * scale) else super end end
+(other)
click to toggle source
operator
# File lib/geomotion/cg_point.rb, line 54 def +(other) case other when CGSize return self.rect_of_size(other) when CGPoint return CGPoint.new(self.x + other.x, self.y + other.y) when CGRect return CGPoint.new(self.x + other.origin.x, self.y + other.origin.y).rect_of_size(other.size) end end
-(other)
click to toggle source
# File lib/geomotion/cg_point.rb, line 93 def -(other) self.+(-other) end
-@()
click to toggle source
# File lib/geomotion/cg_point.rb, line 89 def -@ CGPoint.new(-self.x, -self.y) end
/(scale)
click to toggle source
it is tempting to define this as self * (1.0/scale) but floating point errors result in too many errors
Calls superclass method
# File lib/geomotion/cg_point.rb, line 76 def /(scale) case scale when Numeric return CGPoint.new(self.x / scale, self.y / scale) else super end end
==(point)
click to toggle source
# File lib/geomotion/cg_point.rb, line 85 def ==(point) point.is_a?(CGPoint) && CGPointEqualToPoint(self, point) end
angle_to(point)
click to toggle source
# File lib/geomotion/cg_point.rb, line 47 def angle_to(point) dx = point.x - self.x dy = point.y - self.y return Math.atan2(dy, dx) end
distance_to(point)
click to toggle source
# File lib/geomotion/cg_point.rb, line 41 def distance_to(point) dx = self.x - point.x dy = self.y - point.y return Math.sqrt(dx**2 + dy**2) end
down(dist = 0)
click to toggle source
# File lib/geomotion/cg_point.rb, line 29 def down(dist = 0) CGPoint.new(self.x, self.y + dist) end
inside?(rect)
click to toggle source
# File lib/geomotion/cg_point.rb, line 37 def inside?(rect) CGRectContainsPoint(rect, self) end
inspect()
click to toggle source
# File lib/geomotion/cg_point.rb, line 97 def inspect "#{self.class.name}(#{self.x}, #{self.y})" end
left(dist = 0)
click to toggle source
modified points
# File lib/geomotion/cg_point.rb, line 17 def left(dist = 0) CGPoint.new(self.x - dist, self.y) end
rect_of_size(size)
click to toggle source
size = CGSize.make
width: 100, height: 100 point = CPPoint.make x:0, y:10 point.rect_of_size(size) # => CGRect([0, 10], [100, 100]) point.rect_of_size([10, 20]) # => CGRect([10, 20], [100, 100])
# File lib/geomotion/cg_point.rb, line 12 def rect_of_size(size) CGRect.new(self, size) end
right(dist = 0)
click to toggle source
# File lib/geomotion/cg_point.rb, line 21 def right(dist = 0) CGPoint.new(self.x + dist, self.y) end
round()
click to toggle source
# File lib/geomotion/cg_point.rb, line 33 def round CGPoint.new(self.x.round, self.y.round) end
to_ns_value()
click to toggle source
# File lib/geomotion/cg_point.rb, line 101 def to_ns_value NSValue.valueWithCGPoint(self) end
up(dist = 0)
click to toggle source
# File lib/geomotion/cg_point.rb, line 25 def up(dist = 0) CGPoint.new(self.x, self.y - dist) end
Private Instance Methods
to_ary()
click to toggle source
this method allows us to do parallel assignment of x and y
# File lib/geomotion/cg_point.rb, line 107 def to_ary [self.x, self.y] end