Skip to content

Commit

Permalink
Merge pull request #1119 from hannobraun/builder
Browse files Browse the repository at this point in the history
Fix inconsistencies in builder API
  • Loading branch information
hannobraun authored Sep 20, 2022
2 parents ac22854 + bd15e19 commit cef2c34
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 20 deletions.
4 changes: 2 additions & 2 deletions crates/fj-kernel/src/algorithms/sweep/vertex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ impl Sweep for GlobalVertex {
let a = self;
let b = GlobalVertex::from_position(self.position() + path.into());

let curve = GlobalCurve::build(stores)
let curve = GlobalCurve::builder(stores)
.line_from_points([a.position(), b.position()]);

GlobalEdge::new(curve, [a, b])
Expand Down Expand Up @@ -178,7 +178,7 @@ mod tests {
.sweep([0., 0., 1.], &stores);

let expected_edge = GlobalEdge::new(
GlobalCurve::build(&stores).z_axis(),
GlobalCurve::builder(&stores).z_axis(),
[[0., 0., 0.], [0., 0., 1.]].map(GlobalVertex::from_position),
);
assert_eq!(edge, expected_edge);
Expand Down
14 changes: 5 additions & 9 deletions crates/fj-kernel/src/builder/curve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl<'a> CurveBuilder<'a> {

let path = SurfacePath::circle_from_radius(radius);
let global_form =
GlobalCurve::build(self.stores).circle_from_radius(radius);
GlobalCurve::builder(self.stores).circle_from_radius(radius);

Curve::new(self.surface, path, global_form)
}
Expand All @@ -62,18 +62,14 @@ impl<'a> CurveBuilder<'a> {
}

/// API for building a [`GlobalCurve`]
///
/// Also see [`GlobalCurve::builder`].
pub struct GlobalCurveBuilder<'a> {
stores: &'a Stores,
/// The stores that the created objects are put in
pub stores: &'a Stores,
}

impl<'a> GlobalCurveBuilder<'a> {
/// Construct a new instance of [`GlobalCurveBuilder`]
///
/// Also see [`GlobalCurve::build`].
pub fn new(stores: &'a Stores) -> Self {
Self { stores }
}

/// Build a line that represents the x-axis
pub fn x_axis(&self) -> Handle<GlobalCurve> {
self.stores
Expand Down
6 changes: 3 additions & 3 deletions crates/fj-kernel/src/builder/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ impl<'a> HalfEdgeBuilder<'a> {
let [a_curve, b_curve] =
[Scalar::ZERO, Scalar::TAU].map(|coord| Point::from([coord]));

let global_vertex =
GlobalVertex::build().from_curve_and_position(&curve, a_curve);
let global_vertex = GlobalVertex::builder()
.from_curve_and_position(&curve, a_curve);

let surface_vertices = [a_curve, b_curve].map(|point_curve| {
let point_surface =
Expand Down Expand Up @@ -65,7 +65,7 @@ impl<'a> HalfEdgeBuilder<'a> {
let points = points.map(Into::into);

let global_vertices = points.map(|position| {
GlobalVertex::build()
GlobalVertex::builder()
.from_surface_and_position(&self.surface, position)
});

Expand Down
4 changes: 3 additions & 1 deletion crates/fj-kernel/src/builder/vertex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ impl VertexBuilder {
let &surface = self.curve.surface();

let global_form =
GlobalVertex::build().from_curve_and_position(&self.curve, point);
GlobalVertex::builder().from_curve_and_position(&self.curve, point);

let surface_form = SurfaceVertex::new(
self.curve.path().point_from_path_coords(point),
Expand All @@ -30,6 +30,8 @@ impl VertexBuilder {
}

/// API for building a [`GlobalVertex`]
///
/// Also see [`GlobalVertex::builder`].
pub struct GlobalVertexBuilder;

impl GlobalVertexBuilder {
Expand Down
2 changes: 1 addition & 1 deletion crates/fj-kernel/src/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ mod tests {
fn global_curve() {
let stores = Stores::new();

let object = GlobalCurve::build(&stores).x_axis();
let object = GlobalCurve::builder(&stores).x_axis();

assert_eq!(0, object.curve_iter().count());
assert_eq!(0, object.cycle_iter().count());
Expand Down
6 changes: 3 additions & 3 deletions crates/fj-kernel/src/objects/curve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ pub struct GlobalCurve {
}

impl GlobalCurve {
/// Build a curve using [`GlobalCurveBuilder`]
pub fn build(stores: &Stores) -> GlobalCurveBuilder {
GlobalCurveBuilder::new(stores)
/// Build a `Curve` using [`GlobalCurveBuilder`]
pub fn builder(stores: &Stores) -> GlobalCurveBuilder {
GlobalCurveBuilder { stores }
}

/// Construct a `GlobalCurve` from the path that defines it
Expand Down
2 changes: 1 addition & 1 deletion crates/fj-kernel/src/objects/vertex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ pub struct GlobalVertex {

impl GlobalVertex {
/// Build a `GlobalVertex` using [`GlobalVertexBuilder`]
pub fn build() -> GlobalVertexBuilder {
pub fn builder() -> GlobalVertexBuilder {
GlobalVertexBuilder
}

Expand Down

0 comments on commit cef2c34

Please sign in to comment.