Skip to content

Commit

Permalink
WIP Add support for swept surfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
hannobraun committed Feb 14, 2022
1 parent 86ff48e commit 03a3798
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/kernel/geometry/surfaces/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
pub mod plane;
pub mod swept;

pub use self::plane::Plane;
pub use self::{plane::Plane, swept::Swept};

use nalgebra::vector;
use parry3d_f64::math::Isometry;
Expand All @@ -14,6 +15,11 @@ use super::points::SurfacePoint;
pub enum Surface {
/// A plane
Plane(Plane),

/// A swept curve
// TASK: Un-suppress warning.
#[allow(unused)]
Swept(Swept),
}

impl Surface {
Expand All @@ -31,13 +37,15 @@ impl Surface {
pub fn transform(self, transform: &Isometry<f64>) -> Self {
match self {
Self::Plane(surface) => Self::Plane(surface.transform(transform)),
Self::Swept(surface) => Self::Swept(surface.transform(transform)),
}
}

/// Convert a point in model coordinates to surface coordinates
pub fn point_model_to_surface(&self, point_3d: Point<3>) -> SurfacePoint {
let point_2d = match self {
Self::Plane(surface) => surface.point_model_to_surface(point_3d),
Self::Swept(surface) => surface.point_model_to_surface(point_3d),
};

SurfacePoint {
Expand All @@ -50,13 +58,15 @@ impl Surface {
pub fn point_surface_to_model(&self, point: &Point<2>) -> Point<3> {
match self {
Self::Plane(surface) => surface.point_surface_to_model(point),
Self::Swept(surface) => surface.point_surface_to_model(point),
}
}

/// Convert a vector in surface coordinates to model coordinates
pub fn vector_surface_to_model(&self, vector: &Vector<2>) -> Vector<3> {
match self {
Self::Plane(surface) => surface.vector_surface_to_model(vector),
Self::Swept(surface) => surface.vector_surface_to_model(vector),
}
}
}
47 changes: 47 additions & 0 deletions src/kernel/geometry/surfaces/swept.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
use parry3d_f64::math::Isometry;

use crate::{
kernel::geometry::Curve,
math::{Point, Vector},
};

/// A surface that was swept from a curve
#[derive(Clone, Debug, PartialEq)]
pub struct Swept {
/// The curve that this surface was swept from
pub curve: Curve,

/// The path that the curve was swept along
///
/// Currently, only sweeps along the z-axis are supported.
pub path: Vector<1>,
}

impl Swept {
/// Transform the surface
#[must_use]
pub fn transform(self, _transform: &Isometry<f64>) -> Self {
// TASK: Implement.
todo!()
}

/// Convert a point in model coordinates to surface coordinates
pub fn point_model_to_surface(&self, _point: Point<3>) -> Point<2> {
// TASK: Implement.
todo!()
}

/// Convert a point in surface coordinates to model coordinates
pub fn point_surface_to_model(&self, _point: &Point<2>) -> Point<3> {
// TASK: Implement.
todo!()
}

/// Convert a vector in surface coordinates to model coordinates
pub fn vector_surface_to_model(&self, _vector: &Vector<2>) -> Vector<3> {
// TASK: Implement.
todo!()
}
}

// TASK: Add test suite.

0 comments on commit 03a3798

Please sign in to comment.