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

Clean up module structure in kernel::geometry #183

Merged
merged 3 commits into from
Feb 14, 2022
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions src/kernel/geometry/curves/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
mod circle;
mod line;

use parry3d_f64::math::Isometry;

pub use self::{circle::Circle, line::Line};

use parry3d_f64::math::Isometry;

use crate::math::Point;

/// A one-dimensional shape
Expand Down
64 changes: 64 additions & 0 deletions src/kernel/geometry/surfaces/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
pub mod plane;

pub use self::plane::Plane;

use nalgebra::vector;
use parry3d_f64::math::Isometry;

use crate::math::{Point, Vector};

use super::points::SurfacePoint;

/// A two-dimensional shape
#[derive(Clone, Debug, PartialEq)]
pub enum Surface {
/// A plane
Plane(Plane),
}

impl Surface {
/// Construct a `Surface` that represents the x-y plane
pub fn x_y_plane() -> Self {
Self::Plane(Plane {
origin: Point::origin(),
u: vector![1., 0., 0.],
v: vector![0., 1., 0.],
})
}

/// Transform the surface
#[must_use]
pub fn transform(self, transform: &Isometry<f64>) -> Self {
match self {
Self::Plane(plane) => Self::Plane(plane.transform(transform)),
}
}

/// Convert a point in model coordinates to surface coordinates
///
/// Returns an error, if the provided point is not in the surface.
pub fn point_model_to_surface(&self, point_3d: Point<3>) -> SurfacePoint {
let point_2d = match self {
Self::Plane(plane) => plane.point_model_to_surface(point_3d),
};

SurfacePoint {
value: point_2d,
from: point_3d,
}
}

/// Convert a point in surface coordinates to model coordinates
pub fn point_surface_to_model(&self, point: &Point<2>) -> Point<3> {
match self {
Self::Plane(plane) => plane.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(plane) => plane.vector_surface_to_model(vector),
}
}
}
Original file line number Diff line number Diff line change
@@ -1,64 +1,8 @@
use nalgebra::{point, vector};
use nalgebra::point;
use parry3d_f64::math::Isometry;

use crate::math::{Point, Vector};

use super::points::SurfacePoint;

/// A two-dimensional shape
#[derive(Clone, Debug, PartialEq)]
pub enum Surface {
/// A plane
Plane(Plane),
}

impl Surface {
/// Construct a `Surface` that represents the x-y plane
pub fn x_y_plane() -> Self {
Self::Plane(Plane {
origin: Point::origin(),
u: vector![1., 0., 0.],
v: vector![0., 1., 0.],
})
}

/// Transform the surface
#[must_use]
pub fn transform(self, transform: &Isometry<f64>) -> Self {
match self {
Self::Plane(plane) => Self::Plane(plane.transform(transform)),
}
}

/// Convert a point in model coordinates to surface coordinates
///
/// Returns an error, if the provided point is not in the surface.
pub fn point_model_to_surface(&self, point_3d: Point<3>) -> SurfacePoint {
let point_2d = match self {
Self::Plane(plane) => plane.point_model_to_surface(point_3d),
};

SurfacePoint {
value: point_2d,
from: point_3d,
}
}

/// Convert a point in surface coordinates to model coordinates
pub fn point_surface_to_model(&self, point: &Point<2>) -> Point<3> {
match self {
Self::Plane(plane) => plane.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(plane) => plane.vector_surface_to_model(vector),
}
}
}

/// A plane
///
/// For the time being, only planes parallel to the x-y plane are supported.
Expand Down