Skip to content

Commit

Permalink
Merge pull request #1113 from hannobraun/builder
Browse files Browse the repository at this point in the history
Add builder API for `GlobalVertex`
  • Loading branch information
hannobraun authored Sep 19, 2022
2 parents 7812594 + ee72b81 commit 81145d7
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 11 deletions.
4 changes: 2 additions & 2 deletions crates/fj-kernel/src/builder/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ impl<'a> HalfEdgeBuilder<'a> {
let points = points.map(Into::into);

let global_vertices = points.map(|position| {
let position = self.surface.point_from_surface_coords(position);
GlobalVertex::from_position(position)
GlobalVertex::build()
.from_surface_and_position(&self.surface, position)
});

let surface_vertices = {
Expand Down
2 changes: 1 addition & 1 deletion crates/fj-kernel/src/builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ pub use self::{
shell::ShellBuilder,
sketch::SketchBuilder,
solid::SolidBuilder,
vertex::VertexBuilder,
vertex::{GlobalVertexBuilder, VertexBuilder},
};
36 changes: 29 additions & 7 deletions crates/fj-kernel/src/builder/vertex.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use fj_math::Point;

use crate::objects::{Curve, GlobalVertex, SurfaceVertex, Vertex};
use crate::objects::{Curve, GlobalVertex, Surface, SurfaceVertex, Vertex};

/// API for building a [`Vertex`]
pub struct VertexBuilder {
Expand All @@ -20,12 +20,9 @@ impl VertexBuilder {
let point = point.into();
let &surface = self.curve.surface();

let global_form = GlobalVertex::from_position(
self.curve
.global_form()
.path()
.point_from_path_coords(point),
);
let global_form =
GlobalVertex::build().from_curve_and_position(&self.curve, point);

let surface_form = SurfaceVertex::new(
self.curve.path().point_from_path_coords(point),
surface,
Expand All @@ -35,3 +32,28 @@ impl VertexBuilder {
Vertex::new([0.], self.curve.clone(), surface_form, global_form)
}
}

/// API for building a [`GlobalVertex`]
pub struct GlobalVertexBuilder;

impl GlobalVertexBuilder {
/// Build a [`GlobalVertex`] from a curve and a position on that curve
pub fn from_curve_and_position(
&self,
curve: &Curve,
position: impl Into<Point<1>>,
) -> GlobalVertex {
let position_surface = curve.path().point_from_path_coords(position);
self.from_surface_and_position(curve.surface(), position_surface)
}

/// Build a [`GlobalVertex`] from a surface and a position on that surface
pub fn from_surface_and_position(
&self,
surface: &Surface,
position: impl Into<Point<2>>,
) -> GlobalVertex {
let position = surface.point_from_surface_coords(position);
GlobalVertex::from_position(position)
}
}
7 changes: 6 additions & 1 deletion crates/fj-kernel/src/objects/vertex.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use fj_math::Point;
use pretty_assertions::assert_eq;

use crate::builder::VertexBuilder;
use crate::builder::{GlobalVertexBuilder, VertexBuilder};

use super::{Curve, Surface};

Expand Down Expand Up @@ -134,6 +134,11 @@ pub struct GlobalVertex {
}

impl GlobalVertex {
/// Build a `GlobalVertex` using [`GlobalVertexBuilder`]
pub fn build() -> GlobalVertexBuilder {
GlobalVertexBuilder
}

/// Construct a `GlobalVertex` from a point
pub fn from_position(position: impl Into<Point<3>>) -> Self {
let position = position.into();
Expand Down

0 comments on commit 81145d7

Please sign in to comment.