1 # Copyright (c) 2009 Paolo Capriotti <p.capriotti@gmail.com>
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
11 include PrintablePoint
20 other and @x == other.x and @y == other.y
24 self.class.new(@x + other.x, @y + other.y)
28 self.class.new(@x - other.x, @y - other.y)
32 self.class.new(@x * factor, @y * factor)
36 self.class.new(@x / factor, @y / factor)
40 other.instance_of?(Point) and self == other
48 Point.new(@x.unit, @y.unit)
53 (((not other.x) or other.x == x) and
54 ((not other.y) or other.y == y))
58 "#{(self.x + ?a).chr if x}#{(ysize - self.y) if self.y}"
61 def self.from_coord(s, ysize, opts = { })
62 if s =~ /^([a-zA-Z]?)(\d*)/
65 x = unless letter.empty?
72 y = ysize - number.to_i unless number.empty?
73 if (x and y) or (not opts[:strict])
83 attr_reader :src, :dst, :delta
85 def initialize(src, dst)
89 @increment = @delta.unit
101 @delta.x == 0 or @delta.y == 0
105 @delta.x.abs == @delta.y.abs
109 parallel? or diagonal?