mirror of
				https://github.com/hannobraun/Fornjot
				synced 2025-10-30 19:58:31 +00:00 
			
		
		
		
	Merge pull request #1217 from hannobraun/winding
Fix `Triangle::winding`
This commit is contained in:
		
						commit
						e668c05afc
					
				
							
								
								
									
										1
									
								
								Cargo.lock
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										1
									
								
								Cargo.lock
									
									
									
										generated
									
									
									
								
							| @ -1026,6 +1026,7 @@ dependencies = [ | ||||
|  "num-traits", | ||||
|  "parry2d-f64", | ||||
|  "parry3d-f64", | ||||
|  "robust-predicates", | ||||
| ] | ||||
| 
 | ||||
| [[package]] | ||||
|  | ||||
| @ -22,7 +22,7 @@ pub fn triangulate( | ||||
|             v2.point_surface, | ||||
|         ]) | ||||
|         .expect("invalid triangle") | ||||
|         .winding_direction(); | ||||
|         .winding(); | ||||
| 
 | ||||
|         let required_winding = match coord_handedness { | ||||
|             Handedness::LeftHanded => Winding::Cw, | ||||
|  | ||||
| @ -17,3 +17,4 @@ nalgebra = "0.31.2" | ||||
| num-traits = "0.2.15" | ||||
| parry2d-f64 = "0.10.0" | ||||
| parry3d-f64 = "0.10.0" | ||||
| robust-predicates = "0.1.3" | ||||
|  | ||||
| @ -1,4 +1,3 @@ | ||||
| use parry2d_f64::utils::point_in_triangle::{corner_direction, Orientation}; | ||||
| use parry3d_f64::query::{Ray, RayCast as _}; | ||||
| 
 | ||||
| use crate::Vector; | ||||
| @ -58,9 +57,21 @@ impl<const D: usize> Triangle<D> { | ||||
| 
 | ||||
| impl Triangle<2> { | ||||
|     /// Returns the direction of the line through the points of the triangle.
 | ||||
|     pub fn winding_direction(&self) -> Winding { | ||||
|         let [v0, v1, v2] = self.points.map(|point| point.to_na()); | ||||
|         corner_direction(&v0, &v1, &v2).into() | ||||
|     pub fn winding(&self) -> Winding { | ||||
|         let [pa, pb, pc] = self.points.map(|point| point.into()); | ||||
|         let orient2d = robust_predicates::orient2d(&pa, &pb, &pc); | ||||
| 
 | ||||
|         if orient2d < 0. { | ||||
|             return Winding::Cw; | ||||
|         } | ||||
|         if orient2d > 0. { | ||||
|             return Winding::Ccw; | ||||
|         } | ||||
| 
 | ||||
|         unreachable!( | ||||
|             "Points don't form a triangle, but this was verified in the \ | ||||
|             constructor." | ||||
|         ) | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| @ -122,16 +133,6 @@ pub enum Winding { | ||||
|     Cw, | ||||
| } | ||||
| 
 | ||||
| impl From<Orientation> for Winding { | ||||
|     fn from(o: Orientation) -> Self { | ||||
|         match o { | ||||
|             Orientation::Ccw => Winding::Ccw, | ||||
|             Orientation::Cw => Winding::Cw, | ||||
|             Orientation::None => unreachable!("not a triangle"), | ||||
|         } | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| #[cfg(test)] | ||||
| mod tests { | ||||
|     use crate::{Point, Vector}; | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user