-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6c57453
commit 45b5b2b
Showing
11 changed files
with
75 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,20 @@ | ||
use super::ring::Ring; | ||
|
||
#[derive(Clone, Debug, PartialEq, PartialOrd)] | ||
#[derive(Debug)] | ||
pub struct Face { | ||
pub exterior: Ring, | ||
pub holes: Vec<Ring>, | ||
} | ||
|
||
impl Face { | ||
pub fn from_ring(ring: &Ring) -> Face { | ||
pub fn from_ring(ring: Ring) -> Face { | ||
Face { | ||
exterior: ring.clone(), | ||
exterior: ring, | ||
holes: vec![], | ||
} | ||
} | ||
|
||
pub fn add_hole(&mut self, hole: &Face) { | ||
self.holes.push(hole.exterior.clone()); | ||
pub fn add_hole(&mut self, hole: Ring) { | ||
self.holes.push(hole); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
use crate::sketch::Sketch; | ||
|
||
use self::face::Face; | ||
|
||
pub mod face; | ||
pub mod ring; | ||
pub mod segment; | ||
|
||
pub fn decompose_sketch(sketch: &Sketch) -> Vec<Face> { | ||
for primitive in sketch.primitives() { | ||
let primitive = primitive.borrow().to_primitive(); | ||
} | ||
|
||
todo!("Decompose the sketch into faces") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,76 +1,9 @@ | ||
use super::circle::Circle; | ||
use crate::primitives::circle::Circle; | ||
|
||
use super::segment::Segment; | ||
|
||
#[derive(Clone, Debug, PartialEq, PartialOrd)] | ||
#[derive(Debug)] | ||
pub enum Ring { | ||
Circle(Circle), | ||
Segments(Vec<Segment>), | ||
} | ||
|
||
impl Ring { | ||
pub fn adjacent_edges(&self, other: &Self) -> Option<(Vec<usize>, Vec<usize>)> { | ||
match (self, other) { | ||
(Ring::Segments(segments_a), Ring::Segments(segments_b)) => { | ||
let mut edge_indices_a: Vec<usize> = vec![]; | ||
let mut edge_indices_b: Vec<usize> = vec![]; | ||
for (index_a, segment_a) in segments_a.iter().enumerate() { | ||
for (index_b, segment_b) in segments_b.iter().enumerate() { | ||
if segment_a.reverse_equals(segment_b) { | ||
edge_indices_a.push(index_a); | ||
edge_indices_b.push(index_b); | ||
} | ||
} | ||
} | ||
if edge_indices_a.len() == 0 { | ||
return None; | ||
} else { | ||
Some((edge_indices_a, edge_indices_b)) | ||
} | ||
} | ||
_ => None, | ||
} | ||
} | ||
|
||
pub fn canonical_form(&self) -> Self { | ||
// sort the segments in order by first finding the segment with the smallest start point | ||
// and then rotating the list so that that segment is first | ||
match self { | ||
Ring::Circle(circle) => Ring::Circle(circle.clone()), | ||
Ring::Segments(segments) => { | ||
let mut canonical_segments: Vec<Segment> = vec![]; | ||
let mut min_index = 0; | ||
let mut min_segment = segments.get(0).unwrap(); | ||
for (i, segment) in segments.iter().enumerate() { | ||
if segment.get_start() < min_segment.get_start() { | ||
min_index = i; | ||
min_segment = segment; | ||
} | ||
} | ||
|
||
for i in 0..segments.len() { | ||
canonical_segments.push( | ||
segments | ||
.get((i + min_index) % segments.len()) | ||
.unwrap() | ||
.clone(), | ||
); | ||
} | ||
|
||
Ring::Segments(canonical_segments) | ||
} | ||
} | ||
} | ||
|
||
pub fn reverse(&self) -> Self { | ||
match self { | ||
Ring::Circle(circle) => Ring::Circle(circle.clone()), | ||
Ring::Segments(segments) => { | ||
let mut reversed_segments: Vec<Segment> = vec![]; | ||
for segment in segments.iter().rev() { | ||
reversed_segments.push(segment.reverse()); | ||
} | ||
Ring::Segments(reversed_segments) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters