Class: CGSize

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.emptyObject



12
13
14
# File 'lib/geomotion/cg_size.rb', line 12

def self.empty
  CGSizeZero.dup
end

.infiniteObject



7
8
9
10
# File 'lib/geomotion/cg_size.rb', line 7

def self.infinite
  infinity = CGRect.null[0][0]
  CGSizeMake(infinity, infinity)
end

.make(options = {}) ⇒ Object

CGSize.make(width: 10, height: 30)



3
4
5
# File 'lib/geomotion/cg_size.rb', line 3

def self.make(options = {})
  CGSize.new(options[:width] || 0, options[:height] || 0)
end

Instance Method Details

#+(other) ⇒ Object



31
32
33
34
35
36
37
38
# File 'lib/geomotion/cg_size.rb', line 31

def +(other)
  case other
  when CGSize
    return CGSize.new(self.width + other.width, self.height + other.height)
  when CGPoint
    return self.rect_at_point(other)
  end
end

#-(other) ⇒ Object



57
58
59
# File 'lib/geomotion/cg_size.rb', line 57

def -(other)
  self.+(-other)
end

#-@Object



53
54
55
# File 'lib/geomotion/cg_size.rb', line 53

def -@
  CGSize.new(-self.width, -self.height)
end

#==(size) ⇒ Object



49
50
51
# File 'lib/geomotion/cg_size.rb', line 49

def ==(size)
  size.is_a?(CGSize) && CGSizeEqualToSize(self, size)
end

#centered_in(rect, absolute = false) ⇒ Object



24
25
26
27
28
29
# File 'lib/geomotion/cg_size.rb', line 24

def centered_in(rect, absolute = false)
  offset_x = absolute ? rect.x : 0
  offset_y = absolute ? rect.y : 0
  CGRect.new([offset_x + ((rect.width - self.width) / 2),
              offset_y + ((rect.height - self.height) / 2)], self)
end

#empty?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/geomotion/cg_size.rb', line 45

def empty?
  self == CGSizeZero
end

#infinite?Boolean

Returns:

  • (Boolean)


40
41
42
43
# File 'lib/geomotion/cg_size.rb', line 40

def infinite?
  infinity = CGRect.null[0][0]  # null rects are rects with infinite width & height
  self.width == infinity or self.height == infinity
end

#inspectObject



61
62
63
# File 'lib/geomotion/cg_size.rb', line 61

def inspect
  "#{self.class.name}(#{self.width}, #{self.height})"
end

#rect_at_point(point) ⇒ Object

size = CGSize.make width: 100, height: 100 point = CPPoint.make x:0, y:10 size.rect_at_point(point) # => CGRect([0, 10], [100, 100]) size.rect_at_point([10, 20]) # => CGRect([10, 20], [100, 100])



20
21
22
# File 'lib/geomotion/cg_size.rb', line 20

def rect_at_point(point)
  CGRect.new(point, [self.width, self.height])
end