lib/geometer/point.rb in geometer-0.1.1 vs lib/geometer/point.rb in geometer-0.1.2
- old
+ new
@@ -2,12 +2,23 @@
class Point < Struct.new(:x, :y)
def inspect
"(#{x},#{y})"
end
- def -@
+ def invert
Point.new(-x,-y)
end
+ alias_method :-@, :invert
+
+ def scale(sz)
+ Point.new(x*sz,y*sz)
+ end
+ alias_method :*, :scale
+
+ def divide(sz)
+ scale(1.0/sz)
+ end
+ alias_method :/, :divide
def translate(other_point)
dx,dy = *other_point
Point.new(x+dx, y+dy)
end