@@ -9,30 +9,6 @@ pub(crate) fn point_circle_collision(point: &Entity, circle: &Entity) -> bool {
9
9
let distance = calculate_distance ( & point. position , & circle. position ) ;
10
10
distance <= circle. radius
11
11
}
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
- }
36
12
37
13
/*
38
14
* 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 {
78
54
point_circle_collision ( & closest_point, circle)
79
55
}
80
56
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
-
119
57
/*
120
58
* Determines if a collision has occured between a line and a polygon
121
59
* 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 {
132
70
d1 + d2 >= line_length - buffer && d1 + d2 <= line_length + buffer
133
71
}
134
72
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
-
163
73
pub ( crate ) fn line_polygon_collision ( line : & Entity , polygon : & Entity ) -> bool {
164
74
for current_vertex_index in 0 ..polygon. vertices . len ( ) {
165
75
let mut next_vertex_index = current_vertex_index + 1 ;
0 commit comments