Factor common code out of xboard and gnushogi engines.
[kaya/ydirson.git] / lib / board / point_converter.rb
blob8b019e16cfe02e50543d3b852f04d0b7337da39f
1 # Copyright (c) 2009 Paolo Capriotti <p.capriotti@gmail.com>
2
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.
8 require 'point'
9 require 'qtutils'
11 module PointConverter
12   def to_logical(p)
13     result = Point.new((p.x.to_f / unit.x).floor,
14                        (p.y.to_f / unit.y).floor)
15     result = flip_point(result) if flipped?
16     result
17   end
18   
19   def to_real(p)
20     p = flip_point(p) if flipped?
21     Qt::PointF.new(p.x * unit.x, p.y * unit.y)
22   end
23   
24   def flip_point(p)
25     Point.new(@game.size.x - p.x - 1, @game.size.y - p.y - 1)
26   end
27 end