Skip to content

Commit

Permalink
Add Path::is_negative_direction
Browse files Browse the repository at this point in the history
  • Loading branch information
hannobraun committed Aug 23, 2022
1 parent af5f6ee commit 45c8628
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 25 deletions.
7 changes: 6 additions & 1 deletion crates/fj-kernel/src/algorithms/sweep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ mod face;
mod sketch;

use fj_interop::mesh::Color;
use fj_math::Vector;
use fj_math::{Scalar, Vector};

use super::Tolerance;

Expand All @@ -32,6 +32,11 @@ impl Path {
pub fn inner(&self) -> Vector<3> {
self.0
}

/// Indicate whether the path is in the negative direction
pub fn is_negative_direction(&self) -> bool {
self.0.dot(&Vector::from([0., 0., 1.])) < Scalar::ZERO
}
}

impl<T> From<T> for Path
Expand Down
9 changes: 2 additions & 7 deletions crates/fj-kernel/src/algorithms/sweep/edge.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use fj_interop::mesh::Color;
use fj_math::{Point, Scalar, Transform, Triangle, Vector};
use fj_math::{Point, Transform, Triangle};

use crate::{
algorithms::{CycleApprox, Tolerance},
Expand All @@ -22,13 +22,9 @@ impl Sweep for Edge {
) -> Self::Swept {
let path = path.into();

let is_sweep_along_negative_direction =
path.inner().dot(&Vector::from([0., 0., 1.])) < Scalar::ZERO;

if let Some(vertices) = self.vertices().get() {
let face = create_non_continuous_side_face(
path,
is_sweep_along_negative_direction,
vertices.map(|vertex| *vertex.global()),
color,
);
Expand All @@ -41,7 +37,6 @@ impl Sweep for Edge {

fn create_non_continuous_side_face(
path: Path,
is_sweep_along_negative_direction: bool,
vertices_bottom: [GlobalVertex; 2],
color: Color,
) -> Face {
Expand All @@ -53,7 +48,7 @@ fn create_non_continuous_side_face(

let [[a, b], [c, d]] = [vertices_bottom, vertices_top];

if is_sweep_along_negative_direction {
if path.is_negative_direction() {
[b, a, c, d]
} else {
[a, b, d, c]
Expand Down
21 changes: 4 additions & 17 deletions crates/fj-kernel/src/algorithms/sweep/face.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use fj_math::{Scalar, Vector};

use crate::{
algorithms::{reverse_face, TransformObject},
objects::{Face, Shell},
Expand All @@ -18,20 +16,13 @@ impl Sweep for Face {
) -> Self::Swept {
let path = path.into();

let is_sweep_along_negative_direction =
path.inner().dot(&Vector::from([0., 0., 1.])) < Scalar::ZERO;

let mut faces = Vec::new();

let bottom_face =
create_bottom_face(&self, is_sweep_along_negative_direction);
create_bottom_face(&self, path.is_negative_direction());
faces.push(bottom_face);

let top_face = create_top_face(
self.clone(),
path,
is_sweep_along_negative_direction,
);
let top_face = create_top_face(self.clone(), path);
faces.push(top_face);

for cycle in self.all_cycles() {
Expand All @@ -56,14 +47,10 @@ fn create_bottom_face(
}
}

fn create_top_face(
face: Face,
path: Path,
is_sweep_along_negative_direction: bool,
) -> Face {
fn create_top_face(face: Face, path: Path) -> Face {
let mut face = face.translate(path.inner());

if is_sweep_along_negative_direction {
if path.is_negative_direction() {
face = reverse_face(&face);
};

Expand Down

0 comments on commit 45c8628

Please sign in to comment.