ladybug-tools / ladybug-geometry

🐞 📦 A library with geometry objects used throughout the Ladybug Tools core libraries
https://www.ladybug.tools/ladybug-geometry/docs/
GNU Affero General Public License v3.0
23 stars 22 forks source link

Improve the Performance of Polygon2D.from_shape_with_holes #362

Closed chriswmackey closed 1 year ago

chriswmackey commented 1 year ago

The current Polygon2D.from_shape_with_holes method is really inefficient when it comes to shapes with lots of holes or shapes with very detailed holes like this one:

https://discourse.ladybug.tools/t/how-to-set-and-visualize-a-lot-of-surfaces-as-windows/20318

I remember thinking that it seemed like a waste that I re-compute the distance from every hole point to every boundary point each time I merge in a new hole. In theory, I could just compute those hole-boundary distances once and then find "the path of least resistance" through those values.

I have a feeling that just performing the vertex distance calculations once for the shape and not every time we merge a new hole will solve this scaling problem and get cases like the one uploaded here to run in a tiny fraction of the time. I imagine this would not take me much more than a day but I'll probably need another day after this to test it well and make sure it's working as designed.