class Castaway::Point
Public Class Methods
make(*args)
click to toggle source
# File lib/castaway/point.rb, line 4 def self.make(*args) if args.length == 1 && args[0].is_a?(Array) new(args[0][0], args[0][1]) elsif args.length == 1 && args[0].is_a?(Point) args[0] else raise ArgumentError, "can't make a point from #{args.inspect}" end end
Public Instance Methods
*(factor)
click to toggle source
# File lib/castaway/point.rb, line 14 def *(factor) if factor.respond_to?(:x) Point.new(x * factor.x, y * factor.y) elsif factor.respond_to?(:width) Point.new(x * factor.width, y * factor.height) else Point.new(x * factor, y * factor) end end
+(pt)
click to toggle source
# File lib/castaway/point.rb, line 28 def +(pt) Point.new(x + pt.x, y + pt.y) end
-(pt)
click to toggle source
# File lib/castaway/point.rb, line 24 def -(pt) Point.new(x - pt.x, y - pt.y) end
rotate(radians)
click to toggle source
# File lib/castaway/point.rb, line 44 def rotate(radians) cos = Math.cos(radians) sin = Math.sin(radians) nx = x * cos - y * sin ny = y * cos + x * sin Point.new(nx, ny) end
scale(sx, sy = sx)
click to toggle source
# File lib/castaway/point.rb, line 40 def scale(sx, sy = sx) Point.new(x * sx, y * sy) end
to_geometry()
click to toggle source
# File lib/castaway/point.rb, line 58 def to_geometry format('+%.2f+%.2f', x, y) end
to_s()
click to toggle source
# File lib/castaway/point.rb, line 54 def to_s format('(%.2f, %.2f)', x, y) end
translate(dx, dy)
click to toggle source
# File lib/castaway/point.rb, line 36 def translate(dx, dy) Point.new(x + dx, y + dy) end
zero?()
click to toggle source
# File lib/castaway/point.rb, line 32 def zero? x == 0 && y == 0 end