mapbox / polylabel

A fast algorithm for finding the pole of inaccessibility of a polygon (in JavaScript and C++)
Other
1.44k stars 151 forks source link

redundant calculation #11

Closed jingsam closed 8 years ago

jingsam commented 8 years ago

In https://github.com/mapbox/polylabel/blob/master/index.js#L95, we iterate each segments to calculate distance from point to segment.

Support we have a polygon with 4 nodes as fellows. We should see that point 0 and 4 are identical. So I think the calculation of point to segment 4-0 is unnecessary.

image

However, for compatible reason, it is appropriate to keep this redundant calculation, in case of non-closed polygons. Am I correct?

mourner commented 8 years ago

Yes, this is to make sure we handle non-closed polygons too. Also, in practice this does not have a noticeable performance overhead.