Sha256: 58b12fb4699c966d6646c1d34b3ebe1efff9a6bb99cc4e7cac1f3b7fd1e850ee
Contents?: true
Size: 1.03 KB
Versions: 1
Compression:
Stored size: 1.03 KB
Contents
# # Generic Point/Size unit # class UnderOs::Point attr_accessor :x, :y def initialize(x, y=nil) if x.is_a?(UnderOs::Point) y = x.y if x.y x = x.x elsif x.is_a?(Hash) y = x[:y] || x['y'] || nil x = x[:x] || x['x'] || nil end @x = x @y = y end def ==(*args) point = UnderOs::Point.new(*args) # normalizing x == point.x && y == point.y end def *(multiplier) UnderOs::Point.new(x: x * multiplier, y: y * multiplier) end def /(divider) UnderOs::Point.new(x: x / divider.to_f, y: y / divider.to_f) end def -(point) point = point.is_a?(Numeric) ? UnderOs::Point.new(x: point, y: point) : UnderOs::Point.new(point) UnderOs::Point.new(x: x - point.x, y: y - point.y) end def +(point) point = point.is_a?(Numeric) ? UnderOs::Point.new(x: point, y: point) : UnderOs::Point.new(point) UnderOs::Point.new(x: x + point.x, y: y + point.y) end def to_s "x=#{x} y=#{y}" end def inspect "#<#{self.class.name}:0x#{__id__.to_s(16)} #{to_s}>" end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
under-os-core-1.4.0 | lib/under_os/point.rb |