Skip to content

Commit dc81475

Browse files
author
RealAstolfo
committed
Merge Fixes
Fixed The resolved files from various compiler errors (mostly to match new internals) including the rust formatting.
1 parent 78fde06 commit dc81475

File tree

4 files changed

+56
-215
lines changed

4 files changed

+56
-215
lines changed

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: 23 additions & 94 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,89 +97,41 @@ 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

188137
pub fn cubic_interpolate_in_time(
@@ -196,27 +145,13 @@ impl Vector2 {
196145
post_b_t: f32,
197146
) -> Self {
198147
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,
148+
self.x, b.x, pre_a.x, post_b.x, weight, b_t, pre_a_t, post_b_t,
207149
);
208150
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,
151+
self.y, b.y, pre_a.y, post_b.y, weight, b_t, pre_a_t, post_b_t,
217152
);
218153

219-
Self::new(x, y)
154+
Self::new(x, y)
220155
}
221156

222157
pub fn direction_to(self, to: Self) -> Self {
@@ -264,11 +199,11 @@ impl Vector2 {
264199
}
265200

266201
pub fn lerp(self, to: Self, weight: f32) -> Self {
267-
Self(self.to_glam().lerp(to.to_glam(), weight))
202+
Self::from_glam(self.to_glam().lerp(to.to_glam(), weight))
268203
}
269204

270205
pub fn limit_length(self, length: Option<f32>) -> Self {
271-
Self(self.to_glam().clamp_length_max(length.unwrap_or(1.0)))
206+
Self::from_glam(self.to_glam().clamp_length_max(length.unwrap_or(1.0)))
272207
}
273208

274209
pub fn max_axis_index(self) -> i32 {
@@ -306,10 +241,7 @@ impl Vector2 {
306241
}
307242

308243
pub fn posmodv(self, modv: Self) -> Self {
309-
Self::new(
310-
fposmod(self.x, modv.x),
311-
fposmod(self.y, modv.y),
312-
)
244+
Self::new(fposmod(self.x, modv.x), fposmod(self.y, modv.y))
313245
}
314246

315247
pub fn project(self, b: Self) -> Self {
@@ -345,17 +277,14 @@ impl Vector2 {
345277
}
346278

347279
pub fn snapped(self, step: Self) -> Self {
348-
Self::new(
349-
snapped(self.x, step.x),
350-
snapped(self.y, step.y),
351-
)
280+
Self::new(snapped(self.x, step.x), snapped(self.y, step.y))
352281
}
353282

354283
/// Returns the result of rotating this vector by `angle` (in radians).
355284
pub fn rotated(self, angle: f32) -> Self {
356285
Self::from_glam(glam::Affine2::from_angle(angle).transform_vector2(self.to_glam()))
357286
}
358-
287+
359288
#[cfg(not(any(gdext_test, doctest)))]
360289
#[doc(hidden)]
361290
pub fn as_inner(&self) -> inner::InnerVector2 {

0 commit comments

Comments
 (0)