From a850d3e1d0d52b6800f8cf3239d06f454c76dc2d Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 20 Apr 2023 09:16:49 +0200 Subject: [PATCH 01/11] Remove unnecessary whitespace from error messages --- crates/fj-kernel/src/validate/solid.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/fj-kernel/src/validate/solid.rs b/crates/fj-kernel/src/validate/solid.rs index 3f0e32695..b3c904e1a 100644 --- a/crates/fj-kernel/src/validate/solid.rs +++ b/crates/fj-kernel/src/validate/solid.rs @@ -25,8 +25,8 @@ pub enum SolidValidationError { #[error( "Solid contains Vertices that are coincident but not identical\n Vertex 1: {:#?} {:#?} - Vertex 2: {:#?} {:#?} - ", .0[0].0, .0[0].1,.0[1].0,.0[1].1 + Vertex 2: {:#?} {:#?}", + .0[0].0, .0[0].1,.0[1].0,.0[1].1 )] DistinctVerticesCoincide([(Handle, Point<3>); 2]), @@ -34,8 +34,8 @@ pub enum SolidValidationError { #[error( "Solid contains Vertices that are identical but do not coincide\n Vertex 1: {:#?} {:#?} - Vertex 2: {:#?} {:#?} - ", .0[0].0, .0[0].1,.0[1].0,.0[1].1 + Vertex 2: {:#?} {:#?}", + .0[0].0, .0[0].1,.0[1].0,.0[1].1 )] IdenticalVerticesNotCoincident([(Handle, Point<3>); 2]), } From 3334dd7cecbe8344b65b8fffcb876e136ec04f92 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 20 Apr 2023 09:18:44 +0200 Subject: [PATCH 02/11] Improve formatting in error messages --- crates/fj-kernel/src/validate/solid.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/fj-kernel/src/validate/solid.rs b/crates/fj-kernel/src/validate/solid.rs index b3c904e1a..c5d5bb4ac 100644 --- a/crates/fj-kernel/src/validate/solid.rs +++ b/crates/fj-kernel/src/validate/solid.rs @@ -24,8 +24,8 @@ pub enum SolidValidationError { /// [`Solid`] contains vertices that are coincident, but not identical #[error( "Solid contains Vertices that are coincident but not identical\n - Vertex 1: {:#?} {:#?} - Vertex 2: {:#?} {:#?}", + Vertex 1: {:#?} ({:?}) + Vertex 2: {:#?} ({:?})", .0[0].0, .0[0].1,.0[1].0,.0[1].1 )] DistinctVerticesCoincide([(Handle, Point<3>); 2]), @@ -33,8 +33,8 @@ pub enum SolidValidationError { /// [`Solid`] contains vertices that are identical, but do not coincide #[error( "Solid contains Vertices that are identical but do not coincide\n - Vertex 1: {:#?} {:#?} - Vertex 2: {:#?} {:#?}", + Vertex 1: {:#?} ({:?}) + Vertex 2: {:#?} ({:?})", .0[0].0, .0[0].1,.0[1].0,.0[1].1 )] IdenticalVerticesNotCoincident([(Handle, Point<3>); 2]), From b383e12227a3ce1189e91be9a843f4e4d149dcb2 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 20 Apr 2023 09:22:51 +0200 Subject: [PATCH 03/11] Improve readability of `DistinctVerticesCoincide` --- crates/fj-kernel/src/validate/solid.rs | 29 +++++++++++++++++++------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/crates/fj-kernel/src/validate/solid.rs b/crates/fj-kernel/src/validate/solid.rs index c5d5bb4ac..3511d0ff2 100644 --- a/crates/fj-kernel/src/validate/solid.rs +++ b/crates/fj-kernel/src/validate/solid.rs @@ -24,11 +24,22 @@ pub enum SolidValidationError { /// [`Solid`] contains vertices that are coincident, but not identical #[error( "Solid contains Vertices that are coincident but not identical\n - Vertex 1: {:#?} ({:?}) - Vertex 2: {:#?} ({:?})", - .0[0].0, .0[0].1,.0[1].0,.0[1].1 + Vertex 1: {vertex_a:#?} ({position_a:?}) + Vertex 2: {vertex_b:#?} ({position_b:?})" )] - DistinctVerticesCoincide([(Handle, Point<3>); 2]), + DistinctVerticesCoincide { + /// The first vertex + vertex_a: Handle, + + /// The second vertex + vertex_b: Handle, + + /// Position of first vertex + position_a: Point<3>, + + /// Position of second vertex + position_b: Point<3>, + }, /// [`Solid`] contains vertices that are identical, but do not coincide #[error( @@ -84,10 +95,12 @@ impl SolidValidationError { if a.0.distance_to(&b.0) < config.distinct_min_distance { errors.push( - Self::DistinctVerticesCoincide([ - (a.1.clone(), a.0), - (b.1.clone(), b.0), - ]) + Self::DistinctVerticesCoincide { + vertex_a: a.1.clone(), + vertex_b: b.1.clone(), + position_a: a.0, + position_b: b.0, + } .into(), ) } From c4015709a607fd9c9bcd9d1569a51e88a78b6e32 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 20 Apr 2023 09:23:50 +0200 Subject: [PATCH 04/11] Clean up `IdenticalVerticesNotCoincident` Refactor it to make it more readable. --- crates/fj-kernel/src/validate/solid.rs | 29 +++++++++++++++++++------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/crates/fj-kernel/src/validate/solid.rs b/crates/fj-kernel/src/validate/solid.rs index 3511d0ff2..0ec9c2753 100644 --- a/crates/fj-kernel/src/validate/solid.rs +++ b/crates/fj-kernel/src/validate/solid.rs @@ -44,11 +44,22 @@ pub enum SolidValidationError { /// [`Solid`] contains vertices that are identical, but do not coincide #[error( "Solid contains Vertices that are identical but do not coincide\n - Vertex 1: {:#?} ({:?}) - Vertex 2: {:#?} ({:?})", - .0[0].0, .0[0].1,.0[1].0,.0[1].1 + Vertex 1: {vertex_a:#?} ({position_a:?}) + Vertex 2: {vertex_b:#?} ({position_b:?})" )] - IdenticalVerticesNotCoincident([(Handle, Point<3>); 2]), + IdenticalVerticesNotCoincident { + /// The first vertex + vertex_a: Handle, + + /// The second vertex + vertex_b: Handle, + + /// Position of first vertex + position_a: Point<3>, + + /// Position of second vertex + position_b: Point<3>, + }, } impl SolidValidationError { @@ -83,10 +94,12 @@ impl SolidValidationError { if a.0.distance_to(&b.0) > config.identical_max_distance { errors.push( - Self::IdenticalVerticesNotCoincident([ - (a.1.clone(), a.0), - (b.1.clone(), b.0), - ]) + Self::IdenticalVerticesNotCoincident { + vertex_a: a.1.clone(), + vertex_b: b.1.clone(), + position_a: a.0, + position_b: b.0, + } .into(), ) } From f260b741ea3b0b208b769dcd5cb352a4908a9e3a Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 20 Apr 2023 09:25:24 +0200 Subject: [PATCH 05/11] Destructure tuple to improve readability --- crates/fj-kernel/src/validate/solid.rs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/crates/fj-kernel/src/validate/solid.rs b/crates/fj-kernel/src/validate/solid.rs index 0ec9c2753..2d4e7fa5e 100644 --- a/crates/fj-kernel/src/validate/solid.rs +++ b/crates/fj-kernel/src/validate/solid.rs @@ -87,17 +87,18 @@ impl SolidValidationError { // This is O(N^2) which isn't great, but we can't use a HashMap since we // need to deal with float inaccuracies. Maybe we could use some smarter // data-structure like an octree. - for a in &vertices { + for (position_a, vertex_a) in &vertices { for b in &vertices { - match a.1.id() == b.1.id() { + match vertex_a.id() == b.1.id() { true => { - if a.0.distance_to(&b.0) > config.identical_max_distance + if position_a.distance_to(&b.0) + > config.identical_max_distance { errors.push( Self::IdenticalVerticesNotCoincident { - vertex_a: a.1.clone(), + vertex_a: vertex_a.clone(), vertex_b: b.1.clone(), - position_a: a.0, + position_a: *position_a, position_b: b.0, } .into(), @@ -105,13 +106,14 @@ impl SolidValidationError { } } false => { - if a.0.distance_to(&b.0) < config.distinct_min_distance + if position_a.distance_to(&b.0) + < config.distinct_min_distance { errors.push( Self::DistinctVerticesCoincide { - vertex_a: a.1.clone(), + vertex_a: vertex_a.clone(), vertex_b: b.1.clone(), - position_a: a.0, + position_a: *position_a, position_b: b.0, } .into(), From 82aafc769307fd17bcd6ff6a952151665b0e006f Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 20 Apr 2023 09:26:35 +0200 Subject: [PATCH 06/11] Destructure tuple to improve readability --- crates/fj-kernel/src/validate/solid.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/crates/fj-kernel/src/validate/solid.rs b/crates/fj-kernel/src/validate/solid.rs index 2d4e7fa5e..2e804b26e 100644 --- a/crates/fj-kernel/src/validate/solid.rs +++ b/crates/fj-kernel/src/validate/solid.rs @@ -88,33 +88,33 @@ impl SolidValidationError { // need to deal with float inaccuracies. Maybe we could use some smarter // data-structure like an octree. for (position_a, vertex_a) in &vertices { - for b in &vertices { - match vertex_a.id() == b.1.id() { + for (position_b, vertex_b) in &vertices { + match vertex_a.id() == vertex_b.id() { true => { - if position_a.distance_to(&b.0) + if position_a.distance_to(position_b) > config.identical_max_distance { errors.push( Self::IdenticalVerticesNotCoincident { vertex_a: vertex_a.clone(), - vertex_b: b.1.clone(), + vertex_b: vertex_b.clone(), position_a: *position_a, - position_b: b.0, + position_b: *position_b, } .into(), ) } } false => { - if position_a.distance_to(&b.0) + if position_a.distance_to(position_b) < config.distinct_min_distance { errors.push( Self::DistinctVerticesCoincide { vertex_a: vertex_a.clone(), - vertex_b: b.1.clone(), + vertex_b: vertex_b.clone(), position_a: *position_a, - position_b: b.0, + position_b: *position_b, } .into(), ) From 54eaee608d4f15d06037dd29e6d1133467f2c379 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 20 Apr 2023 09:28:46 +0200 Subject: [PATCH 07/11] Extract variable to improve readability --- crates/fj-kernel/src/validate/solid.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/crates/fj-kernel/src/validate/solid.rs b/crates/fj-kernel/src/validate/solid.rs index 2e804b26e..779197833 100644 --- a/crates/fj-kernel/src/validate/solid.rs +++ b/crates/fj-kernel/src/validate/solid.rs @@ -89,7 +89,9 @@ impl SolidValidationError { // data-structure like an octree. for (position_a, vertex_a) in &vertices { for (position_b, vertex_b) in &vertices { - match vertex_a.id() == vertex_b.id() { + let vertices_are_identical = vertex_a.id() == vertex_b.id(); + + match vertices_are_identical { true => { if position_a.distance_to(position_b) > config.identical_max_distance From e4a6800a6b7f1c0c1c3899ef6b800ed813d6ee2a Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 20 Apr 2023 09:28:46 +0200 Subject: [PATCH 08/11] Extract variable to improve readability --- crates/fj-kernel/src/validate/solid.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/crates/fj-kernel/src/validate/solid.rs b/crates/fj-kernel/src/validate/solid.rs index 779197833..c5374acc5 100644 --- a/crates/fj-kernel/src/validate/solid.rs +++ b/crates/fj-kernel/src/validate/solid.rs @@ -90,12 +90,13 @@ impl SolidValidationError { for (position_a, vertex_a) in &vertices { for (position_b, vertex_b) in &vertices { let vertices_are_identical = vertex_a.id() == vertex_b.id(); + let too_far_to_be_identical = position_a + .distance_to(position_b) + > config.identical_max_distance; match vertices_are_identical { true => { - if position_a.distance_to(position_b) - > config.identical_max_distance - { + if too_far_to_be_identical { errors.push( Self::IdenticalVerticesNotCoincident { vertex_a: vertex_a.clone(), From 2b9283545abb321f0ef3e391f8b4e43fab3be466 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 20 Apr 2023 09:28:46 +0200 Subject: [PATCH 09/11] Extract variable to improve readability --- crates/fj-kernel/src/validate/solid.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/crates/fj-kernel/src/validate/solid.rs b/crates/fj-kernel/src/validate/solid.rs index c5374acc5..1eb8b25d9 100644 --- a/crates/fj-kernel/src/validate/solid.rs +++ b/crates/fj-kernel/src/validate/solid.rs @@ -93,6 +93,9 @@ impl SolidValidationError { let too_far_to_be_identical = position_a .distance_to(position_b) > config.identical_max_distance; + let too_close_to_be_distinct = position_a + .distance_to(position_b) + < config.distinct_min_distance; match vertices_are_identical { true => { @@ -109,9 +112,7 @@ impl SolidValidationError { } } false => { - if position_a.distance_to(position_b) - < config.distinct_min_distance - { + if too_close_to_be_distinct { errors.push( Self::DistinctVerticesCoincide { vertex_a: vertex_a.clone(), From 3d8da18aeb8d152f165fc0156127e28cce0567d3 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 20 Apr 2023 09:28:08 +0200 Subject: [PATCH 10/11] Refactor code to make it more readable --- crates/fj-kernel/src/validate/solid.rs | 45 ++++++++++++-------------- 1 file changed, 20 insertions(+), 25 deletions(-) diff --git a/crates/fj-kernel/src/validate/solid.rs b/crates/fj-kernel/src/validate/solid.rs index 1eb8b25d9..bd5d5a307 100644 --- a/crates/fj-kernel/src/validate/solid.rs +++ b/crates/fj-kernel/src/validate/solid.rs @@ -97,33 +97,28 @@ impl SolidValidationError { .distance_to(position_b) < config.distinct_min_distance; - match vertices_are_identical { - true => { - if too_far_to_be_identical { - errors.push( - Self::IdenticalVerticesNotCoincident { - vertex_a: vertex_a.clone(), - vertex_b: vertex_b.clone(), - position_a: *position_a, - position_b: *position_b, - } - .into(), - ) + if vertices_are_identical && too_far_to_be_identical { + errors.push( + Self::IdenticalVerticesNotCoincident { + vertex_a: vertex_a.clone(), + vertex_b: vertex_b.clone(), + position_a: *position_a, + position_b: *position_b, } - } - false => { - if too_close_to_be_distinct { - errors.push( - Self::DistinctVerticesCoincide { - vertex_a: vertex_a.clone(), - vertex_b: vertex_b.clone(), - position_a: *position_a, - position_b: *position_b, - } - .into(), - ) + .into(), + ) + } + + if !vertices_are_identical && too_close_to_be_distinct { + errors.push( + Self::DistinctVerticesCoincide { + vertex_a: vertex_a.clone(), + vertex_b: vertex_b.clone(), + position_a: *position_a, + position_b: *position_b, } - } + .into(), + ) } } } From 8947cc946f89c067648d1e5a0ffdb6aafa92329a Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 20 Apr 2023 09:46:23 +0200 Subject: [PATCH 11/11] Extract variable to improve readability --- crates/fj-kernel/src/validate/solid.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/crates/fj-kernel/src/validate/solid.rs b/crates/fj-kernel/src/validate/solid.rs index bd5d5a307..9dff3630f 100644 --- a/crates/fj-kernel/src/validate/solid.rs +++ b/crates/fj-kernel/src/validate/solid.rs @@ -90,6 +90,8 @@ impl SolidValidationError { for (position_a, vertex_a) in &vertices { for (position_b, vertex_b) in &vertices { let vertices_are_identical = vertex_a.id() == vertex_b.id(); + let vertices_are_not_identical = !vertices_are_identical; + let too_far_to_be_identical = position_a .distance_to(position_b) > config.identical_max_distance; @@ -109,7 +111,7 @@ impl SolidValidationError { ) } - if !vertices_are_identical && too_close_to_be_distinct { + if vertices_are_not_identical && too_close_to_be_distinct { errors.push( Self::DistinctVerticesCoincide { vertex_a: vertex_a.clone(),