-
-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #904 from hannobraun/curve
Add builder API for `Curve` and `GlobalCurve`
- Loading branch information
Showing
6 changed files
with
113 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
use fj_math::{Line, Point, Vector}; | ||
|
||
use crate::objects::{Curve, CurveKind, GlobalCurve, Surface}; | ||
|
||
/// API for building a [`Curve`] | ||
pub struct CurveBuilder { | ||
surface: Surface, | ||
} | ||
|
||
impl CurveBuilder { | ||
/// Construct a new instance of [`CurveBuilder`] | ||
/// | ||
/// Also see [`Curve::build`]. | ||
pub fn new(surface: Surface) -> Self { | ||
Self { surface } | ||
} | ||
|
||
/// Create a line that represents the u-axis on the surface | ||
pub fn u_axis(&self) -> Curve { | ||
let a = Point::origin(); | ||
let b = a + Vector::unit_u(); | ||
|
||
self.line_from_points([a, b]) | ||
} | ||
|
||
/// Create a line that represents the v-axis on the surface | ||
pub fn v_axis(&self) -> Curve { | ||
let a = Point::origin(); | ||
let b = a + Vector::unit_v(); | ||
|
||
self.line_from_points([a, b]) | ||
} | ||
|
||
/// Create a line from the given points | ||
pub fn line_from_points(&self, points: [impl Into<Point<2>>; 2]) -> Curve { | ||
let points = points.map(Into::into); | ||
|
||
let local = Line::from_points(points); | ||
let global = Line::from_points( | ||
points.map(|point| self.surface.point_from_surface_coords(point)), | ||
); | ||
|
||
Curve::new( | ||
CurveKind::Line(local), | ||
GlobalCurve::from_kind(CurveKind::Line(global)), | ||
) | ||
} | ||
} | ||
|
||
/// API for building a [`GlobalCurve`] | ||
pub struct GlobalCurveBuilder; | ||
|
||
impl GlobalCurveBuilder { | ||
/// Create a line that represents the x-axis | ||
pub fn x_axis(&self) -> GlobalCurve { | ||
GlobalCurve::from_kind(CurveKind::x_axis()) | ||
} | ||
|
||
/// Create a line that represents the y-axis | ||
pub fn y_axis(&self) -> GlobalCurve { | ||
GlobalCurve::from_kind(CurveKind::y_axis()) | ||
} | ||
|
||
/// Create a line that represents the z-axis | ||
pub fn z_axis(&self) -> GlobalCurve { | ||
GlobalCurve::from_kind(CurveKind::z_axis()) | ||
} | ||
|
||
/// Create a line from the given points | ||
pub fn line_from_points( | ||
&self, | ||
points: [impl Into<Point<3>>; 2], | ||
) -> GlobalCurve { | ||
let line = Line::from_points(points); | ||
GlobalCurve::from_kind(CurveKind::Line(line)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters