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

Continue cleanup of builder API #1445

Merged
merged 17 commits into from
Dec 12, 2022
Merged
30 changes: 8 additions & 22 deletions crates/fj-kernel/src/builder/curve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,52 +5,38 @@ use crate::{geometry::path::SurfacePath, partial::PartialCurve};
/// Builder API for [`PartialCurve`]
pub trait CurveBuilder {
/// Update partial curve to represent the u-axis of the surface it is on
fn update_as_u_axis(&mut self) -> &mut Self;
fn update_as_u_axis(&mut self);

/// Update partial curve to represent the v-axis of the surface it is on
fn update_as_v_axis(&mut self) -> &mut Self;
fn update_as_v_axis(&mut self);

/// Update partial curve to be a circle, from the provided radius
fn update_as_circle_from_radius(
&mut self,
radius: impl Into<Scalar>,
) -> &mut Self;
fn update_as_circle_from_radius(&mut self, radius: impl Into<Scalar>);

/// Update partial curve to be a line, from the provided points
fn update_as_line_from_points(
&mut self,
points: [impl Into<Point<2>>; 2],
) -> &mut Self;
fn update_as_line_from_points(&mut self, points: [impl Into<Point<2>>; 2]);
}

impl CurveBuilder for PartialCurve {
fn update_as_u_axis(&mut self) -> &mut Self {
fn update_as_u_axis(&mut self) {
let a = Point::origin();
let b = a + Vector::unit_u();

self.update_as_line_from_points([a, b])
}

fn update_as_v_axis(&mut self) -> &mut Self {
fn update_as_v_axis(&mut self) {
let a = Point::origin();
let b = a + Vector::unit_v();

self.update_as_line_from_points([a, b])
}

fn update_as_circle_from_radius(
&mut self,
radius: impl Into<Scalar>,
) -> &mut Self {
fn update_as_circle_from_radius(&mut self, radius: impl Into<Scalar>) {
self.path = Some(SurfacePath::circle_from_radius(radius));
self
}

fn update_as_line_from_points(
&mut self,
points: [impl Into<Point<2>>; 2],
) -> &mut Self {
fn update_as_line_from_points(&mut self, points: [impl Into<Point<2>>; 2]) {
self.path = Some(SurfacePath::line_from_points(points));
self
}
}
22 changes: 6 additions & 16 deletions crates/fj-kernel/src/builder/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,21 @@ use super::{CurveBuilder, SurfaceVertexBuilder};
/// Builder API for [`PartialHalfEdge`]
pub trait HalfEdgeBuilder {
/// Update partial half-edge to be a circle, from the given radius
fn update_as_circle_from_radius(
&mut self,
radius: impl Into<Scalar>,
) -> &mut Self;
fn update_as_circle_from_radius(&mut self, radius: impl Into<Scalar>);

/// Update partial half-edge to be a line segment, from the given points
fn update_as_line_segment_from_points(
&mut self,
surface: Partial<Surface>,
points: [impl Into<Point<2>>; 2],
) -> &mut Self;
);

/// Update partial half-edge to be a line segment
fn update_as_line_segment(&mut self) -> &mut Self;
fn update_as_line_segment(&mut self);
}

impl HalfEdgeBuilder for PartialHalfEdge {
fn update_as_circle_from_radius(
&mut self,
radius: impl Into<Scalar>,
) -> &mut Self {
fn update_as_circle_from_radius(&mut self, radius: impl Into<Scalar>) {
let mut curve = self.curve();
curve.write().update_as_circle_from_radius(radius);

Expand Down Expand Up @@ -61,15 +55,13 @@ impl HalfEdgeBuilder for PartialHalfEdge {
let global_vertex = surface_vertex.read().global_form.clone();
self.global_form.write().vertices =
[global_vertex.clone(), global_vertex];

self
}

fn update_as_line_segment_from_points(
&mut self,
surface: Partial<Surface>,
points: [impl Into<Point<2>>; 2],
) -> &mut Self {
) {
for (vertex, point) in self.vertices.each_mut_ext().zip_ext(points) {
let mut vertex = vertex.write();
vertex.curve.write().surface = surface.clone();
Expand All @@ -83,7 +75,7 @@ impl HalfEdgeBuilder for PartialHalfEdge {
self.update_as_line_segment()
}

fn update_as_line_segment(&mut self) -> &mut Self {
fn update_as_line_segment(&mut self) {
let points_surface = self.vertices.each_ref_ext().map(|vertex| {
vertex
.read()
Expand All @@ -103,8 +95,6 @@ impl HalfEdgeBuilder for PartialHalfEdge {
}

self.global_form.write().curve = curve.read().global_form.clone();

self
}
}

Expand Down
Loading