Skip to content

Commit d74ddeb

Browse files
committed
feat: Add 'clamped' to 'Vector2'
1 parent 836fa99 commit d74ddeb

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

gdnative-core/src/core_types/vector2.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ pub trait Vector2Godot {
3030
/// This method runs faster than distance_to, so prefer it if you need to compare vectors or
3131
/// need the squared distance for some formula.
3232
fn distance_squared_to(self, other: Vector2) -> f32;
33+
/// Returns the vector with a maximum length by limiting its length to `length`.
34+
fn clamped(self, length: f32) -> Self;
3335
/// Internal API for converting to `sys` representation. Makes it possible to remove
3436
/// `transmute`s elsewhere.
3537
#[doc(hidden)]
@@ -125,6 +127,11 @@ impl Vector2Godot for Vector2 {
125127
(other - self).square_length()
126128
}
127129

130+
#[inline]
131+
fn clamped(self, length: f32) -> Self {
132+
self.clamp_length(0.0, length)
133+
}
134+
128135
#[inline]
129136
fn to_sys(self) -> sys::godot_vector2 {
130137
unsafe { std::mem::transmute(self) }

0 commit comments

Comments
 (0)