Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Curve constructors for surface axes #690

Merged
merged 2 commits into from
Jun 13, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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