Expect &Geometry in Cycle::winding

This commit is contained in:
Hanno Braun 2024-03-18 12:47:23 +01:00
parent f33f5ca712
commit cad8778bcb
5 changed files with 15 additions and 12 deletions

View File

@ -1,7 +1,7 @@
use fj_math::{Scalar, Winding}; use fj_math::{Scalar, Winding};
use crate::{ use crate::{
geometry::SurfacePath, geometry::{Geometry, SurfacePath},
objects::{HalfEdge, ObjectSet}, objects::{HalfEdge, ObjectSet},
storage::Handle, storage::Handle,
}; };
@ -29,7 +29,7 @@ impl Cycle {
/// Please note that this is not *the* winding of the cycle, only one of the /// Please note that this is not *the* winding of the cycle, only one of the
/// two possible windings, depending on the direction you look at the /// two possible windings, depending on the direction you look at the
/// surface that the cycle is defined on from. /// surface that the cycle is defined on from.
pub fn winding(&self) -> Winding { pub fn winding(&self, _: &Geometry) -> Winding {
// The cycle could be made up of one or two circles. If that is the // The cycle could be made up of one or two circles. If that is the
// case, the winding of the cycle is determined by the winding of the // case, the winding of the cycle is determined by the winding of the
// first circle. // first circle.

View File

@ -65,8 +65,8 @@ impl Face {
/// Faces *do* have an orientation, meaning they have definite front and /// Faces *do* have an orientation, meaning they have definite front and
/// back sides. The front side is the side, where the face's exterior cycle /// back sides. The front side is the side, where the face's exterior cycle
/// is wound counter-clockwise. /// is wound counter-clockwise.
pub fn coord_handedness(&self, _: &Geometry) -> Handedness { pub fn coord_handedness(&self, geometry: &Geometry) -> Handedness {
match self.region.exterior().winding() { match self.region.exterior().winding(geometry) {
Winding::Ccw => Handedness::RightHanded, Winding::Ccw => Handedness::RightHanded,
Winding::Cw => Handedness::LeftHanded, Winding::Cw => Handedness::LeftHanded,
} }

View File

@ -40,7 +40,10 @@ impl SweepSketch for Sketch {
let region = { let region = {
// The following code assumes that the sketch is winded counter- // The following code assumes that the sketch is winded counter-
// clockwise. Let's check that real quick. // clockwise. Let's check that real quick.
assert!(region.exterior().winding().is_ccw()); assert!(region
.exterior()
.winding(&core.layers.geometry)
.is_ccw());
let is_negative_sweep = { let is_negative_sweep = {
let u = match core.layers.geometry.of_surface(&surface).u { let u = match core.layers.geometry.of_surface(&surface).u {

View File

@ -58,7 +58,7 @@ impl FaceValidationError {
fn check_interior_winding( fn check_interior_winding(
face: &Face, face: &Face,
_: &Geometry, geometry: &Geometry,
errors: &mut Vec<ValidationError>, errors: &mut Vec<ValidationError>,
) { ) {
if face.region().exterior().half_edges().is_empty() { if face.region().exterior().half_edges().is_empty() {
@ -67,7 +67,7 @@ impl FaceValidationError {
return; return;
} }
let exterior_winding = face.region().exterior().winding(); let exterior_winding = face.region().exterior().winding(geometry);
for interior in face.region().interiors() { for interior in face.region().interiors() {
if interior.half_edges().is_empty() { if interior.half_edges().is_empty() {
@ -75,7 +75,7 @@ impl FaceValidationError {
// like a job for a different validation check. // like a job for a different validation check.
continue; continue;
} }
let interior_winding = interior.winding(); let interior_winding = interior.winding(geometry);
if exterior_winding == interior_winding { if exterior_winding == interior_winding {
errors.push( errors.push(

View File

@ -78,13 +78,13 @@ impl SketchValidationError {
fn check_exterior_cycles( fn check_exterior_cycles(
sketch: &Sketch, sketch: &Sketch,
_: &Geometry, geometry: &Geometry,
_config: &ValidationConfig, _config: &ValidationConfig,
errors: &mut Vec<ValidationError>, errors: &mut Vec<ValidationError>,
) { ) {
sketch.regions().iter().for_each(|region| { sketch.regions().iter().for_each(|region| {
let cycle = region.exterior(); let cycle = region.exterior();
if cycle.winding() == Winding::Cw { if cycle.winding(geometry) == Winding::Cw {
errors.push(ValidationError::Sketch( errors.push(ValidationError::Sketch(
SketchValidationError::ClockwiseExteriorCycle { SketchValidationError::ClockwiseExteriorCycle {
cycle: cycle.clone(), cycle: cycle.clone(),
@ -96,7 +96,7 @@ impl SketchValidationError {
fn check_interior_cycles( fn check_interior_cycles(
sketch: &Sketch, sketch: &Sketch,
_: &Geometry, geometry: &Geometry,
_config: &ValidationConfig, _config: &ValidationConfig,
errors: &mut Vec<ValidationError>, errors: &mut Vec<ValidationError>,
) { ) {
@ -104,7 +104,7 @@ impl SketchValidationError {
region region
.interiors() .interiors()
.iter() .iter()
.filter(|interior| interior.winding() == Winding::Ccw) .filter(|interior| interior.winding(geometry) == Winding::Ccw)
.for_each(|cycle| { .for_each(|cycle| {
errors.push(ValidationError::Sketch( errors.push(ValidationError::Sketch(
SketchValidationError::CounterClockwiseInteriorCycle { SketchValidationError::CounterClockwiseInteriorCycle {