class CGSize
Public Class Methods
empty()
click to toggle source
# File lib/geomotion/cg_size.rb, line 12 def self.empty CGSizeZero.dup end
infinite()
click to toggle source
# File lib/geomotion/cg_size.rb, line 7 def self.infinite infinity = CGRect.null[0][0] CGSizeMake(infinity, infinity) end
make(options = {})
click to toggle source
CGSize.make
(width: 10, height: 30)
# File lib/geomotion/cg_size.rb, line 3 def self.make(options = {}) CGSize.new(options[:width] || 0, options[:height] || 0) end
Public Instance Methods
*(scale)
click to toggle source
Calls superclass method
# File lib/geomotion/cg_size.rb, line 56 def *(scale) case scale when Numeric return CGSize.new(self.width * scale, self.height * scale) else super end end
+(other)
click to toggle source
# File lib/geomotion/cg_size.rb, line 47 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)
click to toggle source
# File lib/geomotion/cg_size.rb, line 93 def -(other) self.+(-other) end
-@()
click to toggle source
# File lib/geomotion/cg_size.rb, line 89 def -@ CGSize.new(-self.width, -self.height) 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 miscalculations
Calls superclass method
# File lib/geomotion/cg_size.rb, line 67 def /(scale) case scale when Numeric return CGSize.new(self.width / scale, self.height / scale) else super end end
==(size)
click to toggle source
# File lib/geomotion/cg_size.rb, line 85 def ==(size) size.is_a?(CGSize) && CGSizeEqualToSize(self, size) end
centered_in(rect, absolute = false)
click to toggle source
# File lib/geomotion/cg_size.rb, line 40 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?()
click to toggle source
# File lib/geomotion/cg_size.rb, line 81 def empty? self == CGSizeZero end
infinite?()
click to toggle source
# File lib/geomotion/cg_size.rb, line 76 def infinite? infinity = CGRect.null[0][0] # null rects are rects with infinite width & height self.width == infinity or self.height == infinity end
inspect()
click to toggle source
# File lib/geomotion/cg_size.rb, line 97 def inspect "#{self.class.name}(#{self.width}, #{self.height})" end
rect_at_point(point)
click to toggle source
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])
# File lib/geomotion/cg_size.rb, line 36 def rect_at_point(point) CGRect.new(point, [self.width, self.height]) end
shorter(dist)
click to toggle source
# File lib/geomotion/cg_size.rb, line 28 def shorter(dist) CGSize.new(self.width, self.height - dist) end
taller(dist)
click to toggle source
# File lib/geomotion/cg_size.rb, line 24 def taller(dist) CGSize.new(self.width, self.height + dist) end
thinner(dist)
click to toggle source
# File lib/geomotion/cg_size.rb, line 20 def thinner(dist) CGSize.new(self.width - dist, self.height) end
to_ns_value()
click to toggle source
# File lib/geomotion/cg_size.rb, line 101 def to_ns_value NSValue.valueWithCGSize(self) end
wider(dist)
click to toggle source
# File lib/geomotion/cg_size.rb, line 16 def wider(dist) CGSize.new(self.width + dist, self.height) end
Private Instance Methods
to_ary()
click to toggle source
# File lib/geomotion/cg_size.rb, line 106 def to_ary [self.width, self.height] end