1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
//! # Robust Triangulation with Louvre 🌙
//!
//! Louvre is a robust triangulation algorithm, which can handle self-intersecting polygons' triangulation.
//!
//! What is triangulation? ["Polygon triangulation"](https://en.wikipedia.org/wiki/Polygon_triangulation)
//! makes a polygon's vertex coordinates array
//! into a set of coordinates of triangles, whose areas' sum equals to the polygon's.
//!
//! As most of computational graphic processing systems (like opengl/webgl)
//! handle polygons by decomposing them into triangles,
//! a good and fast triangulation algorithm is crucial.
//!
//! Earcut([mapbox/earcut.js](https://github.com/mapbox/earcut)) is one of the most widely used triangulation algorithm.
//! However simple earcut cannot properly decompose self-intersecting polygons.
//!
//! Louvre widely refered to mapbox/earcut.js to implement basic logics and utilities of simple earcut algorithm.
//! Making further contribution,
//! louvre can handle **self-intersecting polygons**, which is not viable in most open source algorithms including mapbox/earcut.js.
//!
//! See [the live demo](https://acheul.github.io/louvre) of louvre. Try drawing some complex polygons, with self-intersecting lines.
//!
//! Surely, louvre is FAST and ROBUST.
//! You can use this in rust native or rust supporting wasm environment.
//!
//!
//! # Ex
//! ```rust
//! use louvre::triangulate;
//!
//! let mut data: Vec<f64> = vec![
//! [0., 0.], [0., 3.], [3., 0.], [3., 4.], [-1., 0.]
//! ].concat();
//!
//! let (new_data, indices) = triangulate(&mut data, 2);
//!
//! assert_eq!(new_data,
//! vec![
//! 3.0, 0.0, 3.0, 4.0, 1.0, 2.0,
//! 0.0, 0.0, 0.0, 1.0, -1.0, 0.0,
//! 0.0, 1.0, 1.0, 2.0, 0.0, 3.0
//! ]
//! );
//! assert_eq!(indices, vec![
//! 1, 2, 0,
//! 4, 5, 3,
//! 7, 8, 6
//! ]);
//! ```
pub use *;
pub use triangulate;
use *;
use *;
use Ordering;
use ptr;
use f64;