Skip to content

Commit

Permalink
Merge Fixes
Browse files Browse the repository at this point in the history
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
  • Loading branch information
RealAstolfo committed Jan 28, 2023
1 parent 78fde06 commit 6560738
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 221 deletions.
2 changes: 2 additions & 0 deletions godot-core/src/builtin/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ mod vector_macros;

mod arrays;
mod color;
mod math;
mod node_path;
mod others;
mod string;
Expand All @@ -53,6 +54,7 @@ pub mod meta;

pub use arrays::*;
pub use color::*;
pub use math::*;
pub use node_path::*;
pub use others::*;
pub use string::*;
Expand Down
123 changes: 26 additions & 97 deletions godot-core/src/builtin/vector2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
use std::ops::*;
use std::fmt;
use std::ops::*;

use godot_ffi as sys;
use sys::{ffi_methods, GodotFfi};

use crate::builtin::math::*;
use crate::builtin::{inner, Vector2i};

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

pub fn abs(self) -> Self {
Self(self.to_glam().abs())
}

pub fn angle(self) -> f32 {
self.y.atan2(self.x)
}
Expand All @@ -100,89 +97,41 @@ impl Vector2 {
self.x / self.y
}

pub fn bezier_derivative(
self,
control_1: Self,
control_2: Self,
end: Self,
t: f32,
) -> Self {
let x = bezier_derivative(
self.x,
control_1.x,
control_2.x,
end.x,
t,
);
let y = bezier_derivative(
self.y,
control_1.y,
control_2.y,
end.y,
t,
);
pub fn bezier_derivative(self, control_1: Self, control_2: Self, end: Self, t: f32) -> Self {
let x = bezier_derivative(self.x, control_1.x, control_2.x, end.x, t);
let y = bezier_derivative(self.y, control_1.y, control_2.y, end.y, t);

Self::new(x, y)
Self::new(x, y)
}

pub fn bezier_interpolate(
self,
control_1: Self,
control_2: Self,
end: Self,
t: f32,
) -> Self {
let x = bezier_interpolate(
self.x,
control_1.x,
control_2.x,
end.x,
t,
);
let y = bezier_interpolate(
self.y,
control_1.y,
control_2.y,
end.y,
t,
);
pub fn bezier_interpolate(self, control_1: Self, control_2: Self, end: Self, t: f32) -> Self {
let x = bezier_interpolate(self.x, control_1.x, control_2.x, end.x, t);
let y = bezier_interpolate(self.y, control_1.y, control_2.y, end.y, t);

Self::new(x, y)
Self::new(x, y)
}

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

pub fn ceil(self) -> Self {
Self(self.to_glam().ceil())
Self::from_glam(self.to_glam().ceil())
}

pub fn clamp(self, min: Self, max: Self) -> Self {
Self(self.to_glam().clamp(min.to_glam(), max.to_glam()))
Self::from_glam(self.to_glam().clamp(min.to_glam(), max.to_glam()))
}

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

pub fn cubic_interpolate(self, b: Self, pre_a: Self, post_b: Self, weight: f32) -> Self {
let x = cubic_interpolate(
self.x,
b.x,
pre_a.x,
post_b.x,
weight,
);
let y = cubic_interpolate(
self.y,
b.y,
pre_a.y,
post_b.y,
weight,
);
let x = cubic_interpolate(self.x, b.x, pre_a.x, post_b.x, weight);
let y = cubic_interpolate(self.y, b.y, pre_a.y, post_b.y, weight);

Self::new(x, y)
Self::new(x, y)
}

pub fn cubic_interpolate_in_time(
Expand All @@ -196,27 +145,13 @@ impl Vector2 {
post_b_t: f32,
) -> Self {
let x = cubic_interpolate_in_time(
self.x,
b.x,
pre_a.x,
post_b.x,
weight,
b_t,
pre_a_t,
post_b_t,
self.x, b.x, pre_a.x, post_b.x, weight, b_t, pre_a_t, post_b_t,
);
let y = cubic_interpolate_in_time(
self.y,
b.y,
pre_a.y,
post_b.y,
weight,
b_t,
pre_a_t,
post_b_t,
self.y, b.y, pre_a.y, post_b.y, weight, b_t, pre_a_t, post_b_t,
);

Self::new(x, y)
Self::new(x, y)
}

pub fn direction_to(self, to: Self) -> Self {
Expand Down Expand Up @@ -264,11 +199,11 @@ impl Vector2 {
}

pub fn lerp(self, to: Self, weight: f32) -> Self {
Self(self.to_glam().lerp(to.to_glam(), weight))
Self::from_glam(self.to_glam().lerp(to.to_glam(), weight))
}

pub fn limit_length(self, length: Option<f32>) -> Self {
Self(self.to_glam().clamp_length_max(length.unwrap_or(1.0)))
Self::from_glam(self.to_glam().clamp_length_max(length.unwrap_or(1.0)))
}

pub fn max_axis_index(self) -> i32 {
Expand All @@ -291,10 +226,10 @@ impl Vector2 {
let vd = to - self;
let len = vd.length();
if len <= delta || len < CMP_EPSILON {
return to;
to
} else {
return self + vd / len * delta;
};
self + vd / len * delta
}
}

pub fn orthogonal(self) -> Self {
Expand All @@ -306,10 +241,7 @@ impl Vector2 {
}

pub fn posmodv(self, modv: Self) -> Self {
Self::new(
fposmod(self.x, modv.x),
fposmod(self.y, modv.y),
)
Self::new(fposmod(self.x, modv.x), fposmod(self.y, modv.y))
}

pub fn project(self, b: Self) -> Self {
Expand Down Expand Up @@ -345,17 +277,14 @@ impl Vector2 {
}

pub fn snapped(self, step: Self) -> Self {
Self::new(
snapped(self.x, step.x),
snapped(self.y, step.y),
)
Self::new(snapped(self.x, step.x), snapped(self.y, step.y))
}

/// Returns the result of rotating this vector by `angle` (in radians).
pub fn rotated(self, angle: f32) -> Self {
Self::from_glam(glam::Affine2::from_angle(angle).transform_vector2(self.to_glam()))
}

#[cfg(not(any(gdext_test, doctest)))]
#[doc(hidden)]
pub fn as_inner(&self) -> inner::InnerVector2 {
Expand Down
Loading

0 comments on commit 6560738

Please sign in to comment.