Skip to content

Commit

Permalink
Align behavior with the docs and the quat implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-blackbird committed Nov 13, 2024
1 parent 030494c commit 4f55fbf
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 11 deletions.
5 changes: 3 additions & 2 deletions codegen/templates/vec.rs.tera
Original file line number Diff line number Diff line change
Expand Up @@ -2124,8 +2124,9 @@ impl {{ self_t }} {
pub fn rotate_towards(self, rhs: Self, max_angle: {{ scalar_t }}) -> Self {
let angle_between = self.angle_between(rhs);
if angle_between <= 1e-4 {
return rhs;
return self;
}
// When `max_angle < 0`, rotate no further than `PI` radians away
let angle = max_angle.clamp(angle_between - core::{{ scalar_t }}::consts::PI, angle_between);
let axis = self
.cross(rhs)
Expand Down Expand Up @@ -2238,7 +2239,7 @@ impl {{ self_t }} {
let a = self.angle_to(rhs);
let abs_a = math::abs(a);
if abs_a <= 1e-4 {
return rhs;
return *self;
}
// When `max_angle < 0`, rotate no further than `PI` radians away
let angle = max_angle.clamp(abs_a - core::{{ scalar_t }}::consts::PI, abs_a) * math::signum(a);
Expand Down
3 changes: 2 additions & 1 deletion src/f32/coresimd/vec3a.rs
Original file line number Diff line number Diff line change
Expand Up @@ -894,8 +894,9 @@ impl Vec3A {
pub fn rotate_towards(self, rhs: Self, max_angle: f32) -> Self {
let angle_between = self.angle_between(rhs);
if angle_between <= 1e-4 {
return rhs;
return self;
}
// When `max_angle < 0`, rotate no further than `PI` radians away
let angle = max_angle.clamp(angle_between - core::f32::consts::PI, angle_between);
let axis = self
.cross(rhs)
Expand Down
3 changes: 2 additions & 1 deletion src/f32/neon/vec3a.rs
Original file line number Diff line number Diff line change
Expand Up @@ -938,8 +938,9 @@ impl Vec3A {
pub fn rotate_towards(self, rhs: Self, max_angle: f32) -> Self {
let angle_between = self.angle_between(rhs);
if angle_between <= 1e-4 {
return rhs;
return self;
}
// When `max_angle < 0`, rotate no further than `PI` radians away
let angle = max_angle.clamp(angle_between - core::f32::consts::PI, angle_between);
let axis = self
.cross(rhs)
Expand Down
3 changes: 2 additions & 1 deletion src/f32/scalar/vec3a.rs
Original file line number Diff line number Diff line change
Expand Up @@ -941,8 +941,9 @@ impl Vec3A {
pub fn rotate_towards(self, rhs: Self, max_angle: f32) -> Self {
let angle_between = self.angle_between(rhs);
if angle_between <= 1e-4 {
return rhs;
return self;
}
// When `max_angle < 0`, rotate no further than `PI` radians away
let angle = max_angle.clamp(angle_between - core::f32::consts::PI, angle_between);
let axis = self
.cross(rhs)
Expand Down
3 changes: 2 additions & 1 deletion src/f32/sse2/vec3a.rs
Original file line number Diff line number Diff line change
Expand Up @@ -946,8 +946,9 @@ impl Vec3A {
pub fn rotate_towards(self, rhs: Self, max_angle: f32) -> Self {
let angle_between = self.angle_between(rhs);
if angle_between <= 1e-4 {
return rhs;
return self;
}
// When `max_angle < 0`, rotate no further than `PI` radians away
let angle = max_angle.clamp(angle_between - core::f32::consts::PI, angle_between);
let axis = self
.cross(rhs)
Expand Down
2 changes: 1 addition & 1 deletion src/f32/vec2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -929,7 +929,7 @@ impl Vec2 {
let a = self.angle_to(rhs);
let abs_a = math::abs(a);
if abs_a <= 1e-4 {
return rhs;
return *self;
}
// When `max_angle < 0`, rotate no further than `PI` radians away
let angle = max_angle.clamp(abs_a - core::f32::consts::PI, abs_a) * math::signum(a);
Expand Down
3 changes: 2 additions & 1 deletion src/f32/vec3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -931,8 +931,9 @@ impl Vec3 {
pub fn rotate_towards(self, rhs: Self, max_angle: f32) -> Self {
let angle_between = self.angle_between(rhs);
if angle_between <= 1e-4 {
return rhs;
return self;
}
// When `max_angle < 0`, rotate no further than `PI` radians away
let angle = max_angle.clamp(angle_between - core::f32::consts::PI, angle_between);
let axis = self
.cross(rhs)
Expand Down
3 changes: 2 additions & 1 deletion src/f32/wasm32/vec3a.rs
Original file line number Diff line number Diff line change
Expand Up @@ -909,8 +909,9 @@ impl Vec3A {
pub fn rotate_towards(self, rhs: Self, max_angle: f32) -> Self {
let angle_between = self.angle_between(rhs);
if angle_between <= 1e-4 {
return rhs;
return self;
}
// When `max_angle < 0`, rotate no further than `PI` radians away
let angle = max_angle.clamp(angle_between - core::f32::consts::PI, angle_between);
let axis = self
.cross(rhs)
Expand Down
2 changes: 1 addition & 1 deletion src/f64/dvec2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -929,7 +929,7 @@ impl DVec2 {
let a = self.angle_to(rhs);
let abs_a = math::abs(a);
if abs_a <= 1e-4 {
return rhs;
return *self;
}
// When `max_angle < 0`, rotate no further than `PI` radians away
let angle = max_angle.clamp(abs_a - core::f64::consts::PI, abs_a) * math::signum(a);
Expand Down
3 changes: 2 additions & 1 deletion src/f64/dvec3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -931,8 +931,9 @@ impl DVec3 {
pub fn rotate_towards(self, rhs: Self, max_angle: f64) -> Self {
let angle_between = self.angle_between(rhs);
if angle_between <= 1e-4 {
return rhs;
return self;
}
// When `max_angle < 0`, rotate no further than `PI` radians away
let angle = max_angle.clamp(angle_between - core::f64::consts::PI, angle_between);
let axis = self
.cross(rhs)
Expand Down

0 comments on commit 4f55fbf

Please sign in to comment.