Upgrade to the Rust 2024 edition (#2367)

* Update to rust 2024 edition

* Fixes

* Clean up imports

* Cargo fmt again

---------

Co-authored-by: Keavon Chambers <keavon@keavon.com>
This commit is contained in:
Dennis Kobert
2025-03-12 17:29:12 -07:00
committed by GitHub
co-authored by Keavon Chambers
parent 927d7dd9b2
commit beb1c6ae64
253 changed files with 980 additions and 1371 deletions
-1
View File
@@ -1,7 +1,6 @@
use super::*;
use crate::consts::*;
use crate::utils::format_point;
use glam::DVec2;
use std::fmt::Write;
@@ -124,7 +124,6 @@ impl<PointId: crate::Identifier> Subpath<PointId> {
mod tests {
use super::*;
use crate::utils::SubpathTValue;
use glam::DVec2;
fn set_up_open_subpath() -> Subpath<EmptyId> {
+2 -3
View File
@@ -4,13 +4,12 @@ mod manipulators;
mod solvers;
mod structs;
mod transform;
pub use core::*;
pub use structs::*;
use crate::Bezier;
pub use core::*;
use std::fmt::{Debug, Formatter, Result};
use std::ops::{Index, IndexMut};
pub use structs::*;
/// Structure used to represent a path composed of [Bezier] curves.
#[derive(Clone, PartialEq, Hash)]
+151 -123
View File
@@ -1,8 +1,7 @@
use super::*;
use crate::consts::MAX_ABSOLUTE_DIFFERENCE;
use crate::utils::{compute_circular_subpath_details, is_rectangle_inside_other, line_intersection, SubpathTValue};
use crate::TValue;
use crate::consts::MAX_ABSOLUTE_DIFFERENCE;
use crate::utils::{SubpathTValue, compute_circular_subpath_details, is_rectangle_inside_other, line_intersection};
use glam::{DAffine2, DMat2, DVec2};
use std::f64::consts::PI;
@@ -539,10 +538,9 @@ impl<PointId: crate::Identifier> Subpath<PointId> {
#[cfg(test)]
mod tests {
use super::*;
use crate::Bezier;
use crate::consts::MAX_ABSOLUTE_DIFFERENCE;
use crate::utils;
use crate::Bezier;
use glam::DVec2;
fn normalize_t(n: i64, t: f64) -> f64 {
@@ -629,44 +627,54 @@ mod tests {
let mut n = (subpath.len() as i64) - 1;
let t0 = 0.;
assert!(utils::dvec2_compare(
subpath.evaluate(SubpathTValue::GlobalParametric(t0)),
linear_bezier.evaluate(TValue::Parametric(normalize_t(n, t0))),
MAX_ABSOLUTE_DIFFERENCE
)
.all());
assert!(
utils::dvec2_compare(
subpath.evaluate(SubpathTValue::GlobalParametric(t0)),
linear_bezier.evaluate(TValue::Parametric(normalize_t(n, t0))),
MAX_ABSOLUTE_DIFFERENCE
)
.all()
);
let t1 = 0.25;
assert!(utils::dvec2_compare(
subpath.evaluate(SubpathTValue::GlobalParametric(t1)),
linear_bezier.evaluate(TValue::Parametric(normalize_t(n, t1))),
MAX_ABSOLUTE_DIFFERENCE
)
.all());
assert!(
utils::dvec2_compare(
subpath.evaluate(SubpathTValue::GlobalParametric(t1)),
linear_bezier.evaluate(TValue::Parametric(normalize_t(n, t1))),
MAX_ABSOLUTE_DIFFERENCE
)
.all()
);
let t2 = 0.50;
assert!(utils::dvec2_compare(
subpath.evaluate(SubpathTValue::GlobalParametric(t2)),
quadratic_bezier.evaluate(TValue::Parametric(normalize_t(n, t2))),
MAX_ABSOLUTE_DIFFERENCE
)
.all());
assert!(
utils::dvec2_compare(
subpath.evaluate(SubpathTValue::GlobalParametric(t2)),
quadratic_bezier.evaluate(TValue::Parametric(normalize_t(n, t2))),
MAX_ABSOLUTE_DIFFERENCE
)
.all()
);
let t3 = 0.75;
assert!(utils::dvec2_compare(
subpath.evaluate(SubpathTValue::GlobalParametric(t3)),
quadratic_bezier.evaluate(TValue::Parametric(normalize_t(n, t3))),
MAX_ABSOLUTE_DIFFERENCE
)
.all());
assert!(
utils::dvec2_compare(
subpath.evaluate(SubpathTValue::GlobalParametric(t3)),
quadratic_bezier.evaluate(TValue::Parametric(normalize_t(n, t3))),
MAX_ABSOLUTE_DIFFERENCE
)
.all()
);
let t4 = 1.;
assert!(utils::dvec2_compare(
subpath.evaluate(SubpathTValue::GlobalParametric(t4)),
quadratic_bezier.evaluate(TValue::Parametric(1.)),
MAX_ABSOLUTE_DIFFERENCE
)
.all());
assert!(
utils::dvec2_compare(
subpath.evaluate(SubpathTValue::GlobalParametric(t4)),
quadratic_bezier.evaluate(TValue::Parametric(1.)),
MAX_ABSOLUTE_DIFFERENCE
)
.all()
);
// Test closed subpath
@@ -674,20 +682,24 @@ mod tests {
n = subpath.len() as i64;
let t5 = 2. / 3.;
assert!(utils::dvec2_compare(
subpath.evaluate(SubpathTValue::GlobalParametric(t5)),
cubic_bezier.evaluate(TValue::Parametric(normalize_t(n, t5))),
MAX_ABSOLUTE_DIFFERENCE
)
.all());
assert!(
utils::dvec2_compare(
subpath.evaluate(SubpathTValue::GlobalParametric(t5)),
cubic_bezier.evaluate(TValue::Parametric(normalize_t(n, t5))),
MAX_ABSOLUTE_DIFFERENCE
)
.all()
);
let t6 = 1.;
assert!(utils::dvec2_compare(
subpath.evaluate(SubpathTValue::GlobalParametric(t6)),
cubic_bezier.evaluate(TValue::Parametric(1.)),
MAX_ABSOLUTE_DIFFERENCE
)
.all());
assert!(
utils::dvec2_compare(
subpath.evaluate(SubpathTValue::GlobalParametric(t6)),
cubic_bezier.evaluate(TValue::Parametric(1.)),
MAX_ABSOLUTE_DIFFERENCE
)
.all()
);
}
#[test]
@@ -737,35 +749,41 @@ mod tests {
let quadratic_1_intersections = quadratic_bezier_1.intersections(&line, None, None);
let subpath_intersections = subpath.intersections(&line, None, None);
assert!(utils::dvec2_compare(
cubic_bezier.evaluate(TValue::Parametric(cubic_intersections[0])),
subpath.evaluate(SubpathTValue::Parametric {
segment_index: subpath_intersections[0].0,
t: subpath_intersections[0].1
}),
MAX_ABSOLUTE_DIFFERENCE
)
.all());
assert!(
utils::dvec2_compare(
cubic_bezier.evaluate(TValue::Parametric(cubic_intersections[0])),
subpath.evaluate(SubpathTValue::Parametric {
segment_index: subpath_intersections[0].0,
t: subpath_intersections[0].1
}),
MAX_ABSOLUTE_DIFFERENCE
)
.all()
);
assert!(utils::dvec2_compare(
quadratic_bezier_1.evaluate(TValue::Parametric(quadratic_1_intersections[0])),
subpath.evaluate(SubpathTValue::Parametric {
segment_index: subpath_intersections[1].0,
t: subpath_intersections[1].1
}),
MAX_ABSOLUTE_DIFFERENCE
)
.all());
assert!(
utils::dvec2_compare(
quadratic_bezier_1.evaluate(TValue::Parametric(quadratic_1_intersections[0])),
subpath.evaluate(SubpathTValue::Parametric {
segment_index: subpath_intersections[1].0,
t: subpath_intersections[1].1
}),
MAX_ABSOLUTE_DIFFERENCE
)
.all()
);
assert!(utils::dvec2_compare(
quadratic_bezier_1.evaluate(TValue::Parametric(quadratic_1_intersections[1])),
subpath.evaluate(SubpathTValue::Parametric {
segment_index: subpath_intersections[2].0,
t: subpath_intersections[2].1
}),
MAX_ABSOLUTE_DIFFERENCE
)
.all());
assert!(
utils::dvec2_compare(
quadratic_bezier_1.evaluate(TValue::Parametric(quadratic_1_intersections[1])),
subpath.evaluate(SubpathTValue::Parametric {
segment_index: subpath_intersections[2].0,
t: subpath_intersections[2].1
}),
MAX_ABSOLUTE_DIFFERENCE
)
.all()
);
}
#[test]
@@ -816,25 +834,29 @@ mod tests {
let quadratic_1_intersections = quadratic_bezier_1.intersections(&line, None, None);
let subpath_intersections = subpath.intersections(&line, None, None);
assert!(utils::dvec2_compare(
cubic_bezier.evaluate(TValue::Parametric(cubic_intersections[0])),
subpath.evaluate(SubpathTValue::Parametric {
segment_index: subpath_intersections[0].0,
t: subpath_intersections[0].1
}),
MAX_ABSOLUTE_DIFFERENCE
)
.all());
assert!(
utils::dvec2_compare(
cubic_bezier.evaluate(TValue::Parametric(cubic_intersections[0])),
subpath.evaluate(SubpathTValue::Parametric {
segment_index: subpath_intersections[0].0,
t: subpath_intersections[0].1
}),
MAX_ABSOLUTE_DIFFERENCE
)
.all()
);
assert!(utils::dvec2_compare(
quadratic_bezier_1.evaluate(TValue::Parametric(quadratic_1_intersections[0])),
subpath.evaluate(SubpathTValue::Parametric {
segment_index: subpath_intersections[1].0,
t: subpath_intersections[1].1
}),
MAX_ABSOLUTE_DIFFERENCE
)
.all());
assert!(
utils::dvec2_compare(
quadratic_bezier_1.evaluate(TValue::Parametric(quadratic_1_intersections[0])),
subpath.evaluate(SubpathTValue::Parametric {
segment_index: subpath_intersections[1].0,
t: subpath_intersections[1].1
}),
MAX_ABSOLUTE_DIFFERENCE
)
.all()
);
}
#[test]
@@ -884,35 +906,41 @@ mod tests {
let quadratic_1_intersections = quadratic_bezier_1.intersections(&line, None, None);
let subpath_intersections = subpath.intersections(&line, None, None);
assert!(utils::dvec2_compare(
cubic_bezier.evaluate(TValue::Parametric(cubic_intersections[0])),
subpath.evaluate(SubpathTValue::Parametric {
segment_index: subpath_intersections[0].0,
t: subpath_intersections[0].1
}),
MAX_ABSOLUTE_DIFFERENCE
)
.all());
assert!(
utils::dvec2_compare(
cubic_bezier.evaluate(TValue::Parametric(cubic_intersections[0])),
subpath.evaluate(SubpathTValue::Parametric {
segment_index: subpath_intersections[0].0,
t: subpath_intersections[0].1
}),
MAX_ABSOLUTE_DIFFERENCE
)
.all()
);
assert!(utils::dvec2_compare(
quadratic_bezier_1.evaluate(TValue::Parametric(quadratic_1_intersections[0])),
subpath.evaluate(SubpathTValue::Parametric {
segment_index: subpath_intersections[1].0,
t: subpath_intersections[1].1
}),
MAX_ABSOLUTE_DIFFERENCE
)
.all());
assert!(
utils::dvec2_compare(
quadratic_bezier_1.evaluate(TValue::Parametric(quadratic_1_intersections[0])),
subpath.evaluate(SubpathTValue::Parametric {
segment_index: subpath_intersections[1].0,
t: subpath_intersections[1].1
}),
MAX_ABSOLUTE_DIFFERENCE
)
.all()
);
assert!(utils::dvec2_compare(
quadratic_bezier_1.evaluate(TValue::Parametric(quadratic_1_intersections[1])),
subpath.evaluate(SubpathTValue::Parametric {
segment_index: subpath_intersections[2].0,
t: subpath_intersections[2].1
}),
MAX_ABSOLUTE_DIFFERENCE
)
.all());
assert!(
utils::dvec2_compare(
quadratic_bezier_1.evaluate(TValue::Parametric(quadratic_1_intersections[1])),
subpath.evaluate(SubpathTValue::Parametric {
segment_index: subpath_intersections[2].0,
t: subpath_intersections[2].1
}),
MAX_ABSOLUTE_DIFFERENCE
)
.all()
);
}
// TODO: add more intersection tests
@@ -924,19 +952,19 @@ mod tests {
let curve = Bezier::from_quadratic_dvec2(DVec2::new(189., 289.), DVec2::new(9., 286.), DVec2::new(45., 410.));
let curve_intersecting = Subpath::<EmptyId>::from_bezier(&curve);
assert_eq!(curve_intersecting.is_inside_subpath(&boundary_polygon, None, None), false);
assert!(!curve_intersecting.is_inside_subpath(&boundary_polygon, None, None));
let curve = Bezier::from_quadratic_dvec2(DVec2::new(115., 37.), DVec2::new(51.4, 91.8), DVec2::new(76.5, 242.));
let curve_outside = Subpath::<EmptyId>::from_bezier(&curve);
assert_eq!(curve_outside.is_inside_subpath(&boundary_polygon, None, None), false);
assert!(!curve_outside.is_inside_subpath(&boundary_polygon, None, None));
let curve = Bezier::from_cubic_dvec2(DVec2::new(210.1, 133.5), DVec2::new(150.2, 436.9), DVec2::new(436., 285.), DVec2::new(247.6, 240.7));
let curve_inside = Subpath::<EmptyId>::from_bezier(&curve);
assert_eq!(curve_inside.is_inside_subpath(&boundary_polygon, None, None), true);
assert!(curve_inside.is_inside_subpath(&boundary_polygon, None, None));
let line = Bezier::from_linear_dvec2(DVec2::new(101., 101.5), DVec2::new(150.2, 499.));
let line_inside = Subpath::<EmptyId>::from_bezier(&line);
assert_eq!(line_inside.is_inside_subpath(&boundary_polygon, None, None), true);
assert!(line_inside.is_inside_subpath(&boundary_polygon, None, None));
}
#[test]
+3 -6
View File
@@ -1,10 +1,7 @@
use super::Bezier;
use glam::{DAffine2, DVec2};
use std::{
fmt::{Debug, Formatter, Result},
hash::Hash,
};
use std::fmt::{Debug, Formatter, Result};
use std::hash::Hash;
/// An id type used for each [ManipulatorGroup].
pub trait Identifier: Sized + Clone + PartialEq + Hash + 'static {
@@ -113,7 +110,7 @@ impl<PointId: crate::Identifier> ManipulatorGroup<PointId> {
/// Are all handles at finite positions
pub fn is_finite(&self) -> bool {
self.anchor.is_finite() && self.in_handle.map_or(true, |handle| handle.is_finite()) && self.out_handle.map_or(true, |handle| handle.is_finite())
self.anchor.is_finite() && self.in_handle.is_none_or(|handle| handle.is_finite()) && self.out_handle.is_none_or(|handle| handle.is_finite())
}
/// Reverse directions of handles
+3 -9
View File
@@ -1,20 +1,14 @@
use std::vec;
use super::*;
use crate::consts::MAX_ABSOLUTE_DIFFERENCE;
use crate::utils::{Cap, Join, SubpathTValue, TValue};
use glam::{DAffine2, DVec2};
use std::vec;
/// Helper function to ensure the index and t value pair is mapped within a maximum index value.
/// Allows for the point to be fetched without needing to handle an additional edge case.
/// - Ex. Via `subpath.iter().nth(index).evaluate(t);`
fn map_index_within_range(index: usize, t: f64, max_size: usize) -> (usize, f64) {
if max_size > 0 && index == max_size && t == 0. {
(index - 1, 1.)
} else {
(index, t)
}
if max_size > 0 && index == max_size && t == 0. { (index - 1, 1.) } else { (index, t) }
}
/// Functionality that transforms Subpaths, such as split, reduce, offset, etc.
@@ -549,10 +543,10 @@ impl<PointId: crate::Identifier> Subpath<PointId> {
#[cfg(test)]
mod tests {
use super::{Cap, Join, ManipulatorGroup, Subpath};
use crate::EmptyId;
use crate::compare::{compare_points, compare_subpaths, compare_vec_of_points};
use crate::consts::MAX_ABSOLUTE_DIFFERENCE;
use crate::utils::{SubpathTValue, TValue};
use crate::EmptyId;
use glam::DVec2;
fn set_up_open_subpath() -> Subpath<EmptyId> {