HarryStevens / geometric

A JavaScript library for doing geometry.
https://www.npmjs.com/package/geometric
MIT License
970 stars 49 forks source link

Better boolean operations for V3 #7

Open HarryStevens opened 4 years ago

HarryStevens commented 4 years ago

The current relationship methods return only booleans, i.e. if the relationship exists. Better would be to return where the relationship exists, or false if it does not exist.

The polygon relationship methods will likely be somewhat time consuming to implement. The most modern algorithms for performing boolean operations on polygons can be found here: http://www.cs.ucr.edu/~vbz/cs230papers/martinez_boolean.pdf

These will likely not be compatible with current methods, so it may be necessary to bump major versions.

HarryStevens commented 4 years ago

It will likely also be necessary to implement a utility method called, say, polygonWind, polygonSort, or polygonOrder because the Martinez et al clipping algorithms require a polygon's vertices to be in counter-clockwise order.

Here's an implementation: https://observablehq.com/d/eaf3a3c863d34aee

HarryStevens commented 4 years ago

See also: http://sean.cm/a/polygon-clipping-pt1

HarryStevens commented 4 years ago

On simple polygons, see: https://en.wikipedia.org/wiki/Simple_polygon

HarryStevens commented 4 years ago

Fil's done it: https://observablehq.com/@d3/polygonclip

ianstormtaylor commented 2 years ago

Would love to see this added to the library!