aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArne Dußin2020-11-21 11:23:16 +0100
committerArne Dußin2020-11-21 11:23:16 +0100
commit58ca374fab6dd90c4d7415bdcc98add002274894 (patch)
tree94ec5f6c49f9c7e4e812550c82ad21110b02c2ce
parent32aec90d0fac637e165913f194422e5b3d96de36 (diff)
downloadgraf_karto-58ca374fab6dd90c4d7415bdcc98add002274894.tar.gz
graf_karto-58ca374fab6dd90c4d7415bdcc98add002274894.zip
Move polygon functions into own mod
The math module was starting to be mostly polygon files and functions, so those got their own subfolder to make the math module less of a mess.
-rw-r--r--src/math/mod.rs4
-rw-r--r--src/math/polygon/mod.rs (renamed from src/math/polygon.rs)10
-rw-r--r--src/math/polygon/polygon_graph.rs (renamed from src/math/polygon_graph.rs)7
-rw-r--r--src/math/polygon/triangulate.rs (renamed from src/math/triangulate.rs)3
4 files changed, 15 insertions, 9 deletions
diff --git a/src/math/mod.rs b/src/math/mod.rs
index 07bc36b..e72a7a4 100644
--- a/src/math/mod.rs
+++ b/src/math/mod.rs
@@ -1,17 +1,13 @@
pub mod line_segment;
pub mod polygon;
-pub mod polygon_graph;
pub mod rect;
pub mod triangle;
-pub mod triangulate;
pub mod vec2;
pub use self::line_segment::*;
pub use self::polygon::*;
-pub use self::polygon_graph::*;
pub use self::rect::*;
pub use self::triangle::*;
-pub use self::triangulate::*;
pub use self::vec2::*;
use std::cmp::Ordering;
diff --git a/src/math/polygon.rs b/src/math/polygon/mod.rs
index 5711049..4530857 100644
--- a/src/math/polygon.rs
+++ b/src/math/polygon/mod.rs
@@ -1,4 +1,12 @@
-use super::{PolygonGraph, Vec2};
+//! Contains functions and structures to help with operations on polygons.
+
+pub mod polygon_graph;
+pub mod triangulate;
+
+pub use polygon_graph::*;
+pub use triangulate::*;
+
+use super::Vec2;
use nalgebra::{ClosedDiv, ClosedMul, ClosedSub, RealField, Scalar};
use num_traits::Zero;
use std::ops::Neg;
diff --git a/src/math/polygon_graph.rs b/src/math/polygon/polygon_graph.rs
index 14b2b0d..9477fbc 100644
--- a/src/math/polygon_graph.rs
+++ b/src/math/polygon/polygon_graph.rs
@@ -1,4 +1,5 @@
-use super::{LineSegment, Polygon, Vec2};
+use super::Polygon;
+use crate::math::{self, LineSegment, Vec2};
use nalgebra::{RealField, Scalar};
use std::cmp::{Ordering, PartialOrd};
@@ -273,8 +274,8 @@ impl<T: Scalar + Copy + PartialOrd> PolygonGraph<T> {
.adjacent
.iter()
.max_by(|&a, &b| {
- super::triplet_angle(last_vec, current_node.vec, *a)
- .partial_cmp(&super::triplet_angle(last_vec, current_node.vec, *b))
+ math::triplet_angle(last_vec, current_node.vec, *a)
+ .partial_cmp(&math::triplet_angle(last_vec, current_node.vec, *b))
.unwrap_or(Ordering::Equal)
})
.expect("Adjacency list is empty. The polygon has an open edge (is broken)");
diff --git a/src/math/triangulate.rs b/src/math/polygon/triangulate.rs
index 8ef92f1..4860518 100644
--- a/src/math/triangulate.rs
+++ b/src/math/polygon/triangulate.rs
@@ -1,6 +1,7 @@
//! Module for turning a polygon into a number of non-overlapping triangles.
-use super::{Polygon, Triangle};
+use super::Polygon;
+use crate::math::Triangle;
use nalgebra::Scalar;
/// Uses earclipping algorithm (see https://www.geometrictools.com/Documentation/TriangulationByEarClipping.pdf)