From 43cc14cff2fd70f1eda39af122bd43515323f9df Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 22 Sep 2022 12:39:24 +0200 Subject: [PATCH 01/26] Make curve in `VertexBuilder` optional --- .../fj-kernel/src/algorithms/sweep/vertex.rs | 2 +- crates/fj-kernel/src/builder/vertex.rs | 19 ++++++++++++------- crates/fj-kernel/src/objects/vertex.rs | 7 ++----- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/sweep/vertex.rs b/crates/fj-kernel/src/algorithms/sweep/vertex.rs index 2aad1162d..e4fa1b597 100644 --- a/crates/fj-kernel/src/algorithms/sweep/vertex.rs +++ b/crates/fj-kernel/src/algorithms/sweep/vertex.rs @@ -161,7 +161,7 @@ mod tests { let surface = Surface::xz_plane(); let curve = Curve::builder(&stores, surface).build_u_axis(); - let vertex = Vertex::builder([0.], curve).build(); + let vertex = Vertex::builder([0.]).with_curve(curve).build(); let half_edge = (vertex, surface).sweep([0., 0., 1.], &stores); diff --git a/crates/fj-kernel/src/builder/vertex.rs b/crates/fj-kernel/src/builder/vertex.rs index 50587c19c..ba51ae774 100644 --- a/crates/fj-kernel/src/builder/vertex.rs +++ b/crates/fj-kernel/src/builder/vertex.rs @@ -10,7 +10,7 @@ pub struct VertexBuilder { pub position: Point<1>, /// The curve that the [`Vertex`] is defined in - pub curve: Curve, + pub curve: Option, /// The surface form of the [`Vertex`] /// @@ -26,6 +26,12 @@ pub struct VertexBuilder { } impl VertexBuilder { + /// Build the [`Vertex`] with the provided curve + pub fn with_curve(mut self, curve: Curve) -> Self { + self.curve = Some(curve); + self + } + /// Build the [`Vertex`] with the provided surface form pub fn with_surface_form(mut self, surface_form: SurfaceVertex) -> Self { self.surface_form = Some(surface_form); @@ -40,13 +46,12 @@ impl VertexBuilder { /// Finish building the [`Vertex`] pub fn build(self) -> Vertex { + let curve = self.curve.expect("Can't build `Vertex` without `Curve`"); + let surface_form = self.surface_form.unwrap_or_else(|| { SurfaceVertexBuilder { - position: self - .curve - .path() - .point_from_path_coords(self.position), - surface: *self.curve.surface(), + position: curve.path().point_from_path_coords(self.position), + surface: *curve.surface(), global_form: self.global_form, } .build() @@ -54,7 +59,7 @@ impl VertexBuilder { let global_form = *surface_form.global_form(); - Vertex::new(self.position, self.curve, surface_form, global_form) + Vertex::new(self.position, curve, surface_form, global_form) } } diff --git a/crates/fj-kernel/src/objects/vertex.rs b/crates/fj-kernel/src/objects/vertex.rs index 65622cfee..feb26a437 100644 --- a/crates/fj-kernel/src/objects/vertex.rs +++ b/crates/fj-kernel/src/objects/vertex.rs @@ -22,13 +22,10 @@ pub struct Vertex { impl Vertex { /// Build a `Vertex` using [`VertexBuilder`] - pub fn builder( - position: impl Into>, - curve: Curve, - ) -> VertexBuilder { + pub fn builder(position: impl Into>) -> VertexBuilder { VertexBuilder { position: position.into(), - curve, + curve: None, surface_form: None, global_form: None, } From f56bef4b2af79d804c7cd5a749f043a916d5cca9 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 22 Sep 2022 12:42:01 +0200 Subject: [PATCH 02/26] Make position in `VertexBuilder` optional --- crates/fj-kernel/src/algorithms/sweep/vertex.rs | 5 ++++- crates/fj-kernel/src/builder/vertex.rs | 15 ++++++++++++--- crates/fj-kernel/src/objects/vertex.rs | 4 ++-- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/sweep/vertex.rs b/crates/fj-kernel/src/algorithms/sweep/vertex.rs index e4fa1b597..51f53f29b 100644 --- a/crates/fj-kernel/src/algorithms/sweep/vertex.rs +++ b/crates/fj-kernel/src/algorithms/sweep/vertex.rs @@ -161,7 +161,10 @@ mod tests { let surface = Surface::xz_plane(); let curve = Curve::builder(&stores, surface).build_u_axis(); - let vertex = Vertex::builder([0.]).with_curve(curve).build(); + let vertex = Vertex::builder() + .with_position([0.]) + .with_curve(curve) + .build(); let half_edge = (vertex, surface).sweep([0., 0., 1.], &stores); diff --git a/crates/fj-kernel/src/builder/vertex.rs b/crates/fj-kernel/src/builder/vertex.rs index ba51ae774..60d43fda4 100644 --- a/crates/fj-kernel/src/builder/vertex.rs +++ b/crates/fj-kernel/src/builder/vertex.rs @@ -7,7 +7,7 @@ use crate::objects::{Curve, GlobalVertex, Surface, SurfaceVertex, Vertex}; /// Also see [`Vertex::builder`]. pub struct VertexBuilder { /// The position of the [`Vertex`] on the [`Curve`] - pub position: Point<1>, + pub position: Option>, /// The curve that the [`Vertex`] is defined in pub curve: Option, @@ -26,6 +26,12 @@ pub struct VertexBuilder { } impl VertexBuilder { + /// Build the [`Vertex`] with the provided position + pub fn with_position(mut self, position: impl Into>) -> Self { + self.position = Some(position.into()); + self + } + /// Build the [`Vertex`] with the provided curve pub fn with_curve(mut self, curve: Curve) -> Self { self.curve = Some(curve); @@ -46,11 +52,14 @@ impl VertexBuilder { /// Finish building the [`Vertex`] pub fn build(self) -> Vertex { + let position = self + .position + .expect("Cant' build `Vertex` without position"); let curve = self.curve.expect("Can't build `Vertex` without `Curve`"); let surface_form = self.surface_form.unwrap_or_else(|| { SurfaceVertexBuilder { - position: curve.path().point_from_path_coords(self.position), + position: curve.path().point_from_path_coords(position), surface: *curve.surface(), global_form: self.global_form, } @@ -59,7 +68,7 @@ impl VertexBuilder { let global_form = *surface_form.global_form(); - Vertex::new(self.position, curve, surface_form, global_form) + Vertex::new(position, curve, surface_form, global_form) } } diff --git a/crates/fj-kernel/src/objects/vertex.rs b/crates/fj-kernel/src/objects/vertex.rs index feb26a437..9feed0c46 100644 --- a/crates/fj-kernel/src/objects/vertex.rs +++ b/crates/fj-kernel/src/objects/vertex.rs @@ -22,9 +22,9 @@ pub struct Vertex { impl Vertex { /// Build a `Vertex` using [`VertexBuilder`] - pub fn builder(position: impl Into>) -> VertexBuilder { + pub fn builder() -> VertexBuilder { VertexBuilder { - position: position.into(), + position: None, curve: None, surface_form: None, global_form: None, From b192af9ab5a213a92dae1606108643ea63d76cfc Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 22 Sep 2022 12:44:00 +0200 Subject: [PATCH 03/26] Derive `Default` for `VertexBuilder` --- crates/fj-kernel/src/builder/vertex.rs | 1 + crates/fj-kernel/src/objects/vertex.rs | 7 +------ 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/crates/fj-kernel/src/builder/vertex.rs b/crates/fj-kernel/src/builder/vertex.rs index 60d43fda4..8659fb3b8 100644 --- a/crates/fj-kernel/src/builder/vertex.rs +++ b/crates/fj-kernel/src/builder/vertex.rs @@ -5,6 +5,7 @@ use crate::objects::{Curve, GlobalVertex, Surface, SurfaceVertex, Vertex}; /// API for building a [`Vertex`] /// /// Also see [`Vertex::builder`]. +#[derive(Default)] pub struct VertexBuilder { /// The position of the [`Vertex`] on the [`Curve`] pub position: Option>, diff --git a/crates/fj-kernel/src/objects/vertex.rs b/crates/fj-kernel/src/objects/vertex.rs index 9feed0c46..022fe2c49 100644 --- a/crates/fj-kernel/src/objects/vertex.rs +++ b/crates/fj-kernel/src/objects/vertex.rs @@ -23,12 +23,7 @@ pub struct Vertex { impl Vertex { /// Build a `Vertex` using [`VertexBuilder`] pub fn builder() -> VertexBuilder { - VertexBuilder { - position: None, - curve: None, - surface_form: None, - global_form: None, - } + VertexBuilder::default() } /// Construct an instance of `Vertex` From 56f44d78e1e2dced11cfebd296bab6826adc2c6c Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 22 Sep 2022 12:45:28 +0200 Subject: [PATCH 04/26] Rename `VertexBuilder` to `PartialVertex` The new name describes what it is, while the old name ascribes a use case. Since I intend to use `PartialVertex` (and its other "builder" siblings) for other use cases too, the new name is more appropriate, I think. --- crates/fj-kernel/src/builder/mod.rs | 2 +- crates/fj-kernel/src/builder/vertex.rs | 4 ++-- crates/fj-kernel/src/objects/vertex.rs | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/crates/fj-kernel/src/builder/mod.rs b/crates/fj-kernel/src/builder/mod.rs index 4f8aaccef..e003cb264 100644 --- a/crates/fj-kernel/src/builder/mod.rs +++ b/crates/fj-kernel/src/builder/mod.rs @@ -17,5 +17,5 @@ pub use self::{ shell::ShellBuilder, sketch::SketchBuilder, solid::SolidBuilder, - vertex::{GlobalVertexBuilder, SurfaceVertexBuilder, VertexBuilder}, + vertex::{GlobalVertexBuilder, PartialVertex, SurfaceVertexBuilder}, }; diff --git a/crates/fj-kernel/src/builder/vertex.rs b/crates/fj-kernel/src/builder/vertex.rs index 8659fb3b8..191f58e93 100644 --- a/crates/fj-kernel/src/builder/vertex.rs +++ b/crates/fj-kernel/src/builder/vertex.rs @@ -6,7 +6,7 @@ use crate::objects::{Curve, GlobalVertex, Surface, SurfaceVertex, Vertex}; /// /// Also see [`Vertex::builder`]. #[derive(Default)] -pub struct VertexBuilder { +pub struct PartialVertex { /// The position of the [`Vertex`] on the [`Curve`] pub position: Option>, @@ -26,7 +26,7 @@ pub struct VertexBuilder { pub global_form: Option, } -impl VertexBuilder { +impl PartialVertex { /// Build the [`Vertex`] with the provided position pub fn with_position(mut self, position: impl Into>) -> Self { self.position = Some(position.into()); diff --git a/crates/fj-kernel/src/objects/vertex.rs b/crates/fj-kernel/src/objects/vertex.rs index 022fe2c49..f93d57688 100644 --- a/crates/fj-kernel/src/objects/vertex.rs +++ b/crates/fj-kernel/src/objects/vertex.rs @@ -2,7 +2,7 @@ use fj_math::Point; use pretty_assertions::assert_eq; use crate::builder::{ - GlobalVertexBuilder, SurfaceVertexBuilder, VertexBuilder, + GlobalVertexBuilder, PartialVertex, SurfaceVertexBuilder, }; use super::{Curve, Surface}; @@ -21,9 +21,9 @@ pub struct Vertex { } impl Vertex { - /// Build a `Vertex` using [`VertexBuilder`] - pub fn builder() -> VertexBuilder { - VertexBuilder::default() + /// Build a `Vertex` using [`PartialVertex`] + pub fn builder() -> PartialVertex { + PartialVertex::default() } /// Construct an instance of `Vertex` From c35292856522c579c566084acb86f3cf7e67f1c7 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 22 Sep 2022 12:52:29 +0200 Subject: [PATCH 05/26] Rename `Vertex::builder` to `Vertex::partial` --- crates/fj-kernel/src/algorithms/sweep/vertex.rs | 2 +- crates/fj-kernel/src/builder/vertex.rs | 2 +- crates/fj-kernel/src/objects/vertex.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/sweep/vertex.rs b/crates/fj-kernel/src/algorithms/sweep/vertex.rs index 51f53f29b..7de75d8c0 100644 --- a/crates/fj-kernel/src/algorithms/sweep/vertex.rs +++ b/crates/fj-kernel/src/algorithms/sweep/vertex.rs @@ -161,7 +161,7 @@ mod tests { let surface = Surface::xz_plane(); let curve = Curve::builder(&stores, surface).build_u_axis(); - let vertex = Vertex::builder() + let vertex = Vertex::partial() .with_position([0.]) .with_curve(curve) .build(); diff --git a/crates/fj-kernel/src/builder/vertex.rs b/crates/fj-kernel/src/builder/vertex.rs index 191f58e93..418558bd4 100644 --- a/crates/fj-kernel/src/builder/vertex.rs +++ b/crates/fj-kernel/src/builder/vertex.rs @@ -4,7 +4,7 @@ use crate::objects::{Curve, GlobalVertex, Surface, SurfaceVertex, Vertex}; /// API for building a [`Vertex`] /// -/// Also see [`Vertex::builder`]. +/// Also see [`Vertex::partial`]. #[derive(Default)] pub struct PartialVertex { /// The position of the [`Vertex`] on the [`Curve`] diff --git a/crates/fj-kernel/src/objects/vertex.rs b/crates/fj-kernel/src/objects/vertex.rs index f93d57688..62a81f204 100644 --- a/crates/fj-kernel/src/objects/vertex.rs +++ b/crates/fj-kernel/src/objects/vertex.rs @@ -22,7 +22,7 @@ pub struct Vertex { impl Vertex { /// Build a `Vertex` using [`PartialVertex`] - pub fn builder() -> PartialVertex { + pub fn partial() -> PartialVertex { PartialVertex::default() } From f4faa09c39f367c6e4a1d34b9d17a1e6ece9fc68 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 22 Sep 2022 12:43:42 +0200 Subject: [PATCH 06/26] Update doc comments --- crates/fj-kernel/src/builder/cycle.rs | 2 +- crates/fj-kernel/src/builder/vertex.rs | 6 ++++++ crates/fj-kernel/src/objects/vertex.rs | 5 ++++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/crates/fj-kernel/src/builder/cycle.rs b/crates/fj-kernel/src/builder/cycle.rs index a31a333f3..346caef0a 100644 --- a/crates/fj-kernel/src/builder/cycle.rs +++ b/crates/fj-kernel/src/builder/cycle.rs @@ -83,7 +83,7 @@ impl<'a> CycleBuilder<'a> { self } - /// Create a polygon from a list of points + /// Finish building the [`Cycle`] pub fn build(self) -> Cycle { Cycle::new(self.surface, self.half_edges) } diff --git a/crates/fj-kernel/src/builder/vertex.rs b/crates/fj-kernel/src/builder/vertex.rs index 418558bd4..8993e6a4a 100644 --- a/crates/fj-kernel/src/builder/vertex.rs +++ b/crates/fj-kernel/src/builder/vertex.rs @@ -8,9 +8,15 @@ use crate::objects::{Curve, GlobalVertex, Surface, SurfaceVertex, Vertex}; #[derive(Default)] pub struct PartialVertex { /// The position of the [`Vertex`] on the [`Curve`] + /// + /// Must be provided to the builder before [`PartialVertex::build`] is + /// called. pub position: Option>, /// The curve that the [`Vertex`] is defined in + /// + /// Must be provided to the builder before [`PartialVertex::build`] is + /// called. pub curve: Option, /// The surface form of the [`Vertex`] diff --git a/crates/fj-kernel/src/objects/vertex.rs b/crates/fj-kernel/src/objects/vertex.rs index 62a81f204..da980353f 100644 --- a/crates/fj-kernel/src/objects/vertex.rs +++ b/crates/fj-kernel/src/objects/vertex.rs @@ -21,7 +21,10 @@ pub struct Vertex { } impl Vertex { - /// Build a `Vertex` using [`PartialVertex`] + /// Create a [`PartialVertex`] + /// + /// This function exists just for convenience, and will just return a + /// default [`PartialVertex`]. pub fn partial() -> PartialVertex { PartialVertex::default() } From d2ed3de0fad15286811fcdc518f49c416a18541c Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 22 Sep 2022 13:21:03 +0200 Subject: [PATCH 07/26] Move `PartialVertex` to new `partial` module --- crates/fj-kernel/src/builder/mod.rs | 2 +- crates/fj-kernel/src/builder/vertex.rs | 79 +----------------------- crates/fj-kernel/src/lib.rs | 1 + crates/fj-kernel/src/objects/vertex.rs | 5 +- crates/fj-kernel/src/partial/mod.rs | 29 +++++++++ crates/fj-kernel/src/partial/vertex.rs | 83 ++++++++++++++++++++++++++ 6 files changed, 118 insertions(+), 81 deletions(-) create mode 100644 crates/fj-kernel/src/partial/mod.rs create mode 100644 crates/fj-kernel/src/partial/vertex.rs diff --git a/crates/fj-kernel/src/builder/mod.rs b/crates/fj-kernel/src/builder/mod.rs index e003cb264..cfcf754ab 100644 --- a/crates/fj-kernel/src/builder/mod.rs +++ b/crates/fj-kernel/src/builder/mod.rs @@ -17,5 +17,5 @@ pub use self::{ shell::ShellBuilder, sketch::SketchBuilder, solid::SolidBuilder, - vertex::{GlobalVertexBuilder, PartialVertex, SurfaceVertexBuilder}, + vertex::{GlobalVertexBuilder, SurfaceVertexBuilder}, }; diff --git a/crates/fj-kernel/src/builder/vertex.rs b/crates/fj-kernel/src/builder/vertex.rs index 8993e6a4a..8d7c7aa65 100644 --- a/crates/fj-kernel/src/builder/vertex.rs +++ b/crates/fj-kernel/src/builder/vertex.rs @@ -1,83 +1,6 @@ use fj_math::Point; -use crate::objects::{Curve, GlobalVertex, Surface, SurfaceVertex, Vertex}; - -/// API for building a [`Vertex`] -/// -/// Also see [`Vertex::partial`]. -#[derive(Default)] -pub struct PartialVertex { - /// The position of the [`Vertex`] on the [`Curve`] - /// - /// Must be provided to the builder before [`PartialVertex::build`] is - /// called. - pub position: Option>, - - /// The curve that the [`Vertex`] is defined in - /// - /// Must be provided to the builder before [`PartialVertex::build`] is - /// called. - pub curve: Option, - - /// The surface form of the [`Vertex`] - /// - /// Can be provided to the builder, if already available, or computed from - /// the position on the [`Curve`]. - pub surface_form: Option, - - /// The global form of the [`Vertex`] - /// - /// Can be provided to the builder, if already available, or acquired - /// through the surface form. - pub global_form: Option, -} - -impl PartialVertex { - /// Build the [`Vertex`] with the provided position - pub fn with_position(mut self, position: impl Into>) -> Self { - self.position = Some(position.into()); - self - } - - /// Build the [`Vertex`] with the provided curve - pub fn with_curve(mut self, curve: Curve) -> Self { - self.curve = Some(curve); - self - } - - /// Build the [`Vertex`] with the provided surface form - pub fn with_surface_form(mut self, surface_form: SurfaceVertex) -> Self { - self.surface_form = Some(surface_form); - self - } - - /// Build the [`Vertex`] with the provided global form - pub fn with_global_form(mut self, global_form: GlobalVertex) -> Self { - self.global_form = Some(global_form); - self - } - - /// Finish building the [`Vertex`] - pub fn build(self) -> Vertex { - let position = self - .position - .expect("Cant' build `Vertex` without position"); - let curve = self.curve.expect("Can't build `Vertex` without `Curve`"); - - let surface_form = self.surface_form.unwrap_or_else(|| { - SurfaceVertexBuilder { - position: curve.path().point_from_path_coords(position), - surface: *curve.surface(), - global_form: self.global_form, - } - .build() - }); - - let global_form = *surface_form.global_form(); - - Vertex::new(position, curve, surface_form, global_form) - } -} +use crate::objects::{Curve, GlobalVertex, Surface, SurfaceVertex}; /// API for building a [`SurfaceVertex`] /// diff --git a/crates/fj-kernel/src/lib.rs b/crates/fj-kernel/src/lib.rs index 7342e23f1..da162ba61 100644 --- a/crates/fj-kernel/src/lib.rs +++ b/crates/fj-kernel/src/lib.rs @@ -91,5 +91,6 @@ pub mod algorithms; pub mod builder; pub mod iter; pub mod objects; +pub mod partial; pub mod path; pub mod stores; diff --git a/crates/fj-kernel/src/objects/vertex.rs b/crates/fj-kernel/src/objects/vertex.rs index da980353f..6bffd7b47 100644 --- a/crates/fj-kernel/src/objects/vertex.rs +++ b/crates/fj-kernel/src/objects/vertex.rs @@ -1,8 +1,9 @@ use fj_math::Point; use pretty_assertions::assert_eq; -use crate::builder::{ - GlobalVertexBuilder, PartialVertex, SurfaceVertexBuilder, +use crate::{ + builder::{GlobalVertexBuilder, SurfaceVertexBuilder}, + partial::PartialVertex, }; use super::{Curve, Surface}; diff --git a/crates/fj-kernel/src/partial/mod.rs b/crates/fj-kernel/src/partial/mod.rs new file mode 100644 index 000000000..5e8a75aee --- /dev/null +++ b/crates/fj-kernel/src/partial/mod.rs @@ -0,0 +1,29 @@ +//! Partial objects +//! +//! This module contains type that represent partial objects. This is useful +//! when building objects, as it's often possible to provide just some the data +//! they own or objects they reference, while computing the rest. +//! +//! More generally speaking, there are situations where different parts of a new +//! objects are available at different times, and provided from different +//! places. Partial objects can be used to represent such partially constructed +//! objects whenever that is required. +//! +//! The API for partial objects follows a specific style: +//! +//! - Partial objects are structs with fields that mirror the fields of the full +//! object structs, but all fields are optional. +//! - Partial object structs implement [`Default`], but a `partial` method is +//! also available on the respective full object struct, as a perhaps more +//! convenient and readable way to construct a partial object. +//! - Partial object structs have `with_*` methods to provide values for each of +//! their fields. +//! - Partial object structs may have `as_*` methods, if one or more of their +//! fields can be initialized by providing some alternative data. +//! - Partial object structs have a `build` method to build a full object. +//! - All `with_*`, `as_*`, and `build` methods can be chained, to provide a +//! convenient API. + +mod vertex; + +pub use self::vertex::PartialVertex; diff --git a/crates/fj-kernel/src/partial/vertex.rs b/crates/fj-kernel/src/partial/vertex.rs new file mode 100644 index 000000000..9ce8a495e --- /dev/null +++ b/crates/fj-kernel/src/partial/vertex.rs @@ -0,0 +1,83 @@ +use fj_math::Point; + +use crate::{ + builder::SurfaceVertexBuilder, + objects::{Curve, GlobalVertex, SurfaceVertex, Vertex}, +}; + +/// API for building a [`Vertex`] +/// +/// Also see [`Vertex::partial`]. +#[derive(Default)] +pub struct PartialVertex { + /// The position of the [`Vertex`] on the [`Curve`] + /// + /// Must be provided to the builder before [`PartialVertex::build`] is + /// called. + pub position: Option>, + + /// The curve that the [`Vertex`] is defined in + /// + /// Must be provided to the builder before [`PartialVertex::build`] is + /// called. + pub curve: Option, + + /// The surface form of the [`Vertex`] + /// + /// Can be provided to the builder, if already available, or computed from + /// the position on the [`Curve`]. + pub surface_form: Option, + + /// The global form of the [`Vertex`] + /// + /// Can be provided to the builder, if already available, or acquired + /// through the surface form. + pub global_form: Option, +} + +impl PartialVertex { + /// Build the [`Vertex`] with the provided position + pub fn with_position(mut self, position: impl Into>) -> Self { + self.position = Some(position.into()); + self + } + + /// Build the [`Vertex`] with the provided curve + pub fn with_curve(mut self, curve: Curve) -> Self { + self.curve = Some(curve); + self + } + + /// Build the [`Vertex`] with the provided surface form + pub fn with_surface_form(mut self, surface_form: SurfaceVertex) -> Self { + self.surface_form = Some(surface_form); + self + } + + /// Build the [`Vertex`] with the provided global form + pub fn with_global_form(mut self, global_form: GlobalVertex) -> Self { + self.global_form = Some(global_form); + self + } + + /// Finish building the [`Vertex`] + pub fn build(self) -> Vertex { + let position = self + .position + .expect("Cant' build `Vertex` without position"); + let curve = self.curve.expect("Can't build `Vertex` without `Curve`"); + + let surface_form = self.surface_form.unwrap_or_else(|| { + SurfaceVertexBuilder { + position: curve.path().point_from_path_coords(position), + surface: *curve.surface(), + global_form: self.global_form, + } + .build() + }); + + let global_form = *surface_form.global_form(); + + Vertex::new(position, curve, surface_form, global_form) + } +} From 4c5fd94fed379d2d58098f70d6a88bf34f1558b1 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 22 Sep 2022 13:30:28 +0200 Subject: [PATCH 08/26] Update doc comments --- crates/fj-kernel/src/partial/vertex.rs | 34 ++++++++++++++------------ 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/crates/fj-kernel/src/partial/vertex.rs b/crates/fj-kernel/src/partial/vertex.rs index 9ce8a495e..c92257b50 100644 --- a/crates/fj-kernel/src/partial/vertex.rs +++ b/crates/fj-kernel/src/partial/vertex.rs @@ -5,62 +5,66 @@ use crate::{ objects::{Curve, GlobalVertex, SurfaceVertex, Vertex}, }; -/// API for building a [`Vertex`] +/// A partial [`Vertex`] /// -/// Also see [`Vertex::partial`]. +/// See [`crate::partial`] for more information. #[derive(Default)] pub struct PartialVertex { /// The position of the [`Vertex`] on the [`Curve`] /// - /// Must be provided to the builder before [`PartialVertex::build`] is - /// called. + /// Must be provided before [`PartialVertex::build`] is called. pub position: Option>, /// The curve that the [`Vertex`] is defined in /// - /// Must be provided to the builder before [`PartialVertex::build`] is - /// called. + /// Must be provided before [`PartialVertex::build`] is called. pub curve: Option, /// The surface form of the [`Vertex`] /// - /// Can be provided to the builder, if already available, or computed from - /// the position on the [`Curve`]. + /// Can be provided, if already available, or computed from the position on + /// the [`Curve`]. pub surface_form: Option, /// The global form of the [`Vertex`] /// - /// Can be provided to the builder, if already available, or acquired - /// through the surface form. + /// Can be provided, if already available, or acquired through the surface + /// form. pub global_form: Option, } impl PartialVertex { - /// Build the [`Vertex`] with the provided position + /// Provide a position for the partial vertex pub fn with_position(mut self, position: impl Into>) -> Self { self.position = Some(position.into()); self } - /// Build the [`Vertex`] with the provided curve + /// Provide a curve for the partial vertex pub fn with_curve(mut self, curve: Curve) -> Self { self.curve = Some(curve); self } - /// Build the [`Vertex`] with the provided surface form + /// Provide a surface form for the partial vertex pub fn with_surface_form(mut self, surface_form: SurfaceVertex) -> Self { self.surface_form = Some(surface_form); self } - /// Build the [`Vertex`] with the provided global form + /// Provide a global form for the partial vertex pub fn with_global_form(mut self, global_form: GlobalVertex) -> Self { self.global_form = Some(global_form); self } - /// Finish building the [`Vertex`] + /// Build a full [`Vertex`] from the partial vertex + /// + /// # Panics + /// + /// Panics, if no position has been provided. + /// + /// Panics, if no curve has been provided. pub fn build(self) -> Vertex { let position = self .position From 795d0049ae8c532db0e2ab9c566acb794f41f8c4 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 22 Sep 2022 13:32:34 +0200 Subject: [PATCH 09/26] Rename `SurfaceVertexBuilder` --- crates/fj-kernel/src/builder/mod.rs | 2 +- crates/fj-kernel/src/builder/vertex.rs | 4 ++-- crates/fj-kernel/src/objects/vertex.rs | 8 ++++---- crates/fj-kernel/src/partial/vertex.rs | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/crates/fj-kernel/src/builder/mod.rs b/crates/fj-kernel/src/builder/mod.rs index cfcf754ab..4c114173f 100644 --- a/crates/fj-kernel/src/builder/mod.rs +++ b/crates/fj-kernel/src/builder/mod.rs @@ -17,5 +17,5 @@ pub use self::{ shell::ShellBuilder, sketch::SketchBuilder, solid::SolidBuilder, - vertex::{GlobalVertexBuilder, SurfaceVertexBuilder}, + vertex::{GlobalVertexBuilder, PartialSurfaceVertex}, }; diff --git a/crates/fj-kernel/src/builder/vertex.rs b/crates/fj-kernel/src/builder/vertex.rs index 8d7c7aa65..11c41b7ec 100644 --- a/crates/fj-kernel/src/builder/vertex.rs +++ b/crates/fj-kernel/src/builder/vertex.rs @@ -5,7 +5,7 @@ use crate::objects::{Curve, GlobalVertex, Surface, SurfaceVertex}; /// API for building a [`SurfaceVertex`] /// /// Also see [`SurfaceVertex::builder`]. -pub struct SurfaceVertexBuilder { +pub struct PartialSurfaceVertex { /// The position of the [`SurfaceVertex`] on the [`Surface`] pub position: Point<2>, @@ -19,7 +19,7 @@ pub struct SurfaceVertexBuilder { pub global_form: Option, } -impl SurfaceVertexBuilder { +impl PartialSurfaceVertex { /// Build the [`SurfaceVertex`] with the provided global form pub fn with_global_form(mut self, global_form: GlobalVertex) -> Self { self.global_form = Some(global_form); diff --git a/crates/fj-kernel/src/objects/vertex.rs b/crates/fj-kernel/src/objects/vertex.rs index 6bffd7b47..711eaaa1d 100644 --- a/crates/fj-kernel/src/objects/vertex.rs +++ b/crates/fj-kernel/src/objects/vertex.rs @@ -2,7 +2,7 @@ use fj_math::Point; use pretty_assertions::assert_eq; use crate::{ - builder::{GlobalVertexBuilder, SurfaceVertexBuilder}, + builder::{GlobalVertexBuilder, PartialSurfaceVertex}, partial::PartialVertex, }; @@ -86,12 +86,12 @@ pub struct SurfaceVertex { } impl SurfaceVertex { - /// Build a `SurfaceVertex` using [`SurfaceVertexBuilder`] + /// Build a `SurfaceVertex` using [`PartialSurfaceVertex`] pub fn builder( position: impl Into>, surface: Surface, - ) -> SurfaceVertexBuilder { - SurfaceVertexBuilder { + ) -> PartialSurfaceVertex { + PartialSurfaceVertex { position: position.into(), surface, global_form: None, diff --git a/crates/fj-kernel/src/partial/vertex.rs b/crates/fj-kernel/src/partial/vertex.rs index c92257b50..6ce893772 100644 --- a/crates/fj-kernel/src/partial/vertex.rs +++ b/crates/fj-kernel/src/partial/vertex.rs @@ -1,7 +1,7 @@ use fj_math::Point; use crate::{ - builder::SurfaceVertexBuilder, + builder::PartialSurfaceVertex, objects::{Curve, GlobalVertex, SurfaceVertex, Vertex}, }; @@ -72,7 +72,7 @@ impl PartialVertex { let curve = self.curve.expect("Can't build `Vertex` without `Curve`"); let surface_form = self.surface_form.unwrap_or_else(|| { - SurfaceVertexBuilder { + PartialSurfaceVertex { position: curve.path().point_from_path_coords(position), surface: *curve.surface(), global_form: self.global_form, From a832d3acb02ab422b4a2c21af51f39ea82df703a Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 22 Sep 2022 13:33:35 +0200 Subject: [PATCH 10/26] Rename `SurfaceVertex::builder` --- crates/fj-kernel/src/builder/vertex.rs | 2 +- crates/fj-kernel/src/objects/vertex.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/fj-kernel/src/builder/vertex.rs b/crates/fj-kernel/src/builder/vertex.rs index 11c41b7ec..cdc098f42 100644 --- a/crates/fj-kernel/src/builder/vertex.rs +++ b/crates/fj-kernel/src/builder/vertex.rs @@ -4,7 +4,7 @@ use crate::objects::{Curve, GlobalVertex, Surface, SurfaceVertex}; /// API for building a [`SurfaceVertex`] /// -/// Also see [`SurfaceVertex::builder`]. +/// Also see [`SurfaceVertex::partial`]. pub struct PartialSurfaceVertex { /// The position of the [`SurfaceVertex`] on the [`Surface`] pub position: Point<2>, diff --git a/crates/fj-kernel/src/objects/vertex.rs b/crates/fj-kernel/src/objects/vertex.rs index 711eaaa1d..4d64845e5 100644 --- a/crates/fj-kernel/src/objects/vertex.rs +++ b/crates/fj-kernel/src/objects/vertex.rs @@ -87,7 +87,7 @@ pub struct SurfaceVertex { impl SurfaceVertex { /// Build a `SurfaceVertex` using [`PartialSurfaceVertex`] - pub fn builder( + pub fn partial( position: impl Into>, surface: Surface, ) -> PartialSurfaceVertex { From c5929ab418ad2d2c29c2dbe17bca7859ae0e45c7 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 22 Sep 2022 13:36:33 +0200 Subject: [PATCH 11/26] Make `Surface` of `PartialSurfaceVertex` optional --- crates/fj-kernel/src/builder/vertex.rs | 16 +++++++++++++--- crates/fj-kernel/src/objects/vertex.rs | 7 ++----- crates/fj-kernel/src/partial/vertex.rs | 2 +- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/crates/fj-kernel/src/builder/vertex.rs b/crates/fj-kernel/src/builder/vertex.rs index cdc098f42..4802d045c 100644 --- a/crates/fj-kernel/src/builder/vertex.rs +++ b/crates/fj-kernel/src/builder/vertex.rs @@ -10,7 +10,7 @@ pub struct PartialSurfaceVertex { pub position: Point<2>, /// The surface that the [`SurfaceVertex`] is defined in - pub surface: Surface, + pub surface: Option, /// The global form of the [`SurfaceVertex`] /// @@ -20,6 +20,12 @@ pub struct PartialSurfaceVertex { } impl PartialSurfaceVertex { + /// Provide a surface for the partial surface vertex + pub fn with_surface(mut self, surface: Surface) -> Self { + self.surface = Some(surface); + self + } + /// Build the [`SurfaceVertex`] with the provided global form pub fn with_global_form(mut self, global_form: GlobalVertex) -> Self { self.global_form = Some(global_form); @@ -28,12 +34,16 @@ impl PartialSurfaceVertex { /// Finish building the [`SurfaceVertex`] pub fn build(self) -> SurfaceVertex { + let surface = self + .surface + .expect("Can't build `SurfaceVertex` without `Surface`"); + let global_form = self.global_form.unwrap_or_else(|| { GlobalVertex::builder() - .build_from_surface_and_position(&self.surface, self.position) + .build_from_surface_and_position(&surface, self.position) }); - SurfaceVertex::new(self.position, self.surface, global_form) + SurfaceVertex::new(self.position, surface, global_form) } } diff --git a/crates/fj-kernel/src/objects/vertex.rs b/crates/fj-kernel/src/objects/vertex.rs index 4d64845e5..57f5aa0b7 100644 --- a/crates/fj-kernel/src/objects/vertex.rs +++ b/crates/fj-kernel/src/objects/vertex.rs @@ -87,13 +87,10 @@ pub struct SurfaceVertex { impl SurfaceVertex { /// Build a `SurfaceVertex` using [`PartialSurfaceVertex`] - pub fn partial( - position: impl Into>, - surface: Surface, - ) -> PartialSurfaceVertex { + pub fn partial(position: impl Into>) -> PartialSurfaceVertex { PartialSurfaceVertex { position: position.into(), - surface, + surface: None, global_form: None, } } diff --git a/crates/fj-kernel/src/partial/vertex.rs b/crates/fj-kernel/src/partial/vertex.rs index 6ce893772..43595fc7a 100644 --- a/crates/fj-kernel/src/partial/vertex.rs +++ b/crates/fj-kernel/src/partial/vertex.rs @@ -74,7 +74,7 @@ impl PartialVertex { let surface_form = self.surface_form.unwrap_or_else(|| { PartialSurfaceVertex { position: curve.path().point_from_path_coords(position), - surface: *curve.surface(), + surface: Some(*curve.surface()), global_form: self.global_form, } .build() From 454da2c2fdd36fc3c05e520c32c7cdff073d161b Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 22 Sep 2022 13:39:18 +0200 Subject: [PATCH 12/26] Make position of `PartialSurfaceVertex` optional --- crates/fj-kernel/src/builder/vertex.rs | 15 ++++++++++++--- crates/fj-kernel/src/objects/vertex.rs | 4 ++-- crates/fj-kernel/src/partial/vertex.rs | 2 +- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/crates/fj-kernel/src/builder/vertex.rs b/crates/fj-kernel/src/builder/vertex.rs index 4802d045c..ba7c6bc41 100644 --- a/crates/fj-kernel/src/builder/vertex.rs +++ b/crates/fj-kernel/src/builder/vertex.rs @@ -7,7 +7,7 @@ use crate::objects::{Curve, GlobalVertex, Surface, SurfaceVertex}; /// Also see [`SurfaceVertex::partial`]. pub struct PartialSurfaceVertex { /// The position of the [`SurfaceVertex`] on the [`Surface`] - pub position: Point<2>, + pub position: Option>, /// The surface that the [`SurfaceVertex`] is defined in pub surface: Option, @@ -20,6 +20,12 @@ pub struct PartialSurfaceVertex { } impl PartialSurfaceVertex { + /// Provide a position for the partial surface vertex + pub fn with_position(mut self, position: impl Into>) -> Self { + self.position = Some(position.into()); + self + } + /// Provide a surface for the partial surface vertex pub fn with_surface(mut self, surface: Surface) -> Self { self.surface = Some(surface); @@ -34,16 +40,19 @@ impl PartialSurfaceVertex { /// Finish building the [`SurfaceVertex`] pub fn build(self) -> SurfaceVertex { + let position = self + .position + .expect("Can't build `SurfaceVertex` without position"); let surface = self .surface .expect("Can't build `SurfaceVertex` without `Surface`"); let global_form = self.global_form.unwrap_or_else(|| { GlobalVertex::builder() - .build_from_surface_and_position(&surface, self.position) + .build_from_surface_and_position(&surface, position) }); - SurfaceVertex::new(self.position, surface, global_form) + SurfaceVertex::new(position, surface, global_form) } } diff --git a/crates/fj-kernel/src/objects/vertex.rs b/crates/fj-kernel/src/objects/vertex.rs index 57f5aa0b7..ec0876716 100644 --- a/crates/fj-kernel/src/objects/vertex.rs +++ b/crates/fj-kernel/src/objects/vertex.rs @@ -87,9 +87,9 @@ pub struct SurfaceVertex { impl SurfaceVertex { /// Build a `SurfaceVertex` using [`PartialSurfaceVertex`] - pub fn partial(position: impl Into>) -> PartialSurfaceVertex { + pub fn partial() -> PartialSurfaceVertex { PartialSurfaceVertex { - position: position.into(), + position: None, surface: None, global_form: None, } diff --git a/crates/fj-kernel/src/partial/vertex.rs b/crates/fj-kernel/src/partial/vertex.rs index 43595fc7a..13118227e 100644 --- a/crates/fj-kernel/src/partial/vertex.rs +++ b/crates/fj-kernel/src/partial/vertex.rs @@ -73,7 +73,7 @@ impl PartialVertex { let surface_form = self.surface_form.unwrap_or_else(|| { PartialSurfaceVertex { - position: curve.path().point_from_path_coords(position), + position: Some(curve.path().point_from_path_coords(position)), surface: Some(*curve.surface()), global_form: self.global_form, } From 254d45854413b0e48ad7adab55a424cc97c54a9e Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 22 Sep 2022 13:40:28 +0200 Subject: [PATCH 13/26] Derive `Default` for `PartialSurfaceVertex` --- crates/fj-kernel/src/builder/vertex.rs | 1 + crates/fj-kernel/src/objects/vertex.rs | 6 +----- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/crates/fj-kernel/src/builder/vertex.rs b/crates/fj-kernel/src/builder/vertex.rs index ba7c6bc41..87c0c58c1 100644 --- a/crates/fj-kernel/src/builder/vertex.rs +++ b/crates/fj-kernel/src/builder/vertex.rs @@ -5,6 +5,7 @@ use crate::objects::{Curve, GlobalVertex, Surface, SurfaceVertex}; /// API for building a [`SurfaceVertex`] /// /// Also see [`SurfaceVertex::partial`]. +#[derive(Default)] pub struct PartialSurfaceVertex { /// The position of the [`SurfaceVertex`] on the [`Surface`] pub position: Option>, diff --git a/crates/fj-kernel/src/objects/vertex.rs b/crates/fj-kernel/src/objects/vertex.rs index ec0876716..0401c61cc 100644 --- a/crates/fj-kernel/src/objects/vertex.rs +++ b/crates/fj-kernel/src/objects/vertex.rs @@ -88,11 +88,7 @@ pub struct SurfaceVertex { impl SurfaceVertex { /// Build a `SurfaceVertex` using [`PartialSurfaceVertex`] pub fn partial() -> PartialSurfaceVertex { - PartialSurfaceVertex { - position: None, - surface: None, - global_form: None, - } + PartialSurfaceVertex::default() } /// Construct a new instance of `SurfaceVertex` From 26e2f6431a5b7219a493201eae63389d2f62f19e Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 22 Sep 2022 13:44:22 +0200 Subject: [PATCH 14/26] Update documentation of `PartialSurfaceVertex` --- crates/fj-kernel/src/builder/vertex.rs | 24 +++++++++++++++++------- crates/fj-kernel/src/objects/vertex.rs | 5 ++++- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/crates/fj-kernel/src/builder/vertex.rs b/crates/fj-kernel/src/builder/vertex.rs index 87c0c58c1..4be114fd9 100644 --- a/crates/fj-kernel/src/builder/vertex.rs +++ b/crates/fj-kernel/src/builder/vertex.rs @@ -2,21 +2,25 @@ use fj_math::Point; use crate::objects::{Curve, GlobalVertex, Surface, SurfaceVertex}; -/// API for building a [`SurfaceVertex`] +/// A partial [`SurfaceVertex`] /// -/// Also see [`SurfaceVertex::partial`]. +/// See [`crate::partial`] for more information. #[derive(Default)] pub struct PartialSurfaceVertex { - /// The position of the [`SurfaceVertex`] on the [`Surface`] + /// The position of the [`SurfaceVertex`] in the [`Surface`] + /// + /// Must be provided before [`PartialSurfaceVertex::build`] is called. pub position: Option>, /// The surface that the [`SurfaceVertex`] is defined in + /// + /// Must be provided before [`PartialSurfaceVertex::build`] is called. pub surface: Option, /// The global form of the [`SurfaceVertex`] /// - /// Can be provided to the builder, if already available, or computed from - /// the position on the [`Surface`]. + /// Can be provided, if already available, or computed from the position on + /// the [`Surface`]. pub global_form: Option, } @@ -33,13 +37,19 @@ impl PartialSurfaceVertex { self } - /// Build the [`SurfaceVertex`] with the provided global form + /// Provide a global form for the partial surface vertex pub fn with_global_form(mut self, global_form: GlobalVertex) -> Self { self.global_form = Some(global_form); self } - /// Finish building the [`SurfaceVertex`] + /// Build a full [`SurfaceVertex`] from the partial surface vertex + /// + /// # Panics + /// + /// Panics, if no position has been provided. + /// + /// Panics, if no surface has been provided. pub fn build(self) -> SurfaceVertex { let position = self .position diff --git a/crates/fj-kernel/src/objects/vertex.rs b/crates/fj-kernel/src/objects/vertex.rs index 0401c61cc..fe00e62af 100644 --- a/crates/fj-kernel/src/objects/vertex.rs +++ b/crates/fj-kernel/src/objects/vertex.rs @@ -86,7 +86,10 @@ pub struct SurfaceVertex { } impl SurfaceVertex { - /// Build a `SurfaceVertex` using [`PartialSurfaceVertex`] + /// Create a [`PartialSurfaceVertex`] + /// + /// This function exists just for convenience, and will just return a + /// default [`PartialSurfaceVertex`]. pub fn partial() -> PartialSurfaceVertex { PartialSurfaceVertex::default() } From 3a2dffe909beb544386193e151eb88487cef5223 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 22 Sep 2022 13:45:59 +0200 Subject: [PATCH 15/26] Move `PartialSurfaceVertex` to `partial` module --- crates/fj-kernel/src/builder/mod.rs | 2 +- crates/fj-kernel/src/builder/vertex.rs | 67 +----------------------- crates/fj-kernel/src/objects/vertex.rs | 4 +- crates/fj-kernel/src/partial/mod.rs | 2 +- crates/fj-kernel/src/partial/vertex.rs | 70 ++++++++++++++++++++++++-- 5 files changed, 71 insertions(+), 74 deletions(-) diff --git a/crates/fj-kernel/src/builder/mod.rs b/crates/fj-kernel/src/builder/mod.rs index 4c114173f..688b09087 100644 --- a/crates/fj-kernel/src/builder/mod.rs +++ b/crates/fj-kernel/src/builder/mod.rs @@ -17,5 +17,5 @@ pub use self::{ shell::ShellBuilder, sketch::SketchBuilder, solid::SolidBuilder, - vertex::{GlobalVertexBuilder, PartialSurfaceVertex}, + vertex::GlobalVertexBuilder, }; diff --git a/crates/fj-kernel/src/builder/vertex.rs b/crates/fj-kernel/src/builder/vertex.rs index 4be114fd9..3f9bafea2 100644 --- a/crates/fj-kernel/src/builder/vertex.rs +++ b/crates/fj-kernel/src/builder/vertex.rs @@ -1,71 +1,6 @@ use fj_math::Point; -use crate::objects::{Curve, GlobalVertex, Surface, SurfaceVertex}; - -/// A partial [`SurfaceVertex`] -/// -/// See [`crate::partial`] for more information. -#[derive(Default)] -pub struct PartialSurfaceVertex { - /// The position of the [`SurfaceVertex`] in the [`Surface`] - /// - /// Must be provided before [`PartialSurfaceVertex::build`] is called. - pub position: Option>, - - /// The surface that the [`SurfaceVertex`] is defined in - /// - /// Must be provided before [`PartialSurfaceVertex::build`] is called. - pub surface: Option, - - /// The global form of the [`SurfaceVertex`] - /// - /// Can be provided, if already available, or computed from the position on - /// the [`Surface`]. - pub global_form: Option, -} - -impl PartialSurfaceVertex { - /// Provide a position for the partial surface vertex - pub fn with_position(mut self, position: impl Into>) -> Self { - self.position = Some(position.into()); - self - } - - /// Provide a surface for the partial surface vertex - pub fn with_surface(mut self, surface: Surface) -> Self { - self.surface = Some(surface); - self - } - - /// Provide a global form for the partial surface vertex - pub fn with_global_form(mut self, global_form: GlobalVertex) -> Self { - self.global_form = Some(global_form); - self - } - - /// Build a full [`SurfaceVertex`] from the partial surface vertex - /// - /// # Panics - /// - /// Panics, if no position has been provided. - /// - /// Panics, if no surface has been provided. - pub fn build(self) -> SurfaceVertex { - let position = self - .position - .expect("Can't build `SurfaceVertex` without position"); - let surface = self - .surface - .expect("Can't build `SurfaceVertex` without `Surface`"); - - let global_form = self.global_form.unwrap_or_else(|| { - GlobalVertex::builder() - .build_from_surface_and_position(&surface, position) - }); - - SurfaceVertex::new(position, surface, global_form) - } -} +use crate::objects::{Curve, GlobalVertex, Surface}; /// API for building a [`GlobalVertex`] /// diff --git a/crates/fj-kernel/src/objects/vertex.rs b/crates/fj-kernel/src/objects/vertex.rs index fe00e62af..32749c308 100644 --- a/crates/fj-kernel/src/objects/vertex.rs +++ b/crates/fj-kernel/src/objects/vertex.rs @@ -2,8 +2,8 @@ use fj_math::Point; use pretty_assertions::assert_eq; use crate::{ - builder::{GlobalVertexBuilder, PartialSurfaceVertex}, - partial::PartialVertex, + builder::GlobalVertexBuilder, + partial::{PartialSurfaceVertex, PartialVertex}, }; use super::{Curve, Surface}; diff --git a/crates/fj-kernel/src/partial/mod.rs b/crates/fj-kernel/src/partial/mod.rs index 5e8a75aee..d6ea119a6 100644 --- a/crates/fj-kernel/src/partial/mod.rs +++ b/crates/fj-kernel/src/partial/mod.rs @@ -26,4 +26,4 @@ mod vertex; -pub use self::vertex::PartialVertex; +pub use self::vertex::{PartialSurfaceVertex, PartialVertex}; diff --git a/crates/fj-kernel/src/partial/vertex.rs b/crates/fj-kernel/src/partial/vertex.rs index 13118227e..0ce000abd 100644 --- a/crates/fj-kernel/src/partial/vertex.rs +++ b/crates/fj-kernel/src/partial/vertex.rs @@ -1,9 +1,6 @@ use fj_math::Point; -use crate::{ - builder::PartialSurfaceVertex, - objects::{Curve, GlobalVertex, SurfaceVertex, Vertex}, -}; +use crate::objects::{Curve, GlobalVertex, Surface, SurfaceVertex, Vertex}; /// A partial [`Vertex`] /// @@ -85,3 +82,68 @@ impl PartialVertex { Vertex::new(position, curve, surface_form, global_form) } } + +/// A partial [`SurfaceVertex`] +/// +/// See [`crate::partial`] for more information. +#[derive(Default)] +pub struct PartialSurfaceVertex { + /// The position of the [`SurfaceVertex`] in the [`Surface`] + /// + /// Must be provided before [`PartialSurfaceVertex::build`] is called. + pub position: Option>, + + /// The surface that the [`SurfaceVertex`] is defined in + /// + /// Must be provided before [`PartialSurfaceVertex::build`] is called. + pub surface: Option, + + /// The global form of the [`SurfaceVertex`] + /// + /// Can be provided, if already available, or computed from the position on + /// the [`Surface`]. + pub global_form: Option, +} + +impl PartialSurfaceVertex { + /// Provide a position for the partial surface vertex + pub fn with_position(mut self, position: impl Into>) -> Self { + self.position = Some(position.into()); + self + } + + /// Provide a surface for the partial surface vertex + pub fn with_surface(mut self, surface: Surface) -> Self { + self.surface = Some(surface); + self + } + + /// Provide a global form for the partial surface vertex + pub fn with_global_form(mut self, global_form: GlobalVertex) -> Self { + self.global_form = Some(global_form); + self + } + + /// Build a full [`SurfaceVertex`] from the partial surface vertex + /// + /// # Panics + /// + /// Panics, if no position has been provided. + /// + /// Panics, if no surface has been provided. + pub fn build(self) -> SurfaceVertex { + let position = self + .position + .expect("Can't build `SurfaceVertex` without position"); + let surface = self + .surface + .expect("Can't build `SurfaceVertex` without `Surface`"); + + let global_form = self.global_form.unwrap_or_else(|| { + GlobalVertex::builder() + .build_from_surface_and_position(&surface, position) + }); + + SurfaceVertex::new(position, surface, global_form) + } +} From b0eaedda2cba686f63ee3ea36765749d46011467 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 22 Sep 2022 13:51:06 +0200 Subject: [PATCH 16/26] Move `self` into `GlobalVertexBuilder` methods --- crates/fj-kernel/src/builder/vertex.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/fj-kernel/src/builder/vertex.rs b/crates/fj-kernel/src/builder/vertex.rs index 3f9bafea2..10953b299 100644 --- a/crates/fj-kernel/src/builder/vertex.rs +++ b/crates/fj-kernel/src/builder/vertex.rs @@ -10,7 +10,7 @@ pub struct GlobalVertexBuilder; impl GlobalVertexBuilder { /// Build a [`GlobalVertex`] from a curve and a position on that curve pub fn build_from_curve_and_position( - &self, + self, curve: &Curve, position: impl Into>, ) -> GlobalVertex { @@ -20,7 +20,7 @@ impl GlobalVertexBuilder { /// Build a [`GlobalVertex`] from a surface and a position on that surface pub fn build_from_surface_and_position( - &self, + self, surface: &Surface, position: impl Into>, ) -> GlobalVertex { From d308729d1a0590a82f7b173808dc0b1bf0b9e45e Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 22 Sep 2022 14:04:18 +0200 Subject: [PATCH 17/26] Derive `Default` for `GlobalVertexBuilder` --- crates/fj-kernel/src/builder/vertex.rs | 1 + crates/fj-kernel/src/objects/vertex.rs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/fj-kernel/src/builder/vertex.rs b/crates/fj-kernel/src/builder/vertex.rs index 10953b299..16730deec 100644 --- a/crates/fj-kernel/src/builder/vertex.rs +++ b/crates/fj-kernel/src/builder/vertex.rs @@ -5,6 +5,7 @@ use crate::objects::{Curve, GlobalVertex, Surface}; /// API for building a [`GlobalVertex`] /// /// Also see [`GlobalVertex::builder`]. +#[derive(Default)] pub struct GlobalVertexBuilder; impl GlobalVertexBuilder { diff --git a/crates/fj-kernel/src/objects/vertex.rs b/crates/fj-kernel/src/objects/vertex.rs index 32749c308..bde10ec12 100644 --- a/crates/fj-kernel/src/objects/vertex.rs +++ b/crates/fj-kernel/src/objects/vertex.rs @@ -150,7 +150,7 @@ pub struct GlobalVertex { impl GlobalVertex { /// Build a `GlobalVertex` using [`GlobalVertexBuilder`] pub fn builder() -> GlobalVertexBuilder { - GlobalVertexBuilder + GlobalVertexBuilder::default() } /// Construct a `GlobalVertex` from a point From 24be0e55a3b402a1dbfd18c24b6dcbc0ca88022e Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 22 Sep 2022 14:07:55 +0200 Subject: [PATCH 18/26] Add full builder API to `GlobalVertexBuilder` --- crates/fj-kernel/src/builder/vertex.rs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/crates/fj-kernel/src/builder/vertex.rs b/crates/fj-kernel/src/builder/vertex.rs index 16730deec..1bf21871f 100644 --- a/crates/fj-kernel/src/builder/vertex.rs +++ b/crates/fj-kernel/src/builder/vertex.rs @@ -6,9 +6,18 @@ use crate::objects::{Curve, GlobalVertex, Surface}; /// /// Also see [`GlobalVertex::builder`]. #[derive(Default)] -pub struct GlobalVertexBuilder; +pub struct GlobalVertexBuilder { + /// The position of the [`GlobalVertex`] + pub position: Option>, +} impl GlobalVertexBuilder { + /// Provide a position + pub fn with_position(mut self, position: impl Into>) -> Self { + self.position = Some(position.into()); + self + } + /// Build a [`GlobalVertex`] from a curve and a position on that curve pub fn build_from_curve_and_position( self, @@ -28,4 +37,13 @@ impl GlobalVertexBuilder { let position = surface.point_from_surface_coords(position); GlobalVertex::from_position(position) } + + /// Build a full [`GlobalVertex`] + pub fn build(self) -> GlobalVertex { + let position = self + .position + .expect("Can't build a `GlobalVertex` without a position"); + + GlobalVertex::from_position(position) + } } From 495c5d2ef0052366f5e04f03f391c3bb0874d58d Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 22 Sep 2022 14:13:37 +0200 Subject: [PATCH 19/26] Replace `GlobalVertexBuilder` method --- crates/fj-kernel/src/builder/edge.rs | 3 ++- crates/fj-kernel/src/builder/vertex.rs | 13 +++++++------ crates/fj-kernel/src/partial/vertex.rs | 3 ++- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/crates/fj-kernel/src/builder/edge.rs b/crates/fj-kernel/src/builder/edge.rs index 707b8965c..812df9658 100644 --- a/crates/fj-kernel/src/builder/edge.rs +++ b/crates/fj-kernel/src/builder/edge.rs @@ -99,7 +99,8 @@ impl<'a> HalfEdgeBuilder<'a> { let global_vertices = points.map(|position| { GlobalVertex::builder() - .build_from_surface_and_position(&self.surface, position) + .from_surface_and_position(&self.surface, position) + .build() }); let surface_vertices = { diff --git a/crates/fj-kernel/src/builder/vertex.rs b/crates/fj-kernel/src/builder/vertex.rs index 1bf21871f..42a22d180 100644 --- a/crates/fj-kernel/src/builder/vertex.rs +++ b/crates/fj-kernel/src/builder/vertex.rs @@ -25,17 +25,18 @@ impl GlobalVertexBuilder { position: impl Into>, ) -> GlobalVertex { let position_surface = curve.path().point_from_path_coords(position); - self.build_from_surface_and_position(curve.surface(), position_surface) + self.from_surface_and_position(curve.surface(), position_surface) + .build() } /// Build a [`GlobalVertex`] from a surface and a position on that surface - pub fn build_from_surface_and_position( - self, + pub fn from_surface_and_position( + mut self, surface: &Surface, position: impl Into>, - ) -> GlobalVertex { - let position = surface.point_from_surface_coords(position); - GlobalVertex::from_position(position) + ) -> Self { + self.position = Some(surface.point_from_surface_coords(position)); + self } /// Build a full [`GlobalVertex`] diff --git a/crates/fj-kernel/src/partial/vertex.rs b/crates/fj-kernel/src/partial/vertex.rs index 0ce000abd..33fc6b622 100644 --- a/crates/fj-kernel/src/partial/vertex.rs +++ b/crates/fj-kernel/src/partial/vertex.rs @@ -141,7 +141,8 @@ impl PartialSurfaceVertex { let global_form = self.global_form.unwrap_or_else(|| { GlobalVertex::builder() - .build_from_surface_and_position(&surface, position) + .from_surface_and_position(&surface, position) + .build() }); SurfaceVertex::new(position, surface, global_form) From aa8de0520d87f41bee849f9d0bf9ce7fe6be9b61 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 22 Sep 2022 14:16:01 +0200 Subject: [PATCH 20/26] Replace `GlobalVertexBuilder` method --- crates/fj-kernel/src/builder/edge.rs | 3 ++- crates/fj-kernel/src/builder/vertex.rs | 5 ++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/fj-kernel/src/builder/edge.rs b/crates/fj-kernel/src/builder/edge.rs index 812df9658..3d7c1791e 100644 --- a/crates/fj-kernel/src/builder/edge.rs +++ b/crates/fj-kernel/src/builder/edge.rs @@ -61,7 +61,8 @@ impl<'a> HalfEdgeBuilder<'a> { [Scalar::ZERO, Scalar::TAU].map(|coord| Point::from([coord])); let global_vertex = GlobalVertex::builder() - .build_from_curve_and_position(&curve, a_curve); + .from_curve_and_position(&curve, a_curve) + .build(); let surface_vertices = [a_curve, b_curve].map(|point_curve| { let point_surface = diff --git a/crates/fj-kernel/src/builder/vertex.rs b/crates/fj-kernel/src/builder/vertex.rs index 42a22d180..da9a9804c 100644 --- a/crates/fj-kernel/src/builder/vertex.rs +++ b/crates/fj-kernel/src/builder/vertex.rs @@ -19,14 +19,13 @@ impl GlobalVertexBuilder { } /// Build a [`GlobalVertex`] from a curve and a position on that curve - pub fn build_from_curve_and_position( + pub fn from_curve_and_position( self, curve: &Curve, position: impl Into>, - ) -> GlobalVertex { + ) -> Self { let position_surface = curve.path().point_from_path_coords(position); self.from_surface_and_position(curve.surface(), position_surface) - .build() } /// Build a [`GlobalVertex`] from a surface and a position on that surface From f46edfc45ab7dd290902ba061c6e8196c6d333a0 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 22 Sep 2022 14:16:52 +0200 Subject: [PATCH 21/26] Rename `GlobalVertexBuilder` --- crates/fj-kernel/src/builder/mod.rs | 2 +- crates/fj-kernel/src/builder/vertex.rs | 4 ++-- crates/fj-kernel/src/objects/vertex.rs | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/crates/fj-kernel/src/builder/mod.rs b/crates/fj-kernel/src/builder/mod.rs index 688b09087..ae45ffc5a 100644 --- a/crates/fj-kernel/src/builder/mod.rs +++ b/crates/fj-kernel/src/builder/mod.rs @@ -17,5 +17,5 @@ pub use self::{ shell::ShellBuilder, sketch::SketchBuilder, solid::SolidBuilder, - vertex::GlobalVertexBuilder, + vertex::PartialGlobalVertex, }; diff --git a/crates/fj-kernel/src/builder/vertex.rs b/crates/fj-kernel/src/builder/vertex.rs index da9a9804c..775755869 100644 --- a/crates/fj-kernel/src/builder/vertex.rs +++ b/crates/fj-kernel/src/builder/vertex.rs @@ -6,12 +6,12 @@ use crate::objects::{Curve, GlobalVertex, Surface}; /// /// Also see [`GlobalVertex::builder`]. #[derive(Default)] -pub struct GlobalVertexBuilder { +pub struct PartialGlobalVertex { /// The position of the [`GlobalVertex`] pub position: Option>, } -impl GlobalVertexBuilder { +impl PartialGlobalVertex { /// Provide a position pub fn with_position(mut self, position: impl Into>) -> Self { self.position = Some(position.into()); diff --git a/crates/fj-kernel/src/objects/vertex.rs b/crates/fj-kernel/src/objects/vertex.rs index bde10ec12..1a3ca9d06 100644 --- a/crates/fj-kernel/src/objects/vertex.rs +++ b/crates/fj-kernel/src/objects/vertex.rs @@ -2,7 +2,7 @@ use fj_math::Point; use pretty_assertions::assert_eq; use crate::{ - builder::GlobalVertexBuilder, + builder::PartialGlobalVertex, partial::{PartialSurfaceVertex, PartialVertex}, }; @@ -148,9 +148,9 @@ pub struct GlobalVertex { } impl GlobalVertex { - /// Build a `GlobalVertex` using [`GlobalVertexBuilder`] - pub fn builder() -> GlobalVertexBuilder { - GlobalVertexBuilder::default() + /// Build a `GlobalVertex` using [`PartialGlobalVertex`] + pub fn builder() -> PartialGlobalVertex { + PartialGlobalVertex::default() } /// Construct a `GlobalVertex` from a point From e7649d2470a3bdddf2160c828163338d54e38323 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 22 Sep 2022 14:19:09 +0200 Subject: [PATCH 22/26] Rename `GlobalVertex::builder` --- crates/fj-kernel/src/builder/edge.rs | 4 ++-- crates/fj-kernel/src/builder/vertex.rs | 2 +- crates/fj-kernel/src/objects/vertex.rs | 2 +- crates/fj-kernel/src/partial/vertex.rs | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/crates/fj-kernel/src/builder/edge.rs b/crates/fj-kernel/src/builder/edge.rs index 3d7c1791e..335cb50a6 100644 --- a/crates/fj-kernel/src/builder/edge.rs +++ b/crates/fj-kernel/src/builder/edge.rs @@ -60,7 +60,7 @@ impl<'a> HalfEdgeBuilder<'a> { let [a_curve, b_curve] = [Scalar::ZERO, Scalar::TAU].map(|coord| Point::from([coord])); - let global_vertex = GlobalVertex::builder() + let global_vertex = GlobalVertex::partial() .from_curve_and_position(&curve, a_curve) .build(); @@ -99,7 +99,7 @@ impl<'a> HalfEdgeBuilder<'a> { let points = points.map(Into::into); let global_vertices = points.map(|position| { - GlobalVertex::builder() + GlobalVertex::partial() .from_surface_and_position(&self.surface, position) .build() }); diff --git a/crates/fj-kernel/src/builder/vertex.rs b/crates/fj-kernel/src/builder/vertex.rs index 775755869..3631e974a 100644 --- a/crates/fj-kernel/src/builder/vertex.rs +++ b/crates/fj-kernel/src/builder/vertex.rs @@ -4,7 +4,7 @@ use crate::objects::{Curve, GlobalVertex, Surface}; /// API for building a [`GlobalVertex`] /// -/// Also see [`GlobalVertex::builder`]. +/// Also see [`GlobalVertex::partial`]. #[derive(Default)] pub struct PartialGlobalVertex { /// The position of the [`GlobalVertex`] diff --git a/crates/fj-kernel/src/objects/vertex.rs b/crates/fj-kernel/src/objects/vertex.rs index 1a3ca9d06..53a629577 100644 --- a/crates/fj-kernel/src/objects/vertex.rs +++ b/crates/fj-kernel/src/objects/vertex.rs @@ -149,7 +149,7 @@ pub struct GlobalVertex { impl GlobalVertex { /// Build a `GlobalVertex` using [`PartialGlobalVertex`] - pub fn builder() -> PartialGlobalVertex { + pub fn partial() -> PartialGlobalVertex { PartialGlobalVertex::default() } diff --git a/crates/fj-kernel/src/partial/vertex.rs b/crates/fj-kernel/src/partial/vertex.rs index 33fc6b622..0788b96d3 100644 --- a/crates/fj-kernel/src/partial/vertex.rs +++ b/crates/fj-kernel/src/partial/vertex.rs @@ -140,7 +140,7 @@ impl PartialSurfaceVertex { .expect("Can't build `SurfaceVertex` without `Surface`"); let global_form = self.global_form.unwrap_or_else(|| { - GlobalVertex::builder() + GlobalVertex::partial() .from_surface_and_position(&surface, position) .build() }); From 3aa041ad65217af7ddce48fb22db6360e582fba6 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 22 Sep 2022 14:22:02 +0200 Subject: [PATCH 23/26] Update documentation of `PartialGlobalVertex` --- crates/fj-kernel/src/builder/vertex.rs | 14 ++++++++------ crates/fj-kernel/src/objects/vertex.rs | 5 ++++- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/crates/fj-kernel/src/builder/vertex.rs b/crates/fj-kernel/src/builder/vertex.rs index 3631e974a..fc9dd98e8 100644 --- a/crates/fj-kernel/src/builder/vertex.rs +++ b/crates/fj-kernel/src/builder/vertex.rs @@ -2,23 +2,25 @@ use fj_math::Point; use crate::objects::{Curve, GlobalVertex, Surface}; -/// API for building a [`GlobalVertex`] +/// A partial [`GlobalVertex`] /// -/// Also see [`GlobalVertex::partial`]. +/// See [`crate::partial`] for more information. #[derive(Default)] pub struct PartialGlobalVertex { /// The position of the [`GlobalVertex`] + /// + /// Must be provided before [`PartialGlobalVertex::build`] is called. pub position: Option>, } impl PartialGlobalVertex { - /// Provide a position + /// Provide a position for the partial global vertex pub fn with_position(mut self, position: impl Into>) -> Self { self.position = Some(position.into()); self } - /// Build a [`GlobalVertex`] from a curve and a position on that curve + /// Update partial global vertex from the given curve and position on it pub fn from_curve_and_position( self, curve: &Curve, @@ -28,7 +30,7 @@ impl PartialGlobalVertex { self.from_surface_and_position(curve.surface(), position_surface) } - /// Build a [`GlobalVertex`] from a surface and a position on that surface + /// Update partial global vertex from the given surface and position on it pub fn from_surface_and_position( mut self, surface: &Surface, @@ -38,7 +40,7 @@ impl PartialGlobalVertex { self } - /// Build a full [`GlobalVertex`] + /// Build a full [`GlobalVertex`] from the partial global vertex pub fn build(self) -> GlobalVertex { let position = self .position diff --git a/crates/fj-kernel/src/objects/vertex.rs b/crates/fj-kernel/src/objects/vertex.rs index 53a629577..39e0e4d55 100644 --- a/crates/fj-kernel/src/objects/vertex.rs +++ b/crates/fj-kernel/src/objects/vertex.rs @@ -148,7 +148,10 @@ pub struct GlobalVertex { } impl GlobalVertex { - /// Build a `GlobalVertex` using [`PartialGlobalVertex`] + /// Create a [`PartialGlobalVertex`] + /// + /// This function exists just for convenience, and will just return a + /// default [`PartialGlobalVertex`]. pub fn partial() -> PartialGlobalVertex { PartialGlobalVertex::default() } From c16c5db713ba3706dec028a4a4185f1ade3e3ef8 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 22 Sep 2022 14:22:23 +0200 Subject: [PATCH 24/26] Update doc comment --- crates/fj-kernel/src/objects/vertex.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/fj-kernel/src/objects/vertex.rs b/crates/fj-kernel/src/objects/vertex.rs index 39e0e4d55..5c86aa018 100644 --- a/crates/fj-kernel/src/objects/vertex.rs +++ b/crates/fj-kernel/src/objects/vertex.rs @@ -156,7 +156,7 @@ impl GlobalVertex { PartialGlobalVertex::default() } - /// Construct a `GlobalVertex` from a point + /// Construct a `GlobalVertex` from a position pub fn from_position(position: impl Into>) -> Self { let position = position.into(); Self { position } From b7b3671fef33421dd85632abab2fb8f0cb84f186 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 22 Sep 2022 14:24:09 +0200 Subject: [PATCH 25/26] Move `PartialGlobalVertex` to `partial` module --- crates/fj-kernel/src/builder/mod.rs | 2 - crates/fj-kernel/src/builder/vertex.rs | 51 -------------------------- crates/fj-kernel/src/objects/vertex.rs | 5 +-- crates/fj-kernel/src/partial/mod.rs | 4 +- crates/fj-kernel/src/partial/vertex.rs | 48 ++++++++++++++++++++++++ 5 files changed, 53 insertions(+), 57 deletions(-) delete mode 100644 crates/fj-kernel/src/builder/vertex.rs diff --git a/crates/fj-kernel/src/builder/mod.rs b/crates/fj-kernel/src/builder/mod.rs index ae45ffc5a..680d3fff0 100644 --- a/crates/fj-kernel/src/builder/mod.rs +++ b/crates/fj-kernel/src/builder/mod.rs @@ -7,7 +7,6 @@ mod face; mod shell; mod sketch; mod solid; -mod vertex; pub use self::{ curve::{CurveBuilder, GlobalCurveBuilder}, @@ -17,5 +16,4 @@ pub use self::{ shell::ShellBuilder, sketch::SketchBuilder, solid::SolidBuilder, - vertex::PartialGlobalVertex, }; diff --git a/crates/fj-kernel/src/builder/vertex.rs b/crates/fj-kernel/src/builder/vertex.rs deleted file mode 100644 index fc9dd98e8..000000000 --- a/crates/fj-kernel/src/builder/vertex.rs +++ /dev/null @@ -1,51 +0,0 @@ -use fj_math::Point; - -use crate::objects::{Curve, GlobalVertex, Surface}; - -/// A partial [`GlobalVertex`] -/// -/// See [`crate::partial`] for more information. -#[derive(Default)] -pub struct PartialGlobalVertex { - /// The position of the [`GlobalVertex`] - /// - /// Must be provided before [`PartialGlobalVertex::build`] is called. - pub position: Option>, -} - -impl PartialGlobalVertex { - /// Provide a position for the partial global vertex - pub fn with_position(mut self, position: impl Into>) -> Self { - self.position = Some(position.into()); - self - } - - /// Update partial global vertex from the given curve and position on it - pub fn from_curve_and_position( - self, - curve: &Curve, - position: impl Into>, - ) -> Self { - let position_surface = curve.path().point_from_path_coords(position); - self.from_surface_and_position(curve.surface(), position_surface) - } - - /// Update partial global vertex from the given surface and position on it - pub fn from_surface_and_position( - mut self, - surface: &Surface, - position: impl Into>, - ) -> Self { - self.position = Some(surface.point_from_surface_coords(position)); - self - } - - /// Build a full [`GlobalVertex`] from the partial global vertex - pub fn build(self) -> GlobalVertex { - let position = self - .position - .expect("Can't build a `GlobalVertex` without a position"); - - GlobalVertex::from_position(position) - } -} diff --git a/crates/fj-kernel/src/objects/vertex.rs b/crates/fj-kernel/src/objects/vertex.rs index 5c86aa018..19710976f 100644 --- a/crates/fj-kernel/src/objects/vertex.rs +++ b/crates/fj-kernel/src/objects/vertex.rs @@ -1,9 +1,8 @@ use fj_math::Point; use pretty_assertions::assert_eq; -use crate::{ - builder::PartialGlobalVertex, - partial::{PartialSurfaceVertex, PartialVertex}, +use crate::partial::{ + PartialGlobalVertex, PartialSurfaceVertex, PartialVertex, }; use super::{Curve, Surface}; diff --git a/crates/fj-kernel/src/partial/mod.rs b/crates/fj-kernel/src/partial/mod.rs index d6ea119a6..ccab2ca10 100644 --- a/crates/fj-kernel/src/partial/mod.rs +++ b/crates/fj-kernel/src/partial/mod.rs @@ -26,4 +26,6 @@ mod vertex; -pub use self::vertex::{PartialSurfaceVertex, PartialVertex}; +pub use self::vertex::{ + PartialGlobalVertex, PartialSurfaceVertex, PartialVertex, +}; diff --git a/crates/fj-kernel/src/partial/vertex.rs b/crates/fj-kernel/src/partial/vertex.rs index 0788b96d3..80f61cfc0 100644 --- a/crates/fj-kernel/src/partial/vertex.rs +++ b/crates/fj-kernel/src/partial/vertex.rs @@ -148,3 +148,51 @@ impl PartialSurfaceVertex { SurfaceVertex::new(position, surface, global_form) } } + +/// A partial [`GlobalVertex`] +/// +/// See [`crate::partial`] for more information. +#[derive(Default)] +pub struct PartialGlobalVertex { + /// The position of the [`GlobalVertex`] + /// + /// Must be provided before [`PartialGlobalVertex::build`] is called. + pub position: Option>, +} + +impl PartialGlobalVertex { + /// Provide a position for the partial global vertex + pub fn with_position(mut self, position: impl Into>) -> Self { + self.position = Some(position.into()); + self + } + + /// Update partial global vertex from the given curve and position on it + pub fn from_curve_and_position( + self, + curve: &Curve, + position: impl Into>, + ) -> Self { + let position_surface = curve.path().point_from_path_coords(position); + self.from_surface_and_position(curve.surface(), position_surface) + } + + /// Update partial global vertex from the given surface and position on it + pub fn from_surface_and_position( + mut self, + surface: &Surface, + position: impl Into>, + ) -> Self { + self.position = Some(surface.point_from_surface_coords(position)); + self + } + + /// Build a full [`GlobalVertex`] from the partial global vertex + pub fn build(self) -> GlobalVertex { + let position = self + .position + .expect("Can't build a `GlobalVertex` without a position"); + + GlobalVertex::from_position(position) + } +} From 1f62fa61eb625f9968a332dbec4787d8c1d1e874 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 22 Sep 2022 14:25:56 +0200 Subject: [PATCH 26/26] Update doc comment --- crates/fj-kernel/src/partial/mod.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/crates/fj-kernel/src/partial/mod.rs b/crates/fj-kernel/src/partial/mod.rs index ccab2ca10..70f138d6a 100644 --- a/crates/fj-kernel/src/partial/mod.rs +++ b/crates/fj-kernel/src/partial/mod.rs @@ -18,8 +18,9 @@ //! convenient and readable way to construct a partial object. //! - Partial object structs have `with_*` methods to provide values for each of //! their fields. -//! - Partial object structs may have `as_*` methods, if one or more of their -//! fields can be initialized by providing some alternative data. +//! - Partial object structs may have other methods with prefixes like `as_*`, +//! `from_*`, or similar, if one or more of their fields can be initialized by +//! providing alternative data. //! - Partial object structs have a `build` method to build a full object. //! - All `with_*`, `as_*`, and `build` methods can be chained, to provide a //! convenient API.