mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-15 14:18:04 +08:00
Put all #[test] in a mod tests (#2728)
workspace: put all `#[test]` in a `mod tests`
This commit is contained in:
committed by
Keavon Chambers
parent
579bedd9ff
commit
006209c5d0
@@ -570,28 +570,33 @@ pub fn solve_spline_first_handle_closed(points: &[DVec2]) -> Vec<DVec2> {
|
||||
x
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn closed_spline() {
|
||||
// These points are just chosen arbitrary
|
||||
let points = [DVec2::new(0., 0.), DVec2::new(0., 0.), DVec2::new(6., 5.), DVec2::new(7., 9.), DVec2::new(2., 3.)];
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
let out_handles = solve_spline_first_handle_closed(&points);
|
||||
#[test]
|
||||
fn closed_spline() {
|
||||
// These points are just chosen arbitrary
|
||||
let points = [DVec2::new(0., 0.), DVec2::new(0., 0.), DVec2::new(6., 5.), DVec2::new(7., 9.), DVec2::new(2., 3.)];
|
||||
|
||||
// Construct the Subpath
|
||||
let mut manipulator_groups = Vec::new();
|
||||
for i in 0..out_handles.len() {
|
||||
manipulator_groups.push(ManipulatorGroup::<EmptyId>::new(points[i], Some(2. * points[i] - out_handles[i]), Some(out_handles[i])));
|
||||
}
|
||||
let subpath = Subpath::new(manipulator_groups, true);
|
||||
let out_handles = solve_spline_first_handle_closed(&points);
|
||||
|
||||
// For each pair of bézier curves, ensure that the second derivative is continuous
|
||||
for (bézier_a, bézier_b) in subpath.iter().zip(subpath.iter().skip(1).chain(subpath.iter().take(1))) {
|
||||
let derivative2_end_a = bézier_a.derivative().unwrap().derivative().unwrap().evaluate(crate::TValue::Parametric(1.));
|
||||
let derivative2_start_b = bézier_b.derivative().unwrap().derivative().unwrap().evaluate(crate::TValue::Parametric(0.));
|
||||
// Construct the Subpath
|
||||
let mut manipulator_groups = Vec::new();
|
||||
for i in 0..out_handles.len() {
|
||||
manipulator_groups.push(ManipulatorGroup::<EmptyId>::new(points[i], Some(2. * points[i] - out_handles[i]), Some(out_handles[i])));
|
||||
}
|
||||
let subpath = Subpath::new(manipulator_groups, true);
|
||||
|
||||
assert!(
|
||||
derivative2_end_a.abs_diff_eq(derivative2_start_b, 1e-10),
|
||||
"second derivative at the end of a {derivative2_end_a} is equal to the second derivative at the start of b {derivative2_start_b}"
|
||||
);
|
||||
// For each pair of bézier curves, ensure that the second derivative is continuous
|
||||
for (bézier_a, bézier_b) in subpath.iter().zip(subpath.iter().skip(1).chain(subpath.iter().take(1))) {
|
||||
let derivative2_end_a = bézier_a.derivative().unwrap().derivative().unwrap().evaluate(crate::TValue::Parametric(1.));
|
||||
let derivative2_start_b = bézier_b.derivative().unwrap().derivative().unwrap().evaluate(crate::TValue::Parametric(0.));
|
||||
|
||||
assert!(
|
||||
derivative2_end_a.abs_diff_eq(derivative2_start_b, 1e-10),
|
||||
"second derivative at the end of a {derivative2_end_a} is equal to the second derivative at the start of b {derivative2_start_b}"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user