Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add builder API for GlobalVertex #1113

Merged
merged 4 commits into from
Sep 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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