From 98230b5e312c78b2e042e0bc9d1a50c64d2067ed Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 28 Sep 2022 14:54:58 +0200 Subject: [PATCH 01/10] Implement `TransformObject` for `MaybePartial` --- .../fj-kernel/src/algorithms/transform/mod.rs | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/crates/fj-kernel/src/algorithms/transform/mod.rs b/crates/fj-kernel/src/algorithms/transform/mod.rs index c8ce24269..f1286000d 100644 --- a/crates/fj-kernel/src/algorithms/transform/mod.rs +++ b/crates/fj-kernel/src/algorithms/transform/mod.rs @@ -13,7 +13,10 @@ mod vertex; use fj_math::{Transform, Vector}; -use crate::stores::Stores; +use crate::{ + partial::{HasPartial, MaybePartial}, + stores::Stores, +}; /// Transform an object /// @@ -45,3 +48,18 @@ pub trait TransformObject: Sized { self.transform(&Transform::rotation(axis_angle), stores) } } + +impl TransformObject for MaybePartial +where + T: HasPartial + TransformObject, + T::Partial: TransformObject, +{ + fn transform(self, transform: &Transform, stores: &Stores) -> Self { + match self { + Self::Full(full) => Self::Full(full.transform(transform, stores)), + Self::Partial(partial) => { + Self::Partial(partial.transform(transform, stores)) + } + } + } +} From e73f3514792e967be6aa4e403716af0557812b65 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 28 Sep 2022 14:41:27 +0200 Subject: [PATCH 02/10] Impl `TransformObject` for `PartialGlobalCurve` --- crates/fj-kernel/src/algorithms/transform/curve.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/crates/fj-kernel/src/algorithms/transform/curve.rs b/crates/fj-kernel/src/algorithms/transform/curve.rs index dcba67312..c1b8afabf 100644 --- a/crates/fj-kernel/src/algorithms/transform/curve.rs +++ b/crates/fj-kernel/src/algorithms/transform/curve.rs @@ -2,6 +2,7 @@ use fj_math::Transform; use crate::{ objects::{Curve, GlobalCurve}, + partial::PartialGlobalCurve, stores::{Handle, Stores}, }; @@ -26,3 +27,10 @@ impl TransformObject for Handle { )) } } + +impl TransformObject for PartialGlobalCurve { + fn transform(self, transform: &Transform, stores: &Stores) -> Self { + let path = self.path.map(|path| path.transform(transform, stores)); + Self { path } + } +} From dfceecb3039cc0289e06ace1a74096cbf67ddeac Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 28 Sep 2022 14:52:46 +0200 Subject: [PATCH 03/10] Implement `TransformObject` for `PartialCurve` --- .../src/algorithms/transform/curve.rs | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/crates/fj-kernel/src/algorithms/transform/curve.rs b/crates/fj-kernel/src/algorithms/transform/curve.rs index c1b8afabf..34e936a76 100644 --- a/crates/fj-kernel/src/algorithms/transform/curve.rs +++ b/crates/fj-kernel/src/algorithms/transform/curve.rs @@ -2,7 +2,7 @@ use fj_math::Transform; use crate::{ objects::{Curve, GlobalCurve}, - partial::PartialGlobalCurve, + partial::{PartialCurve, PartialGlobalCurve}, stores::{Handle, Stores}, }; @@ -28,6 +28,25 @@ impl TransformObject for Handle { } } +impl TransformObject for PartialCurve { + fn transform(self, transform: &Transform, stores: &Stores) -> Self { + let surface = self + .surface + .map(|surface| surface.transform(transform, stores)); + let global_form = self + .global_form + .map(|global_form| global_form.transform(transform, stores)); + + // Don't need to transform `self.path`, as that's defined in surface + // coordinates, and thus transforming `surface` takes care of it. + Self { + surface, + path: self.path, + global_form, + } + } +} + impl TransformObject for PartialGlobalCurve { fn transform(self, transform: &Transform, stores: &Stores) -> Self { let path = self.path.map(|path| path.transform(transform, stores)); From 7823bcb3e03e89b211687e70f09dd374c637269e Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 28 Sep 2022 14:57:17 +0200 Subject: [PATCH 04/10] Impl `TransformObject` for `PartialGlobalVertex` --- crates/fj-kernel/src/algorithms/transform/vertex.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/crates/fj-kernel/src/algorithms/transform/vertex.rs b/crates/fj-kernel/src/algorithms/transform/vertex.rs index 89d2507b6..07a9b47e4 100644 --- a/crates/fj-kernel/src/algorithms/transform/vertex.rs +++ b/crates/fj-kernel/src/algorithms/transform/vertex.rs @@ -2,6 +2,7 @@ use fj_math::Transform; use crate::{ objects::{GlobalVertex, SurfaceVertex, Vertex}, + partial::PartialGlobalVertex, stores::Stores, }; @@ -36,3 +37,13 @@ impl TransformObject for GlobalVertex { Self::from_position(position) } } + +impl TransformObject for PartialGlobalVertex { + fn transform(self, transform: &Transform, _: &Stores) -> Self { + let position = self + .position + .map(|position| transform.transform_point(&position)); + + Self { position } + } +} From b153bd74460b5348ffd0a89d324b50888b466f03 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 28 Sep 2022 15:01:05 +0200 Subject: [PATCH 05/10] Impl `TransformObject` for `PartialSurfaceVertex` --- .../src/algorithms/transform/vertex.rs | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/crates/fj-kernel/src/algorithms/transform/vertex.rs b/crates/fj-kernel/src/algorithms/transform/vertex.rs index 07a9b47e4..5fda02a3e 100644 --- a/crates/fj-kernel/src/algorithms/transform/vertex.rs +++ b/crates/fj-kernel/src/algorithms/transform/vertex.rs @@ -2,7 +2,7 @@ use fj_math::Transform; use crate::{ objects::{GlobalVertex, SurfaceVertex, Vertex}, - partial::PartialGlobalVertex, + partial::{PartialGlobalVertex, PartialSurfaceVertex}, stores::Stores, }; @@ -38,6 +38,25 @@ impl TransformObject for GlobalVertex { } } +impl TransformObject for PartialSurfaceVertex { + fn transform(self, transform: &Transform, stores: &Stores) -> Self { + let surface = self + .surface + .map(|surface| surface.transform(transform, stores)); + let global_form = self + .global_form + .map(|global_form| global_form.transform(transform, stores)); + + // Don't need to transform `self.position`, as that is in surface + // coordinates and thus transforming the surface takes care of it. + Self { + position: self.position, + surface, + global_form, + } + } +} + impl TransformObject for PartialGlobalVertex { fn transform(self, transform: &Transform, _: &Stores) -> Self { let position = self From edfae11acf76fa43d5e5b1c00d929adb62bf677e Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 28 Sep 2022 15:03:10 +0200 Subject: [PATCH 06/10] Implement `TransformObject` for `PartialVertex` --- .../src/algorithms/transform/vertex.rs | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/crates/fj-kernel/src/algorithms/transform/vertex.rs b/crates/fj-kernel/src/algorithms/transform/vertex.rs index 5fda02a3e..efc019881 100644 --- a/crates/fj-kernel/src/algorithms/transform/vertex.rs +++ b/crates/fj-kernel/src/algorithms/transform/vertex.rs @@ -2,7 +2,7 @@ use fj_math::Transform; use crate::{ objects::{GlobalVertex, SurfaceVertex, Vertex}, - partial::{PartialGlobalVertex, PartialSurfaceVertex}, + partial::{PartialGlobalVertex, PartialSurfaceVertex, PartialVertex}, stores::Stores, }; @@ -38,6 +38,27 @@ impl TransformObject for GlobalVertex { } } +impl TransformObject for PartialVertex { + fn transform(self, transform: &Transform, stores: &Stores) -> Self { + let curve = self.curve.map(|curve| curve.transform(transform, stores)); + let surface_form = self + .surface_form + .map(|surface_form| surface_form.transform(transform, stores)); + let global_form = self + .global_form + .map(|global_form| global_form.transform(transform, stores)); + + // Don't need to transform `self.position`, as that is in curve + // coordinates and thus transforming the curve takes care of it. + Self { + position: self.position, + curve, + surface_form, + global_form, + } + } +} + impl TransformObject for PartialSurfaceVertex { fn transform(self, transform: &Transform, stores: &Stores) -> Self { let surface = self From 15f95531f2a43961e05431e8b4af5d532f7103c5 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 28 Sep 2022 15:03:48 +0200 Subject: [PATCH 07/10] Don't duplicate curve when transforming half-edge --- crates/fj-kernel/src/algorithms/transform/edge.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/crates/fj-kernel/src/algorithms/transform/edge.rs b/crates/fj-kernel/src/algorithms/transform/edge.rs index a900f0791..2727da3d1 100644 --- a/crates/fj-kernel/src/algorithms/transform/edge.rs +++ b/crates/fj-kernel/src/algorithms/transform/edge.rs @@ -2,6 +2,7 @@ use fj_math::Transform; use crate::{ objects::{GlobalEdge, HalfEdge}, + partial::HasPartial, stores::Stores, }; @@ -13,7 +14,13 @@ impl TransformObject for HalfEdge { let vertices = self .vertices() .clone() - .map(|vertex| vertex.transform(transform, stores)); + .map(|vertex| { + vertex + .to_partial() + .transform(transform, stores) + .with_curve(curve.clone()) + .build(stores) + }); let global_form = self.global_form().clone().transform(transform, stores); From 6aa2270138d6edaee10026fd80d15b012eaa8b13 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 28 Sep 2022 15:04:04 +0200 Subject: [PATCH 08/10] Add comment --- crates/fj-kernel/src/algorithms/transform/edge.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/crates/fj-kernel/src/algorithms/transform/edge.rs b/crates/fj-kernel/src/algorithms/transform/edge.rs index 2727da3d1..882338c8c 100644 --- a/crates/fj-kernel/src/algorithms/transform/edge.rs +++ b/crates/fj-kernel/src/algorithms/transform/edge.rs @@ -13,6 +13,8 @@ impl TransformObject for HalfEdge { let curve = self.curve().clone().transform(transform, stores); let vertices = self .vertices() + // The `clone` can be replaced with `each_ref`, once that is stable: + // https://doc.rust-lang.org/std/primitive.array.html#method.each_ref .clone() .map(|vertex| { vertex From 04ea5aefd99c98b268881015b30f7ee5cff2bbbe Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 28 Sep 2022 15:20:03 +0200 Subject: [PATCH 09/10] Impl `TransformObject` for `PartialGlobalEdge` --- crates/fj-kernel/src/algorithms/transform/edge.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/crates/fj-kernel/src/algorithms/transform/edge.rs b/crates/fj-kernel/src/algorithms/transform/edge.rs index 882338c8c..844850c9a 100644 --- a/crates/fj-kernel/src/algorithms/transform/edge.rs +++ b/crates/fj-kernel/src/algorithms/transform/edge.rs @@ -2,7 +2,7 @@ use fj_math::Transform; use crate::{ objects::{GlobalEdge, HalfEdge}, - partial::HasPartial, + partial::{HasPartial, PartialGlobalEdge}, stores::Stores, }; @@ -40,3 +40,14 @@ impl TransformObject for GlobalEdge { Self::new(curve, vertices) } } + +impl TransformObject for PartialGlobalEdge { + fn transform(self, transform: &Transform, stores: &Stores) -> Self { + let curve = self.curve.map(|curve| curve.transform(transform, stores)); + let vertices = self.vertices.map(|vertices| { + vertices.map(|vertex| vertex.transform(transform, stores)) + }); + + Self { curve, vertices } + } +} From 612be6733eea96f693616c3d76a5055b14a99e80 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 28 Sep 2022 15:22:25 +0200 Subject: [PATCH 10/10] Don't duplicate global curve in transform code --- crates/fj-kernel/src/algorithms/transform/edge.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/transform/edge.rs b/crates/fj-kernel/src/algorithms/transform/edge.rs index 844850c9a..bb3f4b1f8 100644 --- a/crates/fj-kernel/src/algorithms/transform/edge.rs +++ b/crates/fj-kernel/src/algorithms/transform/edge.rs @@ -23,8 +23,12 @@ impl TransformObject for HalfEdge { .with_curve(curve.clone()) .build(stores) }); - let global_form = - self.global_form().clone().transform(transform, stores); + let global_form = self + .global_form() + .to_partial() + .transform(transform, stores) + .with_curve(curve.global_form().clone()) + .build(stores); Self::new(curve, vertices, global_form) }