Skip to content

Commit

Permalink
Merge pull request #1117 from hannobraun/builder
Browse files Browse the repository at this point in the history
Simplify builder API
  • Loading branch information
hannobraun authored Sep 20, 2022
2 parents 895ebfa + 15f5116 commit 0e93f78
Show file tree
Hide file tree
Showing 16 changed files with 55 additions and 77 deletions.
16 changes: 7 additions & 9 deletions crates/fj-kernel/src/builder/curve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,17 @@ use crate::{
};

/// API for building a [`Curve`]
///
/// Also see [`Curve::build`].
pub struct CurveBuilder<'a> {
stores: &'a Stores,
surface: Surface,
/// The stores that the created objects are put in
pub stores: &'a Stores,

/// The surface that the [`Curve`] is defined in
pub surface: Surface,
}

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

/// Build a line that represents the u-axis on the surface
pub fn u_axis(&self) -> Curve {
let a = Point::origin();
Expand Down
16 changes: 7 additions & 9 deletions crates/fj-kernel/src/builder/cycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,17 @@ use crate::{
};

/// API for building a [`Cycle`]
///
/// Also see [`Cycle::build`].
pub struct CycleBuilder<'a> {
stores: &'a Stores,
surface: Surface,
/// The stores that the created objects are put in
pub stores: &'a Stores,

/// The surface that the [`Cycle`] is defined in
pub surface: Surface,
}

impl<'a> CycleBuilder<'a> {
/// Construct an instance of `CycleBuilder`
///
/// Also see [`Cycle::build`].
pub fn new(stores: &'a Stores, surface: Surface) -> Self {
Self { stores, surface }
}

/// Create a polygon from a list of points
pub fn polygon_from_points(
&self,
Expand Down
16 changes: 7 additions & 9 deletions crates/fj-kernel/src/builder/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,17 @@ use crate::{
};

/// API for building an [`HalfEdge`]
///
/// Also see [`HalfEdge::build`].
pub struct HalfEdgeBuilder<'a> {
stores: &'a Stores,
surface: Surface,
/// The stores that the created objects are put in
pub stores: &'a Stores,

/// The surface that the [`HalfEdge`] is defined in
pub surface: Surface,
}

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

/// Build a circle from the given radius
pub fn circle_from_radius(&self, radius: impl Into<Scalar>) -> HalfEdge {
let curve =
Expand Down
16 changes: 7 additions & 9 deletions crates/fj-kernel/src/builder/face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,17 @@ use crate::{
};

/// API for building a [`Face`]
///
/// Also see [`Face::build`].
pub struct FaceBuilder<'a> {
stores: &'a Stores,
surface: Surface,
/// The stores that the created objects are put in
pub stores: &'a Stores,

/// The surface that the [`Face`] is defined in
pub surface: Surface,
}

impl<'a> FaceBuilder<'a> {
/// Construct an instance of `FaceBuilder`
///
/// Also see [`Face::build`].
pub fn new(stores: &'a Stores, surface: Surface) -> Self {
Self { stores, surface }
}

/// Construct a polygon from a list of points
pub fn polygon_from_points(
&self,
Expand Down
12 changes: 4 additions & 8 deletions crates/fj-kernel/src/builder/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,14 @@ use crate::{
};

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

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

/// Create a cube from the length of its edges
pub fn cube_from_edge_length(
&self,
Expand Down
16 changes: 7 additions & 9 deletions crates/fj-kernel/src/builder/sketch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,17 @@ use crate::{
};

/// API for building a [`Sketch`]
///
/// Also see [`Sketch::build`].
pub struct SketchBuilder<'a> {
stores: &'a Stores,
surface: Surface,
/// The stores that the created objects are put in
pub stores: &'a Stores,

/// The surface that the [`Sketch`] is defined in
pub surface: Surface,
}

impl<'a> SketchBuilder<'a> {
/// Construct an instance of `SketchBuilder`
///
/// Also see [`Sketch::build`].
pub fn new(stores: &'a Stores, surface: Surface) -> Self {
Self { stores, surface }
}

/// Construct a polygon from a list of points
pub fn polygon_from_points(
&self,
Expand Down
12 changes: 4 additions & 8 deletions crates/fj-kernel/src/builder/solid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,14 @@ use crate::{
};

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

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

/// Create a cube from the length of its edges
pub fn cube_from_edge_length(
&self,
Expand Down
12 changes: 4 additions & 8 deletions crates/fj-kernel/src/builder/vertex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,14 @@ use fj_math::Point;
use crate::objects::{Curve, GlobalVertex, Surface, SurfaceVertex, Vertex};

/// API for building a [`Vertex`]
///
/// Also see [`Vertex::build`].
pub struct VertexBuilder {
curve: Curve,
/// The curve that the [`Vertex`] is defined in
pub 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();
Expand Down
2 changes: 1 addition & 1 deletion crates/fj-kernel/src/objects/curve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub struct Curve {
impl Curve {
/// Build a curve using [`CurveBuilder`]
pub fn build(stores: &Stores, surface: Surface) -> CurveBuilder {
CurveBuilder::new(stores, surface)
CurveBuilder { stores, surface }
}

/// Construct a new instance of `Curve`
Expand Down
2 changes: 1 addition & 1 deletion crates/fj-kernel/src/objects/cycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub struct Cycle {
impl Cycle {
/// Build a cycle using [`CycleBuilder`]
pub fn build(stores: &Stores, surface: Surface) -> CycleBuilder {
CycleBuilder::new(stores, surface)
CycleBuilder { stores, surface }
}

/// Create a new cycle
Expand Down
2 changes: 1 addition & 1 deletion crates/fj-kernel/src/objects/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub struct HalfEdge {
impl HalfEdge {
/// Build a half-edge using [`HalfEdgeBuilder`]
pub fn build(stores: &Stores, surface: Surface) -> HalfEdgeBuilder {
HalfEdgeBuilder::new(stores, surface)
HalfEdgeBuilder { stores, surface }
}

/// Create a new instance of `HalfEdge`
Expand Down
2 changes: 1 addition & 1 deletion crates/fj-kernel/src/objects/face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ pub struct Face {
impl Face {
/// Build a face using [`FaceBuilder`]
pub fn build(stores: &Stores, surface: Surface) -> FaceBuilder {
FaceBuilder::new(stores, surface)
FaceBuilder { stores, surface }
}

/// Construct a new instance of `Face`
Expand Down
2 changes: 1 addition & 1 deletion crates/fj-kernel/src/objects/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub struct Shell {
impl Shell {
/// Build a shell using [`ShellBuilder`]
pub fn build(stores: &Stores) -> ShellBuilder {
ShellBuilder::new(stores)
ShellBuilder { stores }
}

/// Construct an empty instance of `Shell`
Expand Down
2 changes: 1 addition & 1 deletion crates/fj-kernel/src/objects/sketch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub struct Sketch {
impl Sketch {
/// Build a sketch using [`SketchBuilder`]
pub fn build(stores: &Stores, surface: Surface) -> SketchBuilder {
SketchBuilder::new(stores, surface)
SketchBuilder { stores, surface }
}

/// Construct an empty instance of `Sketch`
Expand Down
2 changes: 1 addition & 1 deletion crates/fj-kernel/src/objects/solid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub struct Solid {
impl Solid {
/// Build a solid using [`SolidBuilder`]
pub fn build(stores: &Stores) -> SolidBuilder {
SolidBuilder::new(stores)
SolidBuilder { stores }
}

/// Construct an empty instance of `Solid`
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 @@ -21,7 +21,7 @@ pub struct Vertex {
impl Vertex {
/// Build a vertex using [`VertexBuilder`]
pub fn build(curve: Curve) -> VertexBuilder {
VertexBuilder::new(curve)
VertexBuilder { curve }
}

/// Construct an instance of `Vertex`
Expand Down

0 comments on commit 0e93f78

Please sign in to comment.