Crates.io | polygon_clipping |
lib.rs | polygon_clipping |
version | 0.1.0 |
source | src |
created_at | 2023-08-17 02:27:03.787591 |
updated_at | 2023-08-17 02:27:03.787591 |
description | An algorithm for computing boolean operations on polygons. |
homepage | |
repository | https://github.com/andriyDev/polygon_clipping_rs |
max_upload_size | |
id | 946536 |
size | 121,307 |
A Rust crate to compute boolean operations (i.e., intersection, union, difference, and XOR) of two polygons.
Polygons are represented as a set of "contours". Each contour is a loop of vertices. Points contained by an even number of contours are considered outside the polygon, and points contained by an odd number of contours are considered inside the polygon. Note that "polygon" is not quite correct since this includes "multipolygons" - essentially two completely disjoint shapes.
This implementation does not account for "malformed" polygons. The behavior in these cases is undefined. Some malformed polygons include:
NaN
or Infinity
coordinates. It is pretty obvious why
this would be a problem.This is an implementation of the paper:
Francisco Martínez, Carlos Ogayar, Juan R. Jiménez, Antonio J. Rueda,
A simple algorithm for Boolean operations on polygons,
Advances in Engineering Software,
Volume 64,
2013,
Pages 11-19,
ISSN 0965-9978,
https://doi.org/10.1016/j.advengsoft.2013.04.004.
(https://www.sciencedirect.com/science/article/pii/S0965997813000379)
These are intentional changes to the original algorithm.
These are problems in the implementation that could be addressed in the future.
Vec
, so some
operations may have different performance characteristics. The paper also
mentions that events could store their position in the sweep line to avoid a
search.This paper is quite clever, and the general idea is fairly intuitive. However, the paper seems to hide critical information in single sentences that seem benign (e.g., events must be sorted by non-vertical edges first), and more importantly leaves a lot of figuring out the details of the algorithm to the reader. This made it confusing when my version required significant differences to the pseudo-code in the paper. In addition, some flags are described but not how to compute them, and the "special cases" are treated as footnotes rather than parts of the algorithm that take lots of time and work to restructure and figure out.
Alright, I'm done complaining.
Licensed under the MIT license.