aboutsummaryrefslogtreecommitdiff
path: root/src/math/polygon/mod.rs
diff options
context:
space:
mode:
authorArne Dußin2021-01-11 12:10:16 +0100
committerArne Dußin2021-01-11 12:10:16 +0100
commitec071d5bc677101c0168b5fb3065f2d928234ed9 (patch)
tree963ae90a6563c1f08d8e52078afd62db32e182f0 /src/math/polygon/mod.rs
parentad1e79a517ce64eda7b06bb1567d3df070813dca (diff)
downloadgraf_karto-ec071d5bc677101c0168b5fb3065f2d928234ed9.tar.gz
graf_karto-ec071d5bc677101c0168b5fb3065f2d928234ed9.zip
Rect rooms are now normal polygon rooms in data
Before there was an extra data type for rectangular rooms. This is now changed, with the rectangle tool remaining, to create these often required rooms faster, but the data type is just a normal polygon that is generated from a rect to reduce redundancy.
Diffstat (limited to 'src/math/polygon/mod.rs')
-rw-r--r--src/math/polygon/mod.rs10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/math/polygon/mod.rs b/src/math/polygon/mod.rs
index bc145ed..02d8abb 100644
--- a/src/math/polygon/mod.rs
+++ b/src/math/polygon/mod.rs
@@ -58,13 +58,11 @@ impl<T: Scalar + Copy> Polygon<T> {
}
/// Like new, but does not perform any validity checks, so be careful when using this function.
- pub fn new_unchecked<M>(corners: Vec<Vec2<T>>, t_margin: M) -> Self
+ pub(crate) fn new_unchecked<M>(corners: Vec<Vec2<T>>, t_margin: M) -> Self
where
T: RealField + ApproxEq<Margin = M>,
M: Copy,
{
- assert!(Polygon::check_validity(&corners, t_margin).is_ok());
-
let corners = if combined_angle(&corners, t_margin) > T::zero() {
corners
} else {
@@ -74,6 +72,12 @@ impl<T: Scalar + Copy> Polygon<T> {
Self { corners }
}
+ /// Create a polygon from the sorted vertices. This will create an invalid polygon if the
+ /// vertices are not sorted so that the edges turn counterclockwise, so use with caution.
+ pub(crate) fn from_vertices(corners: Vec<Vec2<T>>) -> Self {
+ Self { corners }
+ }
+
/// Checks if a set of corners can be made into a polygon or not. Returns Ok if they can, or
/// the reason they cannot in form of a PolygonError.
pub fn check_validity<M>(corners: &[Vec2<T>], t_margin: M) -> Result<(), PolygonError<T>>