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
- #+(other) ⇒ Object
- #-(other) ⇒ Object
- #-@ ⇒ Object
- #==(point) ⇒ Object
- #inside?(rect) ⇒ Boolean
- #inspect ⇒ Object
-
#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]).
- #round ⇒ Object
Class Method Details
.make(options = {}) ⇒ Object
CGPoint.make(x: 10, y: 30)
3 4 5 |
# File 'lib/geomotion/cg_point.rb', line 3 def self.make( = {}) CGPoint.new([:x] || 0, [:y] || 0) end |
Instance Method Details
#+(other) ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/geomotion/cg_point.rb', line 15 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) end end |
#-(other) ⇒ Object
40 41 42 |
# File 'lib/geomotion/cg_point.rb', line 40 def -(other) self.+(-other) end |
#-@ ⇒ Object
36 37 38 |
# File 'lib/geomotion/cg_point.rb', line 36 def -@ CGPoint.new(-self.x, -self.y) end |
#==(point) ⇒ Object
32 33 34 |
# File 'lib/geomotion/cg_point.rb', line 32 def ==(point) point.is_a?(CGPoint) && CGPointEqualToPoint(self, point) end |
#inside?(rect) ⇒ Boolean
28 29 30 |
# File 'lib/geomotion/cg_point.rb', line 28 def inside?(rect) CGRectContainsPoint(rect, self) end |
#inspect ⇒ Object
44 45 46 |
# File 'lib/geomotion/cg_point.rb', line 44 def inspect "#{self.class.name}(#{self.x}, #{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])
11 12 13 |
# File 'lib/geomotion/cg_point.rb', line 11 def rect_of_size(size) CGRect.new([self.x, self.y], size) end |
#round ⇒ Object
24 25 26 |
# File 'lib/geomotion/cg_point.rb', line 24 def round CGPoint.new(self.x.round, self.y.round) end |