Extract rebuild stages to methods
This commit is contained in:
parent
ebe6b317f2
commit
7cb3e59329
|
@ -56,9 +56,21 @@ impl Brush {
|
|||
panic!("Invalid number of planes. Minimum 4 planes required.");
|
||||
}
|
||||
|
||||
self.calculate_raw_vertices();
|
||||
self.merge_vertices();
|
||||
}
|
||||
|
||||
pub fn get_vertices(&self) -> Vec<Vec3> {
|
||||
self.vertices.clone()
|
||||
}
|
||||
|
||||
pub fn get_intersections(&self) -> Vec<PlaneIntersection> {
|
||||
self.raw_vertices.clone()
|
||||
}
|
||||
|
||||
fn calculate_raw_vertices(&mut self) {
|
||||
// Test all permutations of brush planes for intersections
|
||||
let mut intersections = vec![];
|
||||
let mut vs: Vec<Vec3> = vec![];
|
||||
let len = self.planes.len();
|
||||
for i in 0..(len - 2) {
|
||||
for j in (i + 1)..(len - 1) {
|
||||
|
@ -75,7 +87,10 @@ impl Brush {
|
|||
}
|
||||
|
||||
// Validate intersections against other brush planes
|
||||
// Intersections only produce vertices if they're in the half-space of every
|
||||
// plane in the brush.
|
||||
// TODO: No need to check against planes that are part of the intersection
|
||||
let mut raw_vertices = vec![];
|
||||
for intersection in &intersections {
|
||||
let mut valid = true;
|
||||
for bplane in &self.planes {
|
||||
|
@ -85,31 +100,30 @@ impl Brush {
|
|||
}
|
||||
}
|
||||
|
||||
// Merge vertices
|
||||
if valid {
|
||||
let point = intersection.get_intersection_point();
|
||||
let mut duplicate = false;
|
||||
for v in &vs {
|
||||
if v.abs_diff_eq(point, math::EPSILON) {
|
||||
duplicate = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if !duplicate {
|
||||
vs.push(point);
|
||||
raw_vertices.push(*intersection);
|
||||
}
|
||||
}
|
||||
|
||||
self.raw_vertices = raw_vertices;
|
||||
}
|
||||
|
||||
fn merge_vertices(&mut self) {
|
||||
let mut vs: Vec<Vec3> = vec![];
|
||||
for intersection in &self.raw_vertices {
|
||||
let point = intersection.get_intersection_point();
|
||||
let mut duplicate = false;
|
||||
for v in &vs {
|
||||
if v.abs_diff_eq(point, math::EPSILON) {
|
||||
duplicate = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if !duplicate {
|
||||
vs.push(point);
|
||||
}
|
||||
}
|
||||
|
||||
self.vertices = vs;
|
||||
self.raw_vertices = intersections;
|
||||
}
|
||||
|
||||
pub fn get_vertices(&self) -> Vec<Vec3> {
|
||||
self.vertices.clone()
|
||||
}
|
||||
|
||||
pub fn get_intersections(&self) -> Vec<PlaneIntersection> {
|
||||
self.raw_vertices.clone()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue