Skip to content

Commit 759d379

Browse files
committed
refactor: remove unused functions
1 parent 31e57b7 commit 759d379

File tree

3 files changed

+1
-106
lines changed

3 files changed

+1
-106
lines changed

apps/bot_manager/native/astarnative/src/collision_detection.rs

Lines changed: 0 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,6 @@ pub(crate) fn point_circle_collision(point: &Entity, circle: &Entity) -> bool {
99
let distance = calculate_distance(&point.position, &circle.position);
1010
distance <= circle.radius
1111
}
12-
pub(crate) fn point_polygon_collision(point: &Entity, polygon: &Entity) -> bool {
13-
let mut collision = false;
14-
for current in 0..polygon.vertices.len() {
15-
let mut next = current + 1;
16-
if next == polygon.vertices.len() {
17-
next = 0
18-
};
19-
20-
let current_vertex = polygon.vertices[current];
21-
let next_vertex = polygon.vertices[next];
22-
23-
if ((current_vertex.y >= point.position.y && next_vertex.y < point.position.y)
24-
|| (current_vertex.y < point.position.y && next_vertex.y >= point.position.y))
25-
&& (point.position.x
26-
< (next_vertex.x - current_vertex.x) * (point.position.y - current_vertex.y)
27-
/ (next_vertex.y - current_vertex.y)
28-
+ current_vertex.x)
29-
{
30-
collision = !collision;
31-
}
32-
}
33-
34-
collision
35-
}
3612

3713
/*
3814
* Determines if a collision has occured between a line and a circle
@@ -78,44 +54,6 @@ pub(crate) fn line_circle_collision(line: &Entity, circle: &Entity) -> bool {
7854
point_circle_collision(&closest_point, circle)
7955
}
8056

81-
/*
82-
* Determines if a collision has occured between two circles
83-
* If the distance between the centers of the circles is less than
84-
* the sum of the radius, a collision has occured
85-
*/
86-
pub(crate) fn circle_circle_collision(circle_1: &Entity, circle_2: &Entity) -> bool {
87-
let distance = calculate_distance(&circle_1.position, &circle_2.position);
88-
distance <= circle_1.radius + circle_2.radius
89-
}
90-
91-
/*
92-
* Determines if a collision has occured between a circle and a polygon
93-
*
94-
*/
95-
pub(crate) fn circle_polygon_collision(circle: &Entity, polygon: &Entity) -> bool {
96-
// For each line in the polygon, check if there is a collision between the line and the circle
97-
// If there is a collision, return true
98-
for current in 0..polygon.vertices.len() {
99-
let mut next = current + 1;
100-
if next == polygon.vertices.len() {
101-
next = 0
102-
};
103-
104-
let current_line =
105-
Entity::new_line(0, vec![polygon.vertices[current], polygon.vertices[next]]);
106-
107-
let collision = line_circle_collision(&current_line, circle);
108-
if collision {
109-
return true;
110-
};
111-
}
112-
113-
// Check if the center of the circle is inside the polygon
114-
// If you doesn't want to check if the circle is inside the polygon,
115-
// return false instead of calling point_polygon_colision
116-
point_polygon_colision(circle, polygon)
117-
}
118-
11957
/*
12058
* Determines if a collision has occured between a line and a polygon
12159
* If the distance between vertex 1 and the point and vertex 2 and the point
@@ -132,34 +70,6 @@ pub(crate) fn line_point_colision(line: &Entity, point: &Entity) -> bool {
13270
d1 + d2 >= line_length - buffer && d1 + d2 <= line_length + buffer
13371
}
13472

135-
/*
136-
* Determines if a collision has occured between a point and a polygon
137-
*/
138-
pub(crate) fn point_polygon_colision(point: &Entity, polygon: &Entity) -> bool {
139-
let mut collision = false;
140-
for current in 0..polygon.vertices.len() {
141-
let mut next = current + 1;
142-
if next == polygon.vertices.len() {
143-
next = 0
144-
};
145-
146-
let current_vertex = polygon.vertices[current];
147-
let next_vertex = polygon.vertices[next];
148-
149-
if ((current_vertex.y >= point.position.y && next_vertex.y < point.position.y)
150-
|| (current_vertex.y < point.position.y && next_vertex.y >= point.position.y))
151-
&& (point.position.x
152-
< (next_vertex.x - current_vertex.x) * (point.position.y - current_vertex.y)
153-
/ (next_vertex.y - current_vertex.y)
154-
+ current_vertex.x)
155-
{
156-
collision = !collision;
157-
}
158-
}
159-
160-
collision
161-
}
162-
16373
pub(crate) fn line_polygon_collision(line: &Entity, polygon: &Entity) -> bool {
16474
for current_vertex_index in 0..polygon.vertices.len() {
16575
let mut next_vertex_index = current_vertex_index + 1;

apps/bot_manager/native/astarnative/src/entity.rs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -78,21 +78,6 @@ impl Entity {
7878
}
7979
}
8080

81-
pub fn new_polygon(id: u64, vertices: Vec<Position>) -> Entity {
82-
Entity {
83-
id,
84-
shape: Shape::Polygon,
85-
position: Position { x: 0.0, y: 0.0 },
86-
radius: 0.0,
87-
vertices,
88-
speed: 0.0,
89-
category: Category::Obstacle,
90-
direction: Direction { x: 0.0, y: 0.0 },
91-
is_moving: false,
92-
name: format!("{}{}", "Polygon ", id),
93-
}
94-
}
95-
9681
pub fn collides_with(&mut self, entities: &Vec<Entity>) -> Vec<u64> {
9782
let mut result = Vec::new();
9883

apps/bot_manager/native/astarnative/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ fn a_star_shortest_path<'a>(from: Position, to: Position, collision_grid: Binary
4545
}
4646

4747
#[rustler::nif()]
48-
fn build_collision_grid<'a>(env: rustler::Env<'a>, obstacles: HashMap<u64, Entity>) -> Result<Binary<'a>, String> {
48+
fn build_collision_grid<'a>(env: Env<'a>, obstacles: HashMap<u64, Entity>) -> Result<Binary<'a>, String> {
4949
let grid : Option<OwnedBinary> = OwnedBinary::new(NUM_COLS as usize * NUM_ROWS as usize);
5050

5151
if grid.is_none() {

0 commit comments

Comments
 (0)