Class: CGPoint
- Inherits:
-
Object
- Object
- CGPoint
- Defined in:
- lib/geomotion/cg_point.rb
Class Method Summary collapse
-
.make(options = {}) ⇒ Object
CGPoint.make(x: 10, y: 30).
Instance Method Summary collapse
- #*(scale) ⇒ Object
-
#+(other) ⇒ Object
operator.
- #-(other) ⇒ Object
- #-@ ⇒ Object
-
#/(scale) ⇒ Object
it is tempting to define this as self * (1.0/scale) but floating point errors result in too many errors.
- #==(point) ⇒ Object
- #angle_to(point) ⇒ Object
- #distance_to(point) ⇒ Object
- #down(dist = 0) ⇒ Object
- #inside?(rect) ⇒ Boolean
- #inspect ⇒ Object
-
#left(dist = 0) ⇒ Object
modified points.
-
#rect_of_size(size) ⇒ Object
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]).
- #right(dist = 0) ⇒ Object
- #round ⇒ Object
- #to_ns_value ⇒ Object
- #up(dist = 0) ⇒ Object
Class Method Details
.make(options = {}) ⇒ Object
CGPoint.make(x: 10, y: 30)
4 5 6 |
# File 'lib/geomotion/cg_point.rb', line 4 def self.make( = {}) CGPoint.new([:x] || 0, [:y] || 0) end |
Instance Method Details
#*(scale) ⇒ Object
65 66 67 68 69 70 71 72 |
# 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) ⇒ Object
operator
54 55 56 57 58 59 60 61 62 63 |
# 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) ⇒ Object
93 94 95 |
# File 'lib/geomotion/cg_point.rb', line 93 def -(other) self.+(-other) end |
#-@ ⇒ Object
89 90 91 |
# File 'lib/geomotion/cg_point.rb', line 89 def -@ CGPoint.new(-self.x, -self.y) end |
#/(scale) ⇒ Object
it is tempting to define this as self * (1.0/scale) but floating point errors result in too many errors
76 77 78 79 80 81 82 83 |
# 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) ⇒ Object
85 86 87 |
# File 'lib/geomotion/cg_point.rb', line 85 def ==(point) point.is_a?(CGPoint) && CGPointEqualToPoint(self, point) end |
#angle_to(point) ⇒ Object
47 48 49 50 51 |
# 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) ⇒ Object
41 42 43 44 45 |
# 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) ⇒ Object
29 30 31 |
# File 'lib/geomotion/cg_point.rb', line 29 def down(dist = 0) CGPoint.new(self.x, self.y + dist) end |
#inside?(rect) ⇒ Boolean
37 38 39 |
# File 'lib/geomotion/cg_point.rb', line 37 def inside?(rect) CGRectContainsPoint(rect, self) end |
#inspect ⇒ Object
97 98 99 |
# File 'lib/geomotion/cg_point.rb', line 97 def inspect "#{self.class.name}(#{self.x}, #{self.y})" end |
#left(dist = 0) ⇒ Object
modified points
17 18 19 |
# File 'lib/geomotion/cg_point.rb', line 17 def left(dist = 0) CGPoint.new(self.x - dist, self.y) end |
#rect_of_size(size) ⇒ Object
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])
12 13 14 |
# File 'lib/geomotion/cg_point.rb', line 12 def rect_of_size(size) CGRect.new(self, size) end |
#right(dist = 0) ⇒ Object
21 22 23 |
# File 'lib/geomotion/cg_point.rb', line 21 def right(dist = 0) CGPoint.new(self.x + dist, self.y) end |
#round ⇒ Object
33 34 35 |
# File 'lib/geomotion/cg_point.rb', line 33 def round CGPoint.new(self.x.round, self.y.round) end |
#to_ns_value ⇒ Object
101 102 103 |
# File 'lib/geomotion/cg_point.rb', line 101 def to_ns_value NSValue.valueWithCGPoint(self) end |
#up(dist = 0) ⇒ Object
25 26 27 |
# File 'lib/geomotion/cg_point.rb', line 25 def up(dist = 0) CGPoint.new(self.x, self.y - dist) end |