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.");
|
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
|
// Test all permutations of brush planes for intersections
|
||||||
let mut intersections = vec![];
|
let mut intersections = vec![];
|
||||||
let mut vs: Vec<Vec3> = vec![];
|
|
||||||
let len = self.planes.len();
|
let len = self.planes.len();
|
||||||
for i in 0..(len - 2) {
|
for i in 0..(len - 2) {
|
||||||
for j in (i + 1)..(len - 1) {
|
for j in (i + 1)..(len - 1) {
|
||||||
|
@ -75,7 +87,10 @@ impl Brush {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate intersections against other brush planes
|
// 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
|
// TODO: No need to check against planes that are part of the intersection
|
||||||
|
let mut raw_vertices = vec![];
|
||||||
for intersection in &intersections {
|
for intersection in &intersections {
|
||||||
let mut valid = true;
|
let mut valid = true;
|
||||||
for bplane in &self.planes {
|
for bplane in &self.planes {
|
||||||
|
@ -85,8 +100,17 @@ impl Brush {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Merge vertices
|
|
||||||
if valid {
|
if valid {
|
||||||
|
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 point = intersection.get_intersection_point();
|
||||||
let mut duplicate = false;
|
let mut duplicate = false;
|
||||||
for v in &vs {
|
for v in &vs {
|
||||||
|
@ -99,17 +123,7 @@ impl Brush {
|
||||||
vs.push(point);
|
vs.push(point);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
self.vertices = vs;
|
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