Permalink
Browse files

Fixed issue with rotating at 90 degrees. Now calculate the distance a…

…s it should

(no more shortcuts).
  • Loading branch information...
1 parent 5292aaf commit 588d5cb4d38051ce135b02735c57b11202d50a4e @amolenaar committed Jul 20, 2012
Showing with 23 additions and 5 deletions.
  1. +2 −2 demo.py
  2. +1 −1 gaphas/geometry.py
  3. +18 −0 gaphas/tests/test_view.py
  4. +2 −2 gaphas/view.py
View
@@ -403,8 +403,8 @@ def create_canvas(c=None):
# AJM: extra boxes:
bb = Box()
- print 'box', bb
- bb.matrix.rotate(math.pi/4.)
+ print 'rotated box', bb
+ bb.matrix.rotate(math.pi/1.567)
c.add(bb, parent=b)
# for i in xrange(10):
# bb=Box()
View
@@ -264,7 +264,7 @@ def distance_point_point(point1, point2=(0., 0.)):
return sqrt(dx*dx + dy*dy)
-def distance_point_point_fast(point1, point2):
+def distance_point_point_fast(point1, point2=(0., 0.)):
"""
Return the distance from point ``point1`` to ``point2``. This version is
faster than ``distance_point_point()``, but less precise.
View
@@ -99,6 +99,24 @@ def test_get_handle_at_point(self):
box.matrix.rotate(math.pi/1.5)
canvas.add(box)
+ i, h = view.get_handle_at_point((20, 20))
+ assert i is box
+ assert h is box.handles()[0]
+
+ def test_get_handle_at_point_at_pi_div_2(self):
+ canvas = Canvas()
+ view = GtkView(canvas)
+ window = gtk.Window(gtk.WINDOW_TOPLEVEL)
+ window.add(view)
+ window.show_all()
+
+ box = Box()
+ box.min_width = 20
+ box.min_height = 30
+ box.matrix.translate(20, 20)
+ box.matrix.rotate(math.pi/2)
+ canvas.add(box)
+
p = canvas.get_matrix_i2c(box).transform_point(0, 20)
p = canvas.get_matrix_c2i(box).transform_point(20, 20)
i, h = view.get_handle_at_point((20, 20))
View
@@ -9,7 +9,7 @@
import gtk
from cairo import Matrix
from canvas import Context
-from geometry import Rectangle
+from geometry import Rectangle, distance_point_point_fast
from quadtree import Quadtree
from tool import DefaultTool
from painter import DefaultPainter, BoundingBoxPainter
@@ -247,7 +247,7 @@ def get_handle_at_point(self, pos, distance=6):
def find(item):
""" Find item's handle at pos """
v2i = self.get_matrix_v2i(item)
- d = abs(v2i.transform_distance(distance, 0)[0])
+ d = distance_point_point_fast(v2i.transform_distance(0, distance))
x, y = v2i.transform_point(*pos)
for h in item.handles():

0 comments on commit 588d5cb

Please sign in to comment.