-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
6 changed files
with
137 additions
and
116 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
use crate::{Edge, Point2D, Triangle}; | ||
|
||
pub fn create_super_triangle(points: &Vec<Point2D>) -> Triangle { | ||
match points.is_empty() { | ||
true => panic!("The input points vector should not be empty."), | ||
false => {} | ||
} | ||
|
||
let index = 0; | ||
let mut min_x = f64::MAX; | ||
let mut min_y = f64::MAX; | ||
let mut max_x = f64::MIN; | ||
let mut max_y = f64::MIN; | ||
|
||
for point in points { | ||
if point.x < min_x { | ||
min_x = point.x; | ||
} | ||
if point.y < min_y { | ||
min_y = point.y; | ||
} | ||
if point.x > max_x { | ||
max_x = point.x; | ||
} | ||
if point.y > max_y { | ||
max_y = point.y; | ||
} | ||
} | ||
|
||
let margin = 100.0; | ||
|
||
let a = Point2D { | ||
index, | ||
x: min_x - margin, | ||
y: min_y - margin, | ||
}; | ||
let b = Point2D { | ||
index, | ||
x: max_x + margin, | ||
y: min_y - margin, | ||
}; | ||
let c = Point2D { | ||
index, | ||
x: (min_x + max_x) / 2.0, | ||
y: max_y + margin, | ||
}; | ||
|
||
Triangle { a, b, c } | ||
} | ||
|
||
pub fn edge_is_shared_by_triangles(edge: &Edge, triangles: &Vec<Triangle>) -> bool { | ||
for triangle in triangles { | ||
let edges_of_triangle = triangle.edges(); | ||
for edge_of_triangle in edges_of_triangle { | ||
if edge_of_triangle == *edge { | ||
return true; | ||
} | ||
if edge_of_triangle.reverse() == *edge { | ||
return true; | ||
} | ||
} | ||
} | ||
false | ||
} | ||
|
||
pub fn retriangulate(edge: &Edge, point: &Point2D) -> Triangle { | ||
Triangle { | ||
a: edge.start, | ||
b: edge.end, | ||
c: *point, | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
use crate::Triangle; | ||
|
||
pub fn triangle_contains_vertex_from_super_triangle( | ||
triangle: &Triangle, | ||
super_triangle: &Triangle, | ||
) -> bool { | ||
let super_triangle_vertices = super_triangle.vertices(); | ||
let triangle_vertices = triangle.vertices(); | ||
for super_triangle_vertex in super_triangle_vertices { | ||
if super_triangle_vertex == triangle_vertices[0] { | ||
return true; | ||
} | ||
if super_triangle_vertex == triangle_vertices[1] { | ||
return true; | ||
} | ||
if super_triangle_vertex == triangle_vertices[2] { | ||
return true; | ||
} | ||
} | ||
false | ||
} | ||
|
||
pub fn remove_triangles_with_vertices_from_super_triangle( | ||
triangles: &Vec<Triangle>, | ||
super_triangle: &Triangle, | ||
) -> Vec<Triangle> { | ||
let mut res: Vec<Triangle> = Vec::new(); | ||
|
||
for triangle in triangles { | ||
if !triangle_contains_vertex_from_super_triangle(triangle, super_triangle) { | ||
res.push(*triangle); | ||
} | ||
} | ||
res | ||
} |