From e3eb04422eaeb5e7b777f0377448956a70537549 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 16 Feb 2023 12:41:37 +0100 Subject: [PATCH 01/21] 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); } } From 92e85e408dd166539f1ecc20be6b142293925777 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 16 Feb 2023 12:42:42 +0100 Subject: [PATCH 02/21] Update doc comments --- crates/fj-math/src/arc.rs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/crates/fj-math/src/arc.rs b/crates/fj-math/src/arc.rs index b7baee920..2fa759129 100644 --- a/crates/fj-math/src/arc.rs +++ b/crates/fj-math/src/arc.rs @@ -11,13 +11,9 @@ pub struct Arc { pub radius: Scalar, /// Angle of `start` relative to `center`, in radians - /// - /// Guaranteed to be less than `end_angle`. pub start_angle: Scalar, /// Angle of `end` relative to `center`, in radians - /// - /// Guaranteed to be greater than `end_angle`. pub end_angle: Scalar, } From bc71fc79cc25c84629807e66f8934dd5e9845cb4 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 16 Feb 2023 12:44:57 +0100 Subject: [PATCH 03/21] Inline variable --- crates/fj-math/src/arc.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/fj-math/src/arc.rs b/crates/fj-math/src/arc.rs index 2fa759129..412a11788 100644 --- a/crates/fj-math/src/arc.rs +++ b/crates/fj-math/src/arc.rs @@ -37,9 +37,9 @@ impl Arc { (radius.powi(2) - (distance_between_endpoints.powi(2) / 4.)).sqrt(); let flipped_construction = angle_rad <= Scalar::ZERO; - let angle_rad = angle_rad.abs(); - let (mut uv_factor, end_angle_offset) = if angle_rad > Scalar::PI { + let (mut uv_factor, end_angle_offset) = if angle_rad.abs() > Scalar::PI + { (Scalar::from_f64(-1.), Scalar::TAU) } else { (Scalar::ONE, Scalar::ZERO) From 9d9a5ea6762a5de854d5c12e4d87852eae3add62 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 16 Feb 2023 12:45:46 +0100 Subject: [PATCH 04/21] Inline variable --- crates/fj-math/src/arc.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/crates/fj-math/src/arc.rs b/crates/fj-math/src/arc.rs index 412a11788..8758cb236 100644 --- a/crates/fj-math/src/arc.rs +++ b/crates/fj-math/src/arc.rs @@ -36,15 +36,13 @@ impl Arc { let distance_center_to_midpoint = (radius.powi(2) - (distance_between_endpoints.powi(2) / 4.)).sqrt(); - let flipped_construction = angle_rad <= Scalar::ZERO; - let (mut uv_factor, end_angle_offset) = if angle_rad.abs() > Scalar::PI { (Scalar::from_f64(-1.), Scalar::TAU) } else { (Scalar::ONE, Scalar::ZERO) }; - if flipped_construction { + if angle_rad <= Scalar::ZERO { uv_factor *= -1.; } From ebbab66f64ed053a1c059ceae755b6fcd8302ed0 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 16 Feb 2023 12:50:45 +0100 Subject: [PATCH 05/21] Refactor --- crates/fj-math/src/arc.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/crates/fj-math/src/arc.rs b/crates/fj-math/src/arc.rs index 8758cb236..42f0809d4 100644 --- a/crates/fj-math/src/arc.rs +++ b/crates/fj-math/src/arc.rs @@ -36,8 +36,9 @@ impl Arc { let distance_center_to_midpoint = (radius.powi(2) - (distance_between_endpoints.powi(2) / 4.)).sqrt(); - let (mut uv_factor, end_angle_offset) = if angle_rad.abs() > Scalar::PI - { + let angle_more_than_half_turn = angle_rad.abs() > Scalar::PI; + + let (mut uv_factor, end_angle_offset) = if angle_more_than_half_turn { (Scalar::from_f64(-1.), Scalar::TAU) } else { (Scalar::ONE, Scalar::ZERO) From 51947428a8f5df1d0436f1d49e39825bf48a71b1 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 16 Feb 2023 12:51:33 +0100 Subject: [PATCH 06/21] Refactor --- crates/fj-math/src/arc.rs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/crates/fj-math/src/arc.rs b/crates/fj-math/src/arc.rs index 42f0809d4..d32c586f3 100644 --- a/crates/fj-math/src/arc.rs +++ b/crates/fj-math/src/arc.rs @@ -38,14 +38,19 @@ impl Arc { let angle_more_than_half_turn = angle_rad.abs() > Scalar::PI; - let (mut uv_factor, end_angle_offset) = if angle_more_than_half_turn { - (Scalar::from_f64(-1.), Scalar::TAU) + let uv_factor = + match (angle_rad <= Scalar::ZERO, angle_more_than_half_turn) { + (false, false) => Scalar::ONE, + (false, true) => -Scalar::ONE, + (true, false) => -Scalar::ONE, + (true, true) => Scalar::ONE, + }; + + let end_angle_offset = if angle_more_than_half_turn { + Scalar::TAU } else { - (Scalar::ONE, Scalar::ZERO) + Scalar::ZERO }; - if angle_rad <= Scalar::ZERO { - uv_factor *= -1.; - } let unit_vector_p0_to_p1 = (p1 - p0) / distance_between_endpoints * uv_factor; From 522156f592672fbfdf0688de6f0ca0ead4462428 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 16 Feb 2023 12:54:05 +0100 Subject: [PATCH 07/21] Refactor --- crates/fj-math/src/arc.rs | 41 +++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/crates/fj-math/src/arc.rs b/crates/fj-math/src/arc.rs index d32c586f3..234733362 100644 --- a/crates/fj-math/src/arc.rs +++ b/crates/fj-math/src/arc.rs @@ -33,18 +33,33 @@ impl Arc { let distance_between_endpoints = (p1 - p0).magnitude(); let radius = distance_between_endpoints / (2. * (angle_rad.abs().into_f64() / 2.).sin()); - let distance_center_to_midpoint = - (radius.powi(2) - (distance_between_endpoints.powi(2) / 4.)).sqrt(); let angle_more_than_half_turn = angle_rad.abs() > Scalar::PI; - let uv_factor = - match (angle_rad <= Scalar::ZERO, angle_more_than_half_turn) { - (false, false) => Scalar::ONE, - (false, true) => -Scalar::ONE, - (true, false) => -Scalar::ONE, - (true, true) => Scalar::ONE, - }; + let center = { + let uv_factor = + match (angle_rad <= Scalar::ZERO, angle_more_than_half_turn) { + (false, false) => Scalar::ONE, + (false, true) => -Scalar::ONE, + (true, false) => -Scalar::ONE, + (true, true) => Scalar::ONE, + }; + + let unit_vector_p0_to_p1 = + (p1 - p0) / distance_between_endpoints * uv_factor; + + let unit_vector_midpoint_to_center = + Vector::from([-unit_vector_p0_to_p1.v, unit_vector_p0_to_p1.u]); + let distance_center_to_midpoint = (radius.powi(2) + - (distance_between_endpoints.powi(2) / 4.)) + .sqrt(); + + Point { + coords: (p0.coords + p1.coords) / 2. + + unit_vector_midpoint_to_center + * distance_center_to_midpoint, + } + }; let end_angle_offset = if angle_more_than_half_turn { Scalar::TAU @@ -52,14 +67,6 @@ impl Arc { Scalar::ZERO }; - let unit_vector_p0_to_p1 = - (p1 - p0) / distance_between_endpoints * uv_factor; - let unit_vector_midpoint_to_center = - Vector::from([-unit_vector_p0_to_p1.v, unit_vector_p0_to_p1.u]); - let center = Point { - coords: (p0.coords + p1.coords) / 2. - + unit_vector_midpoint_to_center * distance_center_to_midpoint, - }; let start_angle = { let center_to_start = p0 - center; center_to_start.v.atan2(center_to_start.u) From 8c96af536c31480f6ca7f7ebf319b12aebb3aac4 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 16 Feb 2023 12:54:23 +0100 Subject: [PATCH 08/21] Simplify variable name --- crates/fj-math/src/arc.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/crates/fj-math/src/arc.rs b/crates/fj-math/src/arc.rs index 234733362..681b1215b 100644 --- a/crates/fj-math/src/arc.rs +++ b/crates/fj-math/src/arc.rs @@ -37,16 +37,16 @@ impl Arc { let angle_more_than_half_turn = angle_rad.abs() > Scalar::PI; let center = { - let uv_factor = - match (angle_rad <= Scalar::ZERO, angle_more_than_half_turn) { - (false, false) => Scalar::ONE, - (false, true) => -Scalar::ONE, - (true, false) => -Scalar::ONE, - (true, true) => Scalar::ONE, - }; + let f = match (angle_rad <= Scalar::ZERO, angle_more_than_half_turn) + { + (false, false) => Scalar::ONE, + (false, true) => -Scalar::ONE, + (true, false) => -Scalar::ONE, + (true, true) => Scalar::ONE, + }; let unit_vector_p0_to_p1 = - (p1 - p0) / distance_between_endpoints * uv_factor; + (p1 - p0) / distance_between_endpoints * f; let unit_vector_midpoint_to_center = Vector::from([-unit_vector_p0_to_p1.v, unit_vector_p0_to_p1.u]); From a6683aa19fd69e40c7d7fcd286be08b3f3bee032 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 16 Feb 2023 12:54:38 +0100 Subject: [PATCH 09/21] Simplify variable name --- crates/fj-math/src/arc.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/crates/fj-math/src/arc.rs b/crates/fj-math/src/arc.rs index 681b1215b..aa95a4cab 100644 --- a/crates/fj-math/src/arc.rs +++ b/crates/fj-math/src/arc.rs @@ -34,11 +34,10 @@ impl Arc { let radius = distance_between_endpoints / (2. * (angle_rad.abs().into_f64() / 2.).sin()); - let angle_more_than_half_turn = angle_rad.abs() > Scalar::PI; + let more_than_half_turn = angle_rad.abs() > Scalar::PI; let center = { - let f = match (angle_rad <= Scalar::ZERO, angle_more_than_half_turn) - { + let f = match (angle_rad <= Scalar::ZERO, more_than_half_turn) { (false, false) => Scalar::ONE, (false, true) => -Scalar::ONE, (true, false) => -Scalar::ONE, @@ -61,7 +60,7 @@ impl Arc { } }; - let end_angle_offset = if angle_more_than_half_turn { + let end_angle_offset = if more_than_half_turn { Scalar::TAU } else { Scalar::ZERO From dc2bfaa0bd105a84ae071d0eb542f243617c2097 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 16 Feb 2023 12:55:09 +0100 Subject: [PATCH 10/21] Refactor --- crates/fj-math/src/arc.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/fj-math/src/arc.rs b/crates/fj-math/src/arc.rs index aa95a4cab..75173f9cf 100644 --- a/crates/fj-math/src/arc.rs +++ b/crates/fj-math/src/arc.rs @@ -34,10 +34,11 @@ impl Arc { let radius = distance_between_endpoints / (2. * (angle_rad.abs().into_f64() / 2.).sin()); + let clockwise_turn = angle_rad <= Scalar::ZERO; let more_than_half_turn = angle_rad.abs() > Scalar::PI; let center = { - let f = match (angle_rad <= Scalar::ZERO, more_than_half_turn) { + let f = match (clockwise_turn, more_than_half_turn) { (false, false) => Scalar::ONE, (false, true) => -Scalar::ONE, (true, false) => -Scalar::ONE, From db4a0d5ffa2cbaf92c2d4c4ce0476a9317e86fb3 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 16 Feb 2023 12:55:39 +0100 Subject: [PATCH 11/21] Simplify match --- crates/fj-math/src/arc.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/crates/fj-math/src/arc.rs b/crates/fj-math/src/arc.rs index 75173f9cf..8b90c0a43 100644 --- a/crates/fj-math/src/arc.rs +++ b/crates/fj-math/src/arc.rs @@ -39,10 +39,8 @@ impl Arc { let center = { let f = match (clockwise_turn, more_than_half_turn) { - (false, false) => Scalar::ONE, - (false, true) => -Scalar::ONE, - (true, false) => -Scalar::ONE, - (true, true) => Scalar::ONE, + (false, false) | (true, true) => Scalar::ONE, + (false, true) | (true, false) => -Scalar::ONE, }; let unit_vector_p0_to_p1 = From 616a2b01e0854a892f098589d0f2279a2dd65c5a Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 16 Feb 2023 12:56:27 +0100 Subject: [PATCH 12/21] Refactor --- crates/fj-math/src/arc.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/crates/fj-math/src/arc.rs b/crates/fj-math/src/arc.rs index 8b90c0a43..add8c1d7a 100644 --- a/crates/fj-math/src/arc.rs +++ b/crates/fj-math/src/arc.rs @@ -59,18 +59,18 @@ impl Arc { } }; - let end_angle_offset = if more_than_half_turn { - Scalar::TAU - } else { - Scalar::ZERO - }; - let start_angle = { let center_to_start = p0 - center; center_to_start.v.atan2(center_to_start.u) }; let end_angle = { let center_to_end = p1 - center; + let end_angle_offset = if more_than_half_turn { + Scalar::TAU + } else { + Scalar::ZERO + }; + center_to_end.v.atan2(center_to_end.u) + end_angle_offset }; Self { From 753dfe359a1e067af4ea3c66038aae958d42a643 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 16 Feb 2023 12:56:42 +0100 Subject: [PATCH 13/21] Simplify variable name --- crates/fj-math/src/arc.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/fj-math/src/arc.rs b/crates/fj-math/src/arc.rs index add8c1d7a..952e2b5d7 100644 --- a/crates/fj-math/src/arc.rs +++ b/crates/fj-math/src/arc.rs @@ -65,13 +65,13 @@ impl Arc { }; let end_angle = { let center_to_end = p1 - center; - let end_angle_offset = if more_than_half_turn { + let offset = if more_than_half_turn { Scalar::TAU } else { Scalar::ZERO }; - center_to_end.v.atan2(center_to_end.u) + end_angle_offset + center_to_end.v.atan2(center_to_end.u) + offset }; Self { center, From 4794b3d2517d78c3ba103dfc63a3bd88cf2c7b37 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 16 Feb 2023 12:57:06 +0100 Subject: [PATCH 14/21] Simplify variable name --- crates/fj-math/src/arc.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/fj-math/src/arc.rs b/crates/fj-math/src/arc.rs index 952e2b5d7..11eabe70a 100644 --- a/crates/fj-math/src/arc.rs +++ b/crates/fj-math/src/arc.rs @@ -64,14 +64,14 @@ impl Arc { center_to_start.v.atan2(center_to_start.u) }; let end_angle = { - let center_to_end = p1 - center; + let from_center = p1 - center; let offset = if more_than_half_turn { Scalar::TAU } else { Scalar::ZERO }; - center_to_end.v.atan2(center_to_end.u) + offset + from_center.v.atan2(from_center.u) + offset }; Self { center, From a02f31cb113cd0360507fb9022c40629a8206a12 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 16 Feb 2023 12:57:17 +0100 Subject: [PATCH 15/21] Simplify variable name --- crates/fj-math/src/arc.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/fj-math/src/arc.rs b/crates/fj-math/src/arc.rs index 11eabe70a..e5271df8b 100644 --- a/crates/fj-math/src/arc.rs +++ b/crates/fj-math/src/arc.rs @@ -60,8 +60,8 @@ impl Arc { }; let start_angle = { - let center_to_start = p0 - center; - center_to_start.v.atan2(center_to_start.u) + let from_center = p0 - center; + from_center.v.atan2(from_center.u) }; let end_angle = { let from_center = p1 - center; From 521f1ab550f77618f973f612d1b5cba373c14f3a Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 16 Feb 2023 12:57:54 +0100 Subject: [PATCH 16/21] Improve wording in comment --- crates/fj-math/src/arc.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/fj-math/src/arc.rs b/crates/fj-math/src/arc.rs index e5271df8b..1549b0717 100644 --- a/crates/fj-math/src/arc.rs +++ b/crates/fj-math/src/arc.rs @@ -27,7 +27,7 @@ impl Arc { let p0 = p0.into(); let p1 = p1.into(); - // This is an implementation of this solution: + // This is an adaptation of this: // https://math.stackexchange.com/a/87374 let distance_between_endpoints = (p1 - p0).magnitude(); From e9060e7e2c981b92814879d5f08a1c16b6a01853 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 16 Feb 2023 12:59:14 +0100 Subject: [PATCH 17/21] Move variable closer to where it's used --- crates/fj-math/src/arc.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/fj-math/src/arc.rs b/crates/fj-math/src/arc.rs index 1549b0717..02a626185 100644 --- a/crates/fj-math/src/arc.rs +++ b/crates/fj-math/src/arc.rs @@ -34,10 +34,10 @@ impl Arc { let radius = distance_between_endpoints / (2. * (angle_rad.abs().into_f64() / 2.).sin()); - let clockwise_turn = angle_rad <= Scalar::ZERO; let more_than_half_turn = angle_rad.abs() > Scalar::PI; let center = { + let clockwise_turn = angle_rad <= Scalar::ZERO; let f = match (clockwise_turn, more_than_half_turn) { (false, false) | (true, true) => Scalar::ONE, (false, true) | (true, false) => -Scalar::ONE, From 67b51f22ec8b7605d2c83548b04498537efba1fb Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 16 Feb 2023 12:59:42 +0100 Subject: [PATCH 18/21] Group calculations used multiple times --- crates/fj-math/src/arc.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/fj-math/src/arc.rs b/crates/fj-math/src/arc.rs index 02a626185..16fa45a85 100644 --- a/crates/fj-math/src/arc.rs +++ b/crates/fj-math/src/arc.rs @@ -31,11 +31,11 @@ impl Arc { // https://math.stackexchange.com/a/87374 let distance_between_endpoints = (p1 - p0).magnitude(); + let more_than_half_turn = angle_rad.abs() > Scalar::PI; + let radius = distance_between_endpoints / (2. * (angle_rad.abs().into_f64() / 2.).sin()); - let more_than_half_turn = angle_rad.abs() > Scalar::PI; - let center = { let clockwise_turn = angle_rad <= Scalar::ZERO; let f = match (clockwise_turn, more_than_half_turn) { From d105d1500c4db7d6858a53fbb589da452ca1d020 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 16 Feb 2023 13:01:03 +0100 Subject: [PATCH 19/21] Refactor --- crates/fj-math/src/arc.rs | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/crates/fj-math/src/arc.rs b/crates/fj-math/src/arc.rs index 16fa45a85..2da7f6735 100644 --- a/crates/fj-math/src/arc.rs +++ b/crates/fj-math/src/arc.rs @@ -37,17 +37,18 @@ impl Arc { / (2. * (angle_rad.abs().into_f64() / 2.).sin()); let center = { - let clockwise_turn = angle_rad <= Scalar::ZERO; - let f = match (clockwise_turn, more_than_half_turn) { - (false, false) | (true, true) => Scalar::ONE, - (false, true) | (true, false) => -Scalar::ONE, - }; + let unit_vector_midpoint_to_center = { + let clockwise_turn = angle_rad <= Scalar::ZERO; + let f = match (clockwise_turn, more_than_half_turn) { + (false, false) | (true, true) => Scalar::ONE, + (false, true) | (true, false) => -Scalar::ONE, + }; - let unit_vector_p0_to_p1 = - (p1 - p0) / distance_between_endpoints * f; + let unit_vector_p0_to_p1 = + (p1 - p0) / distance_between_endpoints * f; - let unit_vector_midpoint_to_center = - Vector::from([-unit_vector_p0_to_p1.v, unit_vector_p0_to_p1.u]); + Vector::from([-unit_vector_p0_to_p1.v, unit_vector_p0_to_p1.u]) + }; let distance_center_to_midpoint = (radius.powi(2) - (distance_between_endpoints.powi(2) / 4.)) .sqrt(); From fc4ae56f2328d3bb2b5478f6fd9b6eee032a9d48 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 16 Feb 2023 13:01:56 +0100 Subject: [PATCH 20/21] Refactor --- crates/fj-math/src/arc.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/fj-math/src/arc.rs b/crates/fj-math/src/arc.rs index 2da7f6735..64dbac344 100644 --- a/crates/fj-math/src/arc.rs +++ b/crates/fj-math/src/arc.rs @@ -37,6 +37,7 @@ impl Arc { / (2. * (angle_rad.abs().into_f64() / 2.).sin()); let center = { + let midpoint = (p0.coords + p1.coords) / 2.; let unit_vector_midpoint_to_center = { let clockwise_turn = angle_rad <= Scalar::ZERO; let f = match (clockwise_turn, more_than_half_turn) { @@ -54,7 +55,7 @@ impl Arc { .sqrt(); Point { - coords: (p0.coords + p1.coords) / 2. + coords: midpoint + unit_vector_midpoint_to_center * distance_center_to_midpoint, } From 3ca98bbfd49fd94dc3e5a529db37f8de1b477d16 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 16 Feb 2023 13:02:30 +0100 Subject: [PATCH 21/21] Refactor --- crates/fj-math/src/arc.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/crates/fj-math/src/arc.rs b/crates/fj-math/src/arc.rs index 64dbac344..5b4057244 100644 --- a/crates/fj-math/src/arc.rs +++ b/crates/fj-math/src/arc.rs @@ -37,7 +37,9 @@ impl Arc { / (2. * (angle_rad.abs().into_f64() / 2.).sin()); let center = { - let midpoint = (p0.coords + p1.coords) / 2.; + let midpoint = Point { + coords: (p0.coords + p1.coords) / 2., + }; let unit_vector_midpoint_to_center = { let clockwise_turn = angle_rad <= Scalar::ZERO; let f = match (clockwise_turn, more_than_half_turn) { @@ -54,11 +56,8 @@ impl Arc { - (distance_between_endpoints.powi(2) / 4.)) .sqrt(); - Point { - coords: midpoint - + unit_vector_midpoint_to_center - * distance_center_to_midpoint, - } + midpoint + + unit_vector_midpoint_to_center * distance_center_to_midpoint }; let start_angle = {