From d8b4166ccc5a0568299309ac62c94fb8661914b4 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 22 Aug 2024 20:55:14 +0200 Subject: [PATCH 01/11] Simplify --- crates/fj-core/src/geometry/surface.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/crates/fj-core/src/geometry/surface.rs b/crates/fj-core/src/geometry/surface.rs index b6ea62f63..7918a407c 100644 --- a/crates/fj-core/src/geometry/surface.rs +++ b/crates/fj-core/src/geometry/surface.rs @@ -65,8 +65,7 @@ impl SurfaceGeom { ) -> (Triangle<3>, [Scalar; 3]) { let point_surface = point_surface.into(); - let Self { u, v } = self; - match u { + match &self.u { Path::Circle(circle) => { let params = PathApproxParams::for_circle(circle, tolerance); @@ -81,7 +80,7 @@ impl SurfaceGeom { circle.point_from_circle_coords([point_circle]) }) .map(|point_global| { - point_global + *v * point_surface.v + point_global + self.v * point_surface.v }); let triangle = Triangle::from(triangle_points_in_global_space); @@ -91,7 +90,7 @@ impl SurfaceGeom { } Path::Line(line) => { let a = line.direction(); - let b = *v; + let b = self.v; let point_global = line.origin() + a * point_surface.u + b * point_surface.v; From 1c387fd625f4f34a30726cd697d60aa17ba286d3 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 22 Aug 2024 20:57:15 +0200 Subject: [PATCH 02/11] Prepare for follow-on change --- crates/fj-core/src/geometry/surface.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/fj-core/src/geometry/surface.rs b/crates/fj-core/src/geometry/surface.rs index 7918a407c..d8d4cfa66 100644 --- a/crates/fj-core/src/geometry/surface.rs +++ b/crates/fj-core/src/geometry/surface.rs @@ -71,7 +71,7 @@ impl SurfaceGeom { let a = point_surface.u - params.increment(); let b = point_surface.u + params.increment(); - let c = a; // triangle is degenerate, as per function docs + let c = point_surface.u; // triangle is degenerate, as per docs let triangle_points_in_circle_space = [a, b, c]; let triangle_points_in_global_space = @@ -84,7 +84,7 @@ impl SurfaceGeom { }); let triangle = Triangle::from(triangle_points_in_global_space); - let barycentric_coords = [0.5, 0.5, 0.0].map(Into::into); + let barycentric_coords = [1. / 3.; 3].map(Into::into); (triangle, barycentric_coords) } From eef3ac3a4f0921f27ced2c98e73c2d6b527d2805 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 22 Aug 2024 20:59:59 +0200 Subject: [PATCH 03/11] Consolidate redundant code --- crates/fj-core/src/geometry/surface.rs | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/crates/fj-core/src/geometry/surface.rs b/crates/fj-core/src/geometry/surface.rs index d8d4cfa66..50a03ddc8 100644 --- a/crates/fj-core/src/geometry/surface.rs +++ b/crates/fj-core/src/geometry/surface.rs @@ -65,7 +65,7 @@ impl SurfaceGeom { ) -> (Triangle<3>, [Scalar; 3]) { let point_surface = point_surface.into(); - match &self.u { + let triangle = match &self.u { Path::Circle(circle) => { let params = PathApproxParams::for_circle(circle, tolerance); @@ -83,10 +83,7 @@ impl SurfaceGeom { point_global + self.v * point_surface.v }); - let triangle = Triangle::from(triangle_points_in_global_space); - let barycentric_coords = [1. / 3.; 3].map(Into::into); - - (triangle, barycentric_coords) + Triangle::from(triangle_points_in_global_space) } Path::Line(line) => { let a = line.direction(); @@ -99,12 +96,12 @@ impl SurfaceGeom { // arbitrarily large or small. Here we choose the smallest // possible size (it is collapsed to a point), as per the // documentation of this function. - let triangle = Triangle::from([point_global; 3]); - let barycentric_coords = [1. / 3.; 3].map(Into::into); - - (triangle, barycentric_coords) + Triangle::from([point_global; 3]) } - } + }; + + let barycentric_coords = [1. / 3.; 3].map(Into::into); + (triangle, barycentric_coords) } /// Convert a point in surface coordinates to model coordinates From 961b72ee5d121a962fbe57626474d92b5590f35e Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 22 Aug 2024 21:02:32 +0200 Subject: [PATCH 04/11] Inline redundant variable --- crates/fj-core/src/geometry/surface.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/fj-core/src/geometry/surface.rs b/crates/fj-core/src/geometry/surface.rs index 50a03ddc8..8a1a0b28d 100644 --- a/crates/fj-core/src/geometry/surface.rs +++ b/crates/fj-core/src/geometry/surface.rs @@ -86,11 +86,11 @@ impl SurfaceGeom { Triangle::from(triangle_points_in_global_space) } Path::Line(line) => { - let a = line.direction(); let b = self.v; - let point_global = - line.origin() + a * point_surface.u + b * point_surface.v; + let point_global = line.origin() + + line.direction() * point_surface.u + + b * point_surface.v; // We don't need to approximate a plane, so our triangle can be // arbitrarily large or small. Here we choose the smallest From 351a61cd7ce1a4fccaca0047c014b25d7a6f8bd6 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 22 Aug 2024 21:03:14 +0200 Subject: [PATCH 05/11] Inline redundant variable --- crates/fj-core/src/geometry/surface.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/crates/fj-core/src/geometry/surface.rs b/crates/fj-core/src/geometry/surface.rs index 8a1a0b28d..badd877f9 100644 --- a/crates/fj-core/src/geometry/surface.rs +++ b/crates/fj-core/src/geometry/surface.rs @@ -86,11 +86,9 @@ impl SurfaceGeom { Triangle::from(triangle_points_in_global_space) } Path::Line(line) => { - let b = self.v; - let point_global = line.origin() + line.direction() * point_surface.u - + b * point_surface.v; + + self.v * point_surface.v; // We don't need to approximate a plane, so our triangle can be // arbitrarily large or small. Here we choose the smallest From efd773916201f743ae7aa6d0e331a5599d78a638 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 22 Aug 2024 21:04:07 +0200 Subject: [PATCH 06/11] Update comments --- crates/fj-core/src/geometry/surface.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/crates/fj-core/src/geometry/surface.rs b/crates/fj-core/src/geometry/surface.rs index badd877f9..5f16b2ea3 100644 --- a/crates/fj-core/src/geometry/surface.rs +++ b/crates/fj-core/src/geometry/surface.rs @@ -86,14 +86,13 @@ impl SurfaceGeom { Triangle::from(triangle_points_in_global_space) } Path::Line(line) => { + // We don't need to approximate a line. So instead of creating a + // line segment to represent the line at this point, we just + // need this single point. let point_global = line.origin() + line.direction() * point_surface.u + self.v * point_surface.v; - // We don't need to approximate a plane, so our triangle can be - // arbitrarily large or small. Here we choose the smallest - // possible size (it is collapsed to a point), as per the - // documentation of this function. Triangle::from([point_global; 3]) } }; From 984ee93df9f4391be14b7d92c64ccf1988b55782 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 22 Aug 2024 21:04:33 +0200 Subject: [PATCH 07/11] Simplify variable name --- crates/fj-core/src/geometry/surface.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/fj-core/src/geometry/surface.rs b/crates/fj-core/src/geometry/surface.rs index 5f16b2ea3..b7e9d9a59 100644 --- a/crates/fj-core/src/geometry/surface.rs +++ b/crates/fj-core/src/geometry/surface.rs @@ -89,11 +89,11 @@ impl SurfaceGeom { // We don't need to approximate a line. So instead of creating a // line segment to represent the line at this point, we just // need this single point. - let point_global = line.origin() + let point = line.origin() + line.direction() * point_surface.u + self.v * point_surface.v; - Triangle::from([point_global; 3]) + Triangle::from([point; 3]) } }; From 7808b55583cd2b10aec428ce43733ba3c5d26500 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 22 Aug 2024 21:09:25 +0200 Subject: [PATCH 08/11] Prepare for follow-on change --- crates/fj-core/src/geometry/surface.rs | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/crates/fj-core/src/geometry/surface.rs b/crates/fj-core/src/geometry/surface.rs index b7e9d9a59..c0eef540b 100644 --- a/crates/fj-core/src/geometry/surface.rs +++ b/crates/fj-core/src/geometry/surface.rs @@ -71,19 +71,18 @@ impl SurfaceGeom { let a = point_surface.u - params.increment(); let b = point_surface.u + params.increment(); - let c = point_surface.u; // triangle is degenerate, as per docs - - let triangle_points_in_circle_space = [a, b, c]; - let triangle_points_in_global_space = - triangle_points_in_circle_space - .map(|point_circle| { - circle.point_from_circle_coords([point_circle]) - }) - .map(|point_global| { - point_global + self.v * point_surface.v - }); - - Triangle::from(triangle_points_in_global_space) + + let triangle_points_in_circle_space = [a, b]; + let [a, b] = triangle_points_in_circle_space + .map(|point_circle| { + circle.point_from_circle_coords([point_circle]) + }) + .map(|point_global| { + point_global + self.v * point_surface.v + }); + + let c = a + (b - a) / 2.; + Triangle::from([a, b, c]) } Path::Line(line) => { // We don't need to approximate a line. So instead of creating a From fcdb7518b8ea577499d03128c30386bc9b0e769b Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 22 Aug 2024 21:09:48 +0200 Subject: [PATCH 09/11] Inline redundant variable --- crates/fj-core/src/geometry/surface.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/crates/fj-core/src/geometry/surface.rs b/crates/fj-core/src/geometry/surface.rs index c0eef540b..d358dc9a8 100644 --- a/crates/fj-core/src/geometry/surface.rs +++ b/crates/fj-core/src/geometry/surface.rs @@ -72,8 +72,7 @@ impl SurfaceGeom { let a = point_surface.u - params.increment(); let b = point_surface.u + params.increment(); - let triangle_points_in_circle_space = [a, b]; - let [a, b] = triangle_points_in_circle_space + let [a, b] = [a, b] .map(|point_circle| { circle.point_from_circle_coords([point_circle]) }) From f47a1f8a96e647d1a4a036d09487bbbff5e2213a Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 22 Aug 2024 21:14:21 +0200 Subject: [PATCH 10/11] Consolidate redundant code --- crates/fj-core/src/geometry/surface.rs | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/crates/fj-core/src/geometry/surface.rs b/crates/fj-core/src/geometry/surface.rs index d358dc9a8..54c9a63b9 100644 --- a/crates/fj-core/src/geometry/surface.rs +++ b/crates/fj-core/src/geometry/surface.rs @@ -65,23 +65,18 @@ impl SurfaceGeom { ) -> (Triangle<3>, [Scalar; 3]) { let point_surface = point_surface.into(); - let triangle = match &self.u { + let [a, b] = match &self.u { Path::Circle(circle) => { let params = PathApproxParams::for_circle(circle, tolerance); let a = point_surface.u - params.increment(); let b = point_surface.u + params.increment(); - let [a, b] = [a, b] + [a, b] .map(|point_circle| { circle.point_from_circle_coords([point_circle]) }) - .map(|point_global| { - point_global + self.v * point_surface.v - }); - - let c = a + (b - a) / 2.; - Triangle::from([a, b, c]) + .map(|point_global| point_global + self.v * point_surface.v) } Path::Line(line) => { // We don't need to approximate a line. So instead of creating a @@ -91,10 +86,13 @@ impl SurfaceGeom { + line.direction() * point_surface.u + self.v * point_surface.v; - Triangle::from([point; 3]) + [point, point] } }; + let c = a + (b - a) / 2.; + let triangle = Triangle::from([a, b, c]); + let barycentric_coords = [1. / 3.; 3].map(Into::into); (triangle, barycentric_coords) } From 33b76e3d198452cee004ed53027235a953d0b5a3 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 22 Aug 2024 21:15:35 +0200 Subject: [PATCH 11/11] Inline redundant variables --- crates/fj-core/src/geometry/surface.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/crates/fj-core/src/geometry/surface.rs b/crates/fj-core/src/geometry/surface.rs index 54c9a63b9..faee73b86 100644 --- a/crates/fj-core/src/geometry/surface.rs +++ b/crates/fj-core/src/geometry/surface.rs @@ -69,14 +69,14 @@ impl SurfaceGeom { Path::Circle(circle) => { let params = PathApproxParams::for_circle(circle, tolerance); - let a = point_surface.u - params.increment(); - let b = point_surface.u + params.increment(); - - [a, b] - .map(|point_circle| { - circle.point_from_circle_coords([point_circle]) - }) - .map(|point_global| point_global + self.v * point_surface.v) + [ + point_surface.u - params.increment(), + point_surface.u + params.increment(), + ] + .map(|point_circle| { + circle.point_from_circle_coords([point_circle]) + }) + .map(|point_global| point_global + self.v * point_surface.v) } Path::Line(line) => { // We don't need to approximate a line. So instead of creating a