[PythonCAD] Upcoming changes in PythonCAD QuadTree code

Art Haas ahaas at airmail.net
Mon Aug 15 22:02:55 CEST 2005


Hi.

The changes of the last few days in handling equivalent entities in
QuadTrees has seemed to go smoothly enough. As a Quadtree now will
have possibly stored numerous equivalent entities, an implicit
assumption in the find() method no longer holds. The find() calls
basically assumed that the QuadTree would only have one entity
of some value stored in any node, so when examining the entities the
find() call will stop after finding an equivalent entity. Now, however,
there may be another equivalent entity in the node that is "better"
for the purpose of the find() call, so stopping after encountering the
first entity is not a good plan. My initial idea is to change the
return type of find() from either 'None' or the found entity to a
list. If no suitable entity is encountered an empty list is returned,
otherwise the list is populated with entities that meet the criteria.

In essence this change makes the find() and getInRegion() methods
essentially identical. In the case of the PointQuadtree, a find()
call takes an 'x' and 'y' argument, plus an optional tolerance
value. Consider in the example below that the find() call wants
to test if there are points at (0, 0), with a tolerance of 0.1
units:

pqt = point.PointQuadTree()
[ ... make points and add them to the tree with addObject()  ... ]
pts = pqt.find(0, 0, 0.1)

This find() call could be replaced by the following:

pts = pqt.getInRegion(-0.1, -0.1, 0.1, 0.1)

If things work correctly both calls should return the same things,
either an empty list or a list populated by the same points.

I'm also looking to remove the getClosest() method as it is currently
unused anywhere in the code. Also, this method too relies on the
implicit assumption of the QuadTree only containing one entity of
any given value.

I've just started making these changes, so there is nothing new at the
repository for anyone to play with yet. Feel free to comment on the
planned changes if you think the above plan sounds bad.

Art
-- 
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