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 Surface::plane_from_points #611

Merged
merged 3 commits into from
May 20, 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
5 changes: 2 additions & 3 deletions crates/fj-kernel/src/algorithms/sweep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ mod tests {

use crate::{
algorithms::Tolerance,
geometry::{Surface, SweptCurve},
geometry::Surface,
shape::{Handle, Shape},
topology::{Cycle, Edge, Face},
};
Expand Down Expand Up @@ -230,8 +230,7 @@ mod tests {

let cycles = shape.insert(Cycle::new(vec![ab, bc, ca]))?;

let surface =
Surface::SweptCurve(SweptCurve::plane_from_points([a, b, c]));
let surface = Surface::plane_from_points([a, b, c]);
let surface = if reverse { surface.reverse() } else { surface };
let surface = shape.insert(surface)?;

Expand Down
12 changes: 11 additions & 1 deletion crates/fj-kernel/src/geometry/surfaces/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ pub mod swept;

pub use self::swept::SweptCurve;

use fj_math::{Point, Transform, Vector};
use fj_math::{Line, Point, Transform, Vector};

use crate::geometry;

Expand Down Expand Up @@ -40,6 +40,16 @@ impl Surface {
})
}

/// Construct a plane from 3 points
pub fn plane_from_points(points: [impl Into<Point<3>>; 3]) -> Self {
let [a, b, c] = points.map(Into::into);

let curve = Curve::Line(Line::from_points([a, b]));
let path = c - a;

Self::SweptCurve(SweptCurve { curve, path })
}

/// Create a new instance that is reversed
#[must_use]
pub fn reverse(self) -> Self {
Expand Down
9 changes: 0 additions & 9 deletions crates/fj-kernel/src/geometry/surfaces/swept.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,6 @@ pub struct SweptCurve {
}

impl SweptCurve {
/// Construct a plane from 3 points
#[cfg(test)]
pub fn plane_from_points([a, b, c]: [Point<3>; 3]) -> Self {
let curve = Curve::Line(Line::from_points([a, b]));
let path = c - a;

Self { curve, path }
}

/// Create a new instance that is reversed
#[must_use]
pub fn reverse(mut self) -> Self {
Expand Down