[PythonCAD] intersecting construction lines?

Art Haas ahaas at airmail.net
Sun Jun 11 02:56:30 CEST 2006


On Thu, Jun 08, 2006 at 10:52:39PM -0400, Russ Nelson wrote:
> Art Haas writes:
>  > I'm not sure what you mean when you write 'set two points on the
>  > diagonal'. Regardless, I'll do some drawing and see if I can duplicate
>  > the problem. 
> 
> The O's are points, the crosses are intersections without a point, and
> the lines are either construction lines or segments; same effect.
> 
>                         _____ /A point drawn near this 
>       |              | /      \intersection doesn't snap.
>       |              |/
> ------O--------------+-----
>       |              |
>       |              |
>       |              |
>       |              |
>       |              |
> ------+--------------O-----
>       |              |
>       |              |

Hi.

I've looked into this, and I found a couple of problems. The
code that under scrutiny the Image::getClosestPoint() method.
First, I fixed a boneheaded typo on line 767 by replacing
the '-' with the correct '<'. Fixing that goof the next change
involves switching the tests for mapped points and intersection
points. In the case above, the mapped point is selected because
the mapped point ends up being closer to the mouse-click point
even though there is an intersection point to use. I've changed
things so that an intersection point will always be chosen
over a mapped point.

The patch below contains the changes listed above, and I've
also sent the changes to the public repo so people using
Subversion can get the fix with 'svn update'.

Art

Index: PythonCAD/Generic/image.py
===================================================================
--- PythonCAD/Generic/image.py	(revision 2385)
+++ PythonCAD/Generic/image.py	(revision 2386)
@@ -724,7 +724,6 @@
                         if _sep is None or _sqlen < _sep:
                             _sep = _sqlen
                             _cp = _pt
-
             _layers.extend(_layer.getSublayers())
         if _cp is not None:
             return None, (_cp.x, _cp.y)            
@@ -760,16 +759,23 @@
                         for _tobj, _mp in _objlist:
                             for _ix, _iy in intersections.find_intersections(_tobj, _obj):
                                 if ((abs(_ix - _x) < _t) and
-                                    (abs(_iy - _y) - _t)):
+                                    (abs(_iy - _y) < _t)):
                                     _sqlen = pow((_x - _ix), 2) + pow((_y - _iy), 2)
                                     _intlist.append((_sqlen, (_ix, _iy)))
                     _objlist.append((_obj, _pt))
             _layers.extend(_layer.getSublayers())
         #
+        # use the nearest intersection point if one is available
+        #
+        _rx = _ry = None
+        if len(_intlist):
+            _intlist.sort()
+            _rx, _ry = _intlist[0][1]
+        #
         # look for the closest intersection or mapped point
         #
-        _rx = _ry = _smin = None
-        if len(_objlist):
+        if _rx is None and len(_objlist):
+            _smin = None
             for _obj, _pt in _objlist:
                 _px, _py = _pt
                 _sqlen = pow((_x - _px), 2) + pow((_y - _py), 2)
@@ -777,13 +783,7 @@
                     _smin = _sqlen
                     _rx = _px
                     _ry = _py
-        if len(_intlist):
-            _intlist.sort()
-            _ismin = _intlist[0][0]
-            if _smin is None or _ismin < _smin:
-                _smin = _ismin
-                _rx, _ry = _intlist[0][1]
-        if _smin is None:
+        if _rx is None:
             _rx = _x
             _ry = _y
         return None, (_rx, _ry)
-- 
Man once surrendering his reason, has no remaining guard against absurdities
the most monstrous, and like a ship without rudder, is the sport of every wind.

-Thomas Jefferson to James Smith, 1822


More information about the PythonCAD mailing list