Skip to content

Commit

Permalink
Merge pull request #1445 from hannobraun/builder
Browse files Browse the repository at this point in the history
Continue cleanup of builder API
  • Loading branch information
hannobraun authored Dec 12, 2022
2 parents e9bebab + 58e722c commit bd2094b
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 143 deletions.
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

0 comments on commit bd2094b

Please sign in to comment.