d3 / d3-polygon

Geometric operations for two-dimensional polygons.
https://d3js.org/d3-polygon
ISC License
97 stars 25 forks source link

Why is Polygon.hull() result not counterclockwise ? #14

Closed Kcnarf closed 6 years ago

Kcnarf commented 6 years ago

The test below shows that the expected result is clockwise, not counterclockwise as mention in the documentation.

https://github.com/d3/d3-polygon/blob/1bfcdc8b63578b936c785639fa73cec566713c45/test/hull-test.js#L12

Is it due to the fact that the y-axis direction of SVGs is going down the screen, and hence inverting some common computation results ?

mbostock commented 6 years ago

Yes; D3 uses the default coordinate system of Canvas and SVG, which is +x pointing right and +y pointing down.

Kcnarf commented 6 years ago

Fine. Thanks for your clarification.

I will refactor the d3-weighted-voronoi (and subsequently d3-voronoi-map/d3-voronoi-treemap) plugin in order to fulfill this convention.