Class: CGSize
- Inherits:
-
Object
- Object
- CGSize
- Defined in:
- lib/geomotion/cg_size.rb
Class Method Summary collapse
- .empty ⇒ Object
- .infinite ⇒ Object
-
.make(options = {}) ⇒ Object
CGSize.make(width: 10, height: 30).
Instance Method Summary collapse
- #*(scale) ⇒ Object
- #+(other) ⇒ Object
- #-(other) ⇒ Object
- #-@ ⇒ Object
-
#/(scale) ⇒ Object
it is tempting to define this as self * (1.0/scale) but floating point errors result in too many miscalculations.
- #==(size) ⇒ Object
- #centered_in(rect, absolute = false) ⇒ Object
- #empty? ⇒ Boolean
- #infinite? ⇒ Boolean
- #inspect ⇒ Object
-
#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]).
- #shorter(dist) ⇒ Object
- #taller(dist) ⇒ Object
- #thinner(dist) ⇒ Object
- #to_ns_value ⇒ Object
- #wider(dist) ⇒ Object
Class Method Details
.empty ⇒ Object
12 13 14 |
# File 'lib/geomotion/cg_size.rb', line 12 def self.empty CGSizeZero.dup end |
.infinite ⇒ Object
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( = {}) CGSize.new([:width] || 0, [:height] || 0) end |
Instance Method Details
#*(scale) ⇒ Object
56 57 58 59 60 61 62 63 |
# 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) ⇒ Object
47 48 49 50 51 52 53 54 |
# 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) ⇒ Object
93 94 95 |
# File 'lib/geomotion/cg_size.rb', line 93 def -(other) self.+(-other) end |
#-@ ⇒ Object
89 90 91 |
# File 'lib/geomotion/cg_size.rb', line 89 def -@ CGSize.new(-self.width, -self.height) end |
#/(scale) ⇒ Object
it is tempting to define this as self * (1.0/scale) but floating point errors result in too many miscalculations
67 68 69 70 71 72 73 74 |
# 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) ⇒ Object
85 86 87 |
# File 'lib/geomotion/cg_size.rb', line 85 def ==(size) size.is_a?(CGSize) && CGSizeEqualToSize(self, size) end |
#centered_in(rect, absolute = false) ⇒ Object
40 41 42 43 44 45 |
# 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? ⇒ Boolean
81 82 83 |
# File 'lib/geomotion/cg_size.rb', line 81 def empty? self == CGSizeZero end |
#infinite? ⇒ Boolean
76 77 78 79 |
# 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 ⇒ Object
97 98 99 |
# File 'lib/geomotion/cg_size.rb', line 97 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])
36 37 38 |
# File 'lib/geomotion/cg_size.rb', line 36 def rect_at_point(point) CGRect.new(point, [self.width, self.height]) end |
#shorter(dist) ⇒ Object
28 29 30 |
# File 'lib/geomotion/cg_size.rb', line 28 def shorter(dist) CGSize.new(self.width, self.height - dist) end |
#taller(dist) ⇒ Object
24 25 26 |
# File 'lib/geomotion/cg_size.rb', line 24 def taller(dist) CGSize.new(self.width, self.height + dist) end |
#thinner(dist) ⇒ Object
20 21 22 |
# File 'lib/geomotion/cg_size.rb', line 20 def thinner(dist) CGSize.new(self.width - dist, self.height) end |
#to_ns_value ⇒ Object
101 102 103 |
# File 'lib/geomotion/cg_size.rb', line 101 def to_ns_value NSValue.valueWithCGSize(self) end |
#wider(dist) ⇒ Object
16 17 18 |
# File 'lib/geomotion/cg_size.rb', line 16 def wider(dist) CGSize.new(self.width + dist, self.height) end |