diff options
| author | Arne Dußin | 2020-11-23 23:25:45 +0100 |
|---|---|---|
| committer | Arne Dußin | 2020-11-23 23:25:45 +0100 |
| commit | 3b0c99351da92410bbfaba233e40376b767cb64e (patch) | |
| tree | 56bd28470942bc79120407a9f646b07aff5b570a /src/math/polygon/triangulate.rs | |
| parent | a6c141908ddb94a0ebb3a1ac95d3f8444e13e3b5 (diff) | |
| download | graf_karto-3b0c99351da92410bbfaba233e40376b767cb64e.tar.gz graf_karto-3b0c99351da92410bbfaba233e40376b767cb64e.zip | |
Add triangulation function
Diffstat (limited to 'src/math/polygon/triangulate.rs')
| -rw-r--r-- | src/math/polygon/triangulate.rs | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/math/polygon/triangulate.rs b/src/math/polygon/triangulate.rs index 096a1c6..78dfa03 100644 --- a/src/math/polygon/triangulate.rs +++ b/src/math/polygon/triangulate.rs @@ -117,3 +117,33 @@ where triangles } + +#[cfg(test)] +mod test { + use super::*; + use crate::math::Vec2; + + #[test] + fn triangulate() { + let polygon = Polygon::new(vec![ + Vec2::new(0., 0.), + Vec2::new(0., 4.5), + Vec2::new(6.5, 4.5), + Vec2::new(5.5, 0.), + Vec2::new(5.5, 3.), + Vec2::new(1.5, 3.), + Vec2::new(1.5, 1.), + Vec2::new(2., 0.5), + Vec2::new(4., 2.), + Vec2::new(4., 0.), + ]); + + let triangles = super::triangulate(polygon); + + assert_eq!(triangles.len(), 8); + assert_eq!( + triangles[0], + (Triangle::new(Vec2::new(2., 0.5), Vec2::new(4., 2.), Vec2::new(4., 0.))) + ); + } +} |
