Sha256: f591c17ca3993db6ab55ca9690ee6e3b3d293c0dea58c233a5d1b6eff9129111
Contents?: true
Size: 1.46 KB
Versions: 1
Compression:
Stored size: 1.46 KB
Contents
class CGSize # CGSize.make(width: 10, height: 30) def self.make(options = {}) CGSize.new(options[:width] || 0, options[:height] || 0) end def self.infinite infinity = CGRect.null[0][0] CGSizeMake(infinity, infinity) end def self.empty CGSizeZero.dup end # 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]) def rect_at_point(point) CGRect.new(point, [self.width, self.height]) end 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 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 def infinite? infinity = CGRect.null[0][0] # null rects are rects with infinite width & height self.width == infinity or self.height == infinity end def empty? self == CGSizeZero end def ==(size) size.is_a?(CGSize) && CGSizeEqualToSize(self, size) end def -@ CGSize.new(-self.width, -self.height) end def -(other) self.+(-other) end def inspect "#{self.class.name}(#{self.width}, #{self.height})" end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
geomotion-0.5 | lib/geomotion/cg_size.rb |