Skip to content

Commit b98c870

Browse files
author
RealAstolfo
committed
Merge Fixes
Fixed The resolved files from various compiler errors (mostly to match new internals) including the rust formatting... and clippy complainers. i think rustic for emacs is broken, as these small things are normally automatically handled
1 parent 78fde06 commit b98c870

File tree

5 files changed

+69
-231
lines changed

5 files changed

+69
-231
lines changed

godot-core/src/builtin/math.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ pub fn cubic_interpolate(from: f32, to: f32, pre: f32, post: f32, weight: f32) -
6666
+ (-pre + 3.0 * from - 3.0 * to + post) * (weight * weight * weight))
6767
}
6868

69+
#[allow(clippy::too_many_arguments)]
6970
pub fn cubic_interpolate_in_time(
7071
from: f32,
7172
to: f32,

godot-core/src/builtin/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ mod vector_macros;
3737

3838
mod arrays;
3939
mod color;
40+
mod math;
4041
mod node_path;
4142
mod others;
4243
mod string;
@@ -53,6 +54,7 @@ pub mod meta;
5354

5455
pub use arrays::*;
5556
pub use color::*;
57+
pub use math::*;
5658
pub use node_path::*;
5759
pub use others::*;
5860
pub use string::*;

godot-core/src/builtin/vector2.rs

Lines changed: 31 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
* License, v. 2.0. If a copy of the MPL was not distributed with this
44
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
55
*/
6-
use std::ops::*;
76
use std::fmt;
7+
use std::ops::*;
88

99
use godot_ffi as sys;
1010
use sys::{ffi_methods, GodotFfi};
1111

12+
use crate::builtin::math::*;
1213
use crate::builtin::{inner, Vector2i};
1314

1415
/// Vector used for 2D math using floating point coordinates.
@@ -80,10 +81,6 @@ impl Vector2 {
8081
glam::Vec2::new(self.x, self.y)
8182
}
8283

83-
pub fn abs(self) -> Self {
84-
Self(self.to_glam().abs())
85-
}
86-
8784
pub fn angle(self) -> f32 {
8885
self.y.atan2(self.x)
8986
}
@@ -100,91 +97,44 @@ impl Vector2 {
10097
self.x / self.y
10198
}
10299

103-
pub fn bezier_derivative(
104-
self,
105-
control_1: Self,
106-
control_2: Self,
107-
end: Self,
108-
t: f32,
109-
) -> Self {
110-
let x = bezier_derivative(
111-
self.x,
112-
control_1.x,
113-
control_2.x,
114-
end.x,
115-
t,
116-
);
117-
let y = bezier_derivative(
118-
self.y,
119-
control_1.y,
120-
control_2.y,
121-
end.y,
122-
t,
123-
);
100+
pub fn bezier_derivative(self, control_1: Self, control_2: Self, end: Self, t: f32) -> Self {
101+
let x = bezier_derivative(self.x, control_1.x, control_2.x, end.x, t);
102+
let y = bezier_derivative(self.y, control_1.y, control_2.y, end.y, t);
124103

125-
Self::new(x, y)
104+
Self::new(x, y)
126105
}
127106

128-
pub fn bezier_interpolate(
129-
self,
130-
control_1: Self,
131-
control_2: Self,
132-
end: Self,
133-
t: f32,
134-
) -> Self {
135-
let x = bezier_interpolate(
136-
self.x,
137-
control_1.x,
138-
control_2.x,
139-
end.x,
140-
t,
141-
);
142-
let y = bezier_interpolate(
143-
self.y,
144-
control_1.y,
145-
control_2.y,
146-
end.y,
147-
t,
148-
);
107+
pub fn bezier_interpolate(self, control_1: Self, control_2: Self, end: Self, t: f32) -> Self {
108+
let x = bezier_interpolate(self.x, control_1.x, control_2.x, end.x, t);
109+
let y = bezier_interpolate(self.y, control_1.y, control_2.y, end.y, t);
149110

150-
Self::new(x, y)
111+
Self::new(x, y)
151112
}
152113

153114
pub fn bounce(self, normal: Self) -> Self {
154115
-self.reflect(normal)
155116
}
156117

157118
pub fn ceil(self) -> Self {
158-
Self(self.to_glam().ceil())
119+
Self::from_glam(self.to_glam().ceil())
159120
}
160121

161122
pub fn clamp(self, min: Self, max: Self) -> Self {
162-
Self(self.to_glam().clamp(min.to_glam(), max.to_glam()))
123+
Self::from_glam(self.to_glam().clamp(min.to_glam(), max.to_glam()))
163124
}
164125

165126
pub fn cross(self, with: Self) -> f32 {
166127
self.to_glam().perp_dot(with.to_glam())
167128
}
168129

169130
pub fn cubic_interpolate(self, b: Self, pre_a: Self, post_b: Self, weight: f32) -> Self {
170-
let x = cubic_interpolate(
171-
self.x,
172-
b.x,
173-
pre_a.x,
174-
post_b.x,
175-
weight,
176-
);
177-
let y = cubic_interpolate(
178-
self.y,
179-
b.y,
180-
pre_a.y,
181-
post_b.y,
182-
weight,
183-
);
131+
let x = cubic_interpolate(self.x, b.x, pre_a.x, post_b.x, weight);
132+
let y = cubic_interpolate(self.y, b.y, pre_a.y, post_b.y, weight);
184133

185-
Self::new(x, y)
134+
Self::new(x, y)
186135
}
187136

137+
#[allow(clippy::too_many_arguments)]
188138
pub fn cubic_interpolate_in_time(
189139
self,
190140
b: Self,
@@ -196,27 +146,13 @@ impl Vector2 {
196146
post_b_t: f32,
197147
) -> Self {
198148
let x = cubic_interpolate_in_time(
199-
self.x,
200-
b.x,
201-
pre_a.x,
202-
post_b.x,
203-
weight,
204-
b_t,
205-
pre_a_t,
206-
post_b_t,
149+
self.x, b.x, pre_a.x, post_b.x, weight, b_t, pre_a_t, post_b_t,
207150
);
208151
let y = cubic_interpolate_in_time(
209-
self.y,
210-
b.y,
211-
pre_a.y,
212-
post_b.y,
213-
weight,
214-
b_t,
215-
pre_a_t,
216-
post_b_t,
152+
self.y, b.y, pre_a.y, post_b.y, weight, b_t, pre_a_t, post_b_t,
217153
);
218154

219-
Self::new(x, y)
155+
Self::new(x, y)
220156
}
221157

222158
pub fn direction_to(self, to: Self) -> Self {
@@ -264,37 +200,31 @@ impl Vector2 {
264200
}
265201

266202
pub fn lerp(self, to: Self, weight: f32) -> Self {
267-
Self(self.to_glam().lerp(to.to_glam(), weight))
203+
Self::from_glam(self.to_glam().lerp(to.to_glam(), weight))
268204
}
269205

270206
pub fn limit_length(self, length: Option<f32>) -> Self {
271-
Self(self.to_glam().clamp_length_max(length.unwrap_or(1.0)))
207+
Self::from_glam(self.to_glam().clamp_length_max(length.unwrap_or(1.0)))
272208
}
273209

274210
pub fn max_axis_index(self) -> i32 {
275-
if self.to_glam().max_element() == self.x {
276-
0
277-
} else {
278-
1
279-
}
211+
let me = self.to_glam().max_element();
212+
(me == self.y) as i32
280213
}
281214

282215
pub fn min_axis_index(self) -> i32 {
283-
if self.to_glam().min_element() == self.x {
284-
0
285-
} else {
286-
1
287-
}
216+
let me = self.to_glam().min_element();
217+
(me == self.y) as i32
288218
}
289219

290220
pub fn move_toward(self, to: Self, delta: f32) -> Self {
291221
let vd = to - self;
292222
let len = vd.length();
293223
if len <= delta || len < CMP_EPSILON {
294-
return to;
224+
to
295225
} else {
296-
return self + vd / len * delta;
297-
};
226+
self + vd / len * delta
227+
}
298228
}
299229

300230
pub fn orthogonal(self) -> Self {
@@ -306,10 +236,7 @@ impl Vector2 {
306236
}
307237

308238
pub fn posmodv(self, modv: Self) -> Self {
309-
Self::new(
310-
fposmod(self.x, modv.x),
311-
fposmod(self.y, modv.y),
312-
)
239+
Self::new(fposmod(self.x, modv.x), fposmod(self.y, modv.y))
313240
}
314241

315242
pub fn project(self, b: Self) -> Self {
@@ -345,17 +272,14 @@ impl Vector2 {
345272
}
346273

347274
pub fn snapped(self, step: Self) -> Self {
348-
Self::new(
349-
snapped(self.x, step.x),
350-
snapped(self.y, step.y),
351-
)
275+
Self::new(snapped(self.x, step.x), snapped(self.y, step.y))
352276
}
353277

354278
/// Returns the result of rotating this vector by `angle` (in radians).
355279
pub fn rotated(self, angle: f32) -> Self {
356280
Self::from_glam(glam::Affine2::from_angle(angle).transform_vector2(self.to_glam()))
357281
}
358-
282+
359283
#[cfg(not(any(gdext_test, doctest)))]
360284
#[doc(hidden)]
361285
pub fn as_inner(&self) -> inner::InnerVector2 {

0 commit comments

Comments
 (0)