1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
use crate::b2_math::*;
use crate::b2_settings::*;
use crate::b2_shape::*;
use crate::private::collision::b2_distance as private;
use std::sync::atomic::AtomicUsize;
pub static B2_GJK_CALLS: AtomicUsize = AtomicUsize::new(0);
pub static B2_GJK_ITERS: AtomicUsize = AtomicUsize::new(0);
pub static B2_GJK_MAX_ITERS: AtomicUsize = AtomicUsize::new(0);
#[derive(Default, Clone, Debug)]
pub struct B2distanceProxy {
pub m_buffer: [B2vec2; 2],
pub m_vertices: Vec<B2vec2>,
pub m_radius: f32,
}
impl B2distanceProxy {
pub fn set_shape(&mut self, shape: ShapePtr, index: usize) {
private::set_shape(self, shape, index);
}
pub fn set_vertices(&mut self, vertices: &[B2vec2], radius: f32) {
private::set_vertices(self, vertices, radius);
}
pub fn get_support(&self, d: B2vec2) -> usize {
return inline::get_support(self, d);
}
pub fn get_support_vertex(&self, d: B2vec2) -> B2vec2 {
return inline::get_support_vertex(self, d);
}
pub fn get_vertex_count(&self) -> usize {
return inline::get_vertex_count(self);
}
pub fn get_vertex(&self, index: usize) -> B2vec2 {
return inline::get_vertex(self, index);
}
}
#[derive(Default, Clone, Copy, Debug)]
pub struct B2simplexCache {
pub metric: f32,
pub count: u16,
pub index_a: [u8; 3],
pub index_b: [u8; 3],
}
#[derive(Default, Clone, Debug)]
pub struct B2distanceInput {
pub proxy_a: B2distanceProxy,
pub proxy_b: B2distanceProxy,
pub transform_a: B2Transform,
pub transform_b: B2Transform,
pub use_radii: bool,
}
#[derive(Default, Clone, Copy, Debug)]
pub struct B2distanceOutput {
pub point_a: B2vec2,
pub point_b: B2vec2,
pub distance: f32,
pub iterations: i32,
}
pub fn b2_distance_fn(
output: &mut B2distanceOutput,
cache: &mut B2simplexCache,
input: &B2distanceInput,
) {
private::b2_distance_fn(output, cache, input);
}
#[derive(Default, Clone, Debug)]
pub struct B2shapeCastInput {
pub proxy_a: B2distanceProxy,
pub proxy_b: B2distanceProxy,
pub transform_a: B2Transform,
pub transform_b: B2Transform,
pub translation_b: B2vec2,
}
#[derive(Default, Clone, Copy, Debug)]
pub struct B2shapeCastOutput {
pub point: B2vec2,
pub normal: B2vec2,
pub lambda: f32,
pub iterations: i32,
}
pub fn b2_shape_cast(output: &mut B2shapeCastOutput, input: B2shapeCastInput) -> bool {
return private::b2_shape_cast(output, input);
}
mod inline {
use super::*;
pub fn get_vertex_count(this: &B2distanceProxy) -> usize {
return this.m_vertices.len();
}
pub fn get_vertex(this: &B2distanceProxy, index: usize) -> B2vec2 {
b2_assert(index < this.m_vertices.len());
return this.m_vertices[index];
}
pub fn get_support(this: &B2distanceProxy, d: B2vec2) -> usize {
let mut best_index: usize = 0;
let mut best_value: f32 = b2_dot(this.m_vertices[0], d);
for i in 1..this.m_vertices.len() {
let value: f32 = b2_dot(this.m_vertices[i], d);
if value > best_value {
best_index = i;
best_value = value;
}
}
return best_index;
}
pub fn get_support_vertex(this: &B2distanceProxy, d: B2vec2) -> B2vec2 {
let mut best_index: usize = 0;
let mut best_value: f32 = b2_dot(this.m_vertices[0], d);
for i in 1..this.m_vertices.len() {
let value: f32 = b2_dot(this.m_vertices[i], d);
if value > best_value {
best_index = i;
best_value = value;
}
}
return this.m_vertices[best_index];
}
}