Skip to content

Commit

Permalink
Merge pull request #690 from hannobraun/curve
Browse files Browse the repository at this point in the history
Add `Curve` constructors for surface axes
  • Loading branch information
hannobraun authored Jun 13, 2022
2 parents cc255d6 + 993415d commit fcbcb5f
Showing 1 changed file with 55 additions and 37 deletions.
92 changes: 55 additions & 37 deletions crates/fj-kernel/src/geometry/curves.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,43 +26,6 @@ pub enum Curve<const D: usize> {
Line(Line<D>),
}

impl Curve<3> {
/// Construct a `Curve` that represents the x-axis
pub fn x_axis() -> Self {
Self::Line(Line {
origin: Point::origin(),
direction: Vector::unit_x(),
})
}

/// Construct a `Curve` that represents the y-axis
pub fn y_axis() -> Self {
Self::Line(Line {
origin: Point::origin(),
direction: Vector::unit_y(),
})
}

/// Construct a `Curve` that represents the z-axis
pub fn z_axis() -> Self {
Self::Line(Line {
origin: Point::origin(),
direction: Vector::unit_z(),
})
}

/// Create a new instance that is transformed by `transform`
#[must_use]
pub fn transform(self, transform: &Transform) -> Self {
match self {
Self::Circle(curve) => {
Self::Circle(transform.transform_circle(&curve))
}
Self::Line(curve) => Self::Line(transform.transform_line(&curve)),
}
}
}

impl<const D: usize> Curve<D> {
/// Access the origin of the curve's coordinate system
pub fn origin(&self) -> Point<D> {
Expand Down Expand Up @@ -129,6 +92,61 @@ impl<const D: usize> Curve<D> {
}
}

impl Curve<2> {
/// Construct a `Curve` that represents the u-axis
pub fn u_axis() -> Self {
Self::Line(Line {
origin: Point::origin(),
direction: Vector::unit_u(),
})
}

/// Construct a `Curve` that represents the v-axis
pub fn v_axis() -> Self {
Self::Line(Line {
origin: Point::origin(),
direction: Vector::unit_v(),
})
}
}

impl Curve<3> {
/// Construct a `Curve` that represents the x-axis
pub fn x_axis() -> Self {
Self::Line(Line {
origin: Point::origin(),
direction: Vector::unit_x(),
})
}

/// Construct a `Curve` that represents the y-axis
pub fn y_axis() -> Self {
Self::Line(Line {
origin: Point::origin(),
direction: Vector::unit_y(),
})
}

/// Construct a `Curve` that represents the z-axis
pub fn z_axis() -> Self {
Self::Line(Line {
origin: Point::origin(),
direction: Vector::unit_z(),
})
}

/// Create a new instance that is transformed by `transform`
#[must_use]
pub fn transform(self, transform: &Transform) -> Self {
match self {
Self::Circle(curve) => {
Self::Circle(transform.transform_circle(&curve))
}
Self::Line(curve) => Self::Line(transform.transform_line(&curve)),
}
}
}

impl<const D: usize> fmt::Display for Curve<D> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Expand Down

0 comments on commit fcbcb5f

Please sign in to comment.