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 Vertex #1076

Merged
merged 2 commits into from
Sep 12, 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 @@ -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