tidwall / tg

Geometry library for C - Fast point-in-polygon
MIT License
562 stars 14 forks source link

Length for tg_line? #5

Closed simonrolfmore-brunswick closed 11 months ago

simonrolfmore-brunswick commented 11 months ago

I absolutely appreciate this may not be the way you want to go with tg, but I figure it can't hurt to ask: would you be interested in exposing a function to calculate the length of a tg_line?

It looks like there's already an internal length function for calculating the Pythagoras distance between 2 points, and a function to calculate a ring's perimeter as part of the Polsby-Popper score calculation, so this doesn't appear to be a huge stretch in terms of extra code, but I understand this may not be an API overhead you want to take on.

For full disclosure, I'm asking for this with the hope of it getting incorporated into sqlite-tg as it's a much lighter-weight alternative to using Spatialite and the GeoJSON conversion, intersection, and bounding box functions are super useful for the work I'm doing.

tidwall commented 11 months ago

You're right that this should be a relatively simple change. Most of the code is already there but just needs to be exposed to the API.

I'll dig a little deep and see what I can do.

tidwall commented 11 months ago

The method is now available.

simonrolfmore-brunswick commented 11 months ago

Thank you! Looks fantastic :)