From e3eb04422eaeb5e7b777f0377448956a70537549 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 16 Feb 2023 12:41:37 +0100 Subject: [PATCH] Ease requirements on `Arc`'s start/end angles Don't require `start < end`. The rest of the system doesn't need this, and it makes `Arc` itself simpler. --- crates/fj-kernel/src/builder/edge.rs | 8 ++--- crates/fj-math/src/arc.rs | 48 +++++++--------------------- 2 files changed, 13 insertions(+), 43 deletions(-) diff --git a/crates/fj-kernel/src/builder/edge.rs b/crates/fj-kernel/src/builder/edge.rs index 6ad4a737f..87c4fb2fb 100644 --- a/crates/fj-kernel/src/builder/edge.rs +++ b/crates/fj-kernel/src/builder/edge.rs @@ -119,12 +119,8 @@ impl HalfEdgeBuilder for PartialHalfEdge { .write() .update_as_circle_from_center_and_radius(arc.center, arc.radius); - let [a_curve, b_curve] = if arc.flipped_construction { - [arc.end_angle, arc.start_angle] - } else { - [arc.start_angle, arc.end_angle] - } - .map(|coord| Point::from([coord])); + let [a_curve, b_curve] = + [arc.start_angle, arc.end_angle].map(|coord| Point::from([coord])); for (vertex, point_curve) in self.vertices.each_mut_ext().zip_ext([a_curve, b_curve]) diff --git a/crates/fj-math/src/arc.rs b/crates/fj-math/src/arc.rs index 0cd991056..b7baee920 100644 --- a/crates/fj-math/src/arc.rs +++ b/crates/fj-math/src/arc.rs @@ -19,9 +19,6 @@ pub struct Arc { /// /// Guaranteed to be greater than `end_angle`. pub end_angle: Scalar, - - /// True if `start` and `end` were switched to ensure `end_angle` > `start_angle` - pub flipped_construction: bool, } impl Arc { @@ -46,17 +43,15 @@ impl Arc { let flipped_construction = angle_rad <= Scalar::ZERO; let angle_rad = angle_rad.abs(); - let [p0, p1] = if flipped_construction { - [p1, p0] - } else { - [p0, p1] - }; - - let (uv_factor, end_angle_offset) = if angle_rad > Scalar::PI { + let (mut uv_factor, end_angle_offset) = if angle_rad > Scalar::PI { (Scalar::from_f64(-1.), Scalar::TAU) } else { (Scalar::ONE, Scalar::ZERO) }; + if flipped_construction { + uv_factor *= -1.; + } + let unit_vector_p0_to_p1 = (p1 - p0) / distance_between_endpoints * uv_factor; let unit_vector_midpoint_to_center = @@ -78,7 +73,6 @@ impl Arc { radius, start_angle, end_angle, - flipped_construction, } } } @@ -143,7 +137,6 @@ mod tests { dbg!(arc.start_angle); dbg!(arc.end_angle); - dbg!(arc.flipped_construction); assert_abs_diff_eq!(arc.center, center, epsilon = epsilon); assert_abs_diff_eq!( arc.radius, @@ -151,30 +144,11 @@ mod tests { epsilon = epsilon ); - if a0 < a1 { - assert!(!arc.flipped_construction); - assert_abs_diff_eq!( - arc.start_angle, - Scalar::from(a0), - epsilon = epsilon - ); - assert_abs_diff_eq!( - arc.end_angle, - Scalar::from(a1), - epsilon = epsilon - ); - } else { - assert!(arc.flipped_construction); - assert_abs_diff_eq!( - arc.end_angle, - Scalar::from(a0), - epsilon = epsilon - ); - assert_abs_diff_eq!( - arc.start_angle, - Scalar::from(a1), - epsilon = epsilon - ); - } + assert_abs_diff_eq!( + arc.start_angle, + Scalar::from(a0), + epsilon = epsilon + ); + assert_abs_diff_eq!(arc.end_angle, Scalar::from(a1), epsilon = epsilon); } }