Class: CGPoint

Inherits:
Object
  • Object
show all
Defined in:
lib/geomotion/cg_point.rb

Class Method Summary collapse

Instance Method Summary collapse

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(options = {})
  CGPoint.new(options[:x] || 0, options[: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

Returns:

  • (Boolean)


28
29
30
# File 'lib/geomotion/cg_point.rb', line 28

def inside?(rect)
  CGRectContainsPoint(rect, self)
end

#inspectObject



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

#roundObject



24
25
26
# File 'lib/geomotion/cg_point.rb', line 24

def round
  CGPoint.new(self.x.round, self.y.round)
end