@davidkoh007 ,
I think my approach would try to reduce the amount of entities selected in a selection set, that would optimistically reduce the amount of time spent searching for entities and processing them.
Something like this workflow:
- store EXTMAX and EXTMIN (now we have a 'box' of coordinates to use)
- when RAY is selected, use vector to calculate the point where your ray intersects our 'box'
- now we have our 2 points to work with on our RAY
*normally at this point I would zoom-window to these 2 points, then use
a Crossing-Polygon selset filter, but since we have about 10k objects
lets first divide this length into quarters. So...*
- use polar function from our ray base point to calculate a new point 1/4 distance away
(polar pBase ang (* 0.25 (distance pBase pIntersect)))
- Now, we can zoom-window to these 2 points
- check IF we get a Crossing Polygon using these 2 points
- if so, we will HOPEFULLY have about 2500 entities to process
(assuming they are mostly evenly distributed within your dwg)
- if we get NO selection set, then calculate another Crossing Polygon
area further out until we can return a selection set to process.
- Once we have entities to process, we can use an intersect function
with our distance function to calculate which element is closest
So, using this method, we are doing more calculations up-front, but saving ourselves some entities to process in the long run.
You could even reduce the distance from 1/4 to 1/10 or less if you'd like. we need to find that balance between selecting too many objects, or not getting any objects in our selection set.
Does this make sense? Best,
~DD