Skip to content

Commit

Permalink
Merge pull request #1076 from hannobraun/builder
Browse files Browse the repository at this point in the history
Add builder API for `Vertex
  • Loading branch information
hannobraun authored Sep 12, 2022
2 parents e7f71e0 + 9c2607b commit 5d556f5
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 2 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 @@ -18,7 +18,7 @@ impl HalfEdgeBuilder {
Self { surface }
}

/// Create a circle from the given radius
/// Build a circle from the given radius
pub fn circle_from_radius(&self, radius: Scalar) -> HalfEdge {
let curve = {
let local = CurveKind::Circle(Circle::new(
Expand Down Expand Up @@ -68,7 +68,7 @@ impl HalfEdgeBuilder {
HalfEdge::from_curve_and_vertices(curve, vertices)
}

/// Create a line segment from two points
/// Build a line segment from two points
pub fn line_segment_from_points(
&self,
points: [impl Into<Point<2>>; 2],
Expand Down
2 changes: 2 additions & 0 deletions crates/fj-kernel/src/builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ mod face;
mod shell;
mod sketch;
mod solid;
mod vertex;

pub use self::{
curve::{CurveBuilder, GlobalCurveBuilder},
Expand All @@ -16,4 +17,5 @@ pub use self::{
shell::ShellBuilder,
sketch::SketchBuilder,
solid::SolidBuilder,
vertex::VertexBuilder,
};
37 changes: 37 additions & 0 deletions crates/fj-kernel/src/builder/vertex.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
use fj_math::Point;

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

/// API for building a [`Vertex`]
pub struct VertexBuilder {
curve: Curve,
}

impl VertexBuilder {
/// Construct a new instance of `VertexBuilder`
///
/// Also see [`Vertex::build`].
pub fn new(curve: Curve) -> Self {
Self { curve }
}

/// Build a vertex from a curve position
pub fn from_point(&self, point: impl Into<Point<1>>) -> Vertex {
let point = point.into();
let &surface = self.curve.surface();

let global_form = GlobalVertex::from_position(
self.curve
.global_form()
.kind()
.point_from_curve_coords(point),
);
let surface_form = SurfaceVertex::new(
self.curve.kind().point_from_curve_coords(point),
surface,
global_form,
);

Vertex::new([0.], self.curve, surface_form, global_form)
}
}
7 changes: 7 additions & 0 deletions crates/fj-kernel/src/objects/vertex.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use fj_math::Point;
use pretty_assertions::assert_eq;

use crate::builder::VertexBuilder;

use super::{Curve, Surface};

/// A vertex
Expand All @@ -17,6 +19,11 @@ pub struct Vertex {
}

impl Vertex {
/// Build a vertex using [`VertexBuilder`]
pub fn build(curve: Curve) -> VertexBuilder {
VertexBuilder::new(curve)
}

/// Construct an instance of `Vertex`
///
/// Panics, if `curve` and `surface_form` are not defined on the same
Expand Down

0 comments on commit 5d556f5

Please sign in to comment.