Skip to content

Commit c928ca1

Browse files
dbeckwithmockersf
authored andcommitted
Fix atan2 docs (#16673)
# Objective The parameter names for `bevy::math::ops::atan2` are labelled such that `x` is the first argument and `y` is the second argument, but it passes those arguments directly to [`f32::atan2`](https://doc.rust-lang.org/stable/std/primitive.f32.html#method.atan2), whose parameters are expected to be `(y, x)`. This PR changes the parameter names in the bevy documentation to use the correct order for the operation being performed. You can verify this by doing: ```rust fn main() { let x = 3.0; let y = 4.0; let angle = bevy::math::ops::atan2(x, y); // standard polar coordinates formula dbg!(5.0 * angle.cos(), 5.0 * angle.sin()); } ``` This will print `(4.0, 3.0)`, which has flipped `x` and `y`. The problem is that the `atan2` function to calculate the angle was really expecting `(y, x)`, not `(x, y)`. ## Solution I flipped the parameter names for `bevy::math::ops::atan2` and updated the documentation. I also removed references to `self` and `other` from the documentation which seemed to be copied from the `f32::atan2` documentation. ## Testing Not really needed, you can compare the `f32::atan2` docs to the `bevy::math::ops::atan2` docs to see the problem is obvious. If a test is required I could add a short one. ## Migration Guide I'm not sure if this counts as a breaking change, since the implementation clearly meant to use `f32::atan2` directly, so it was really just the parameter names that were wrong.
1 parent 1a865af commit c928ca1

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

crates/bevy_math/src/ops.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ mod std_ops {
140140
f32::atan(x)
141141
}
142142

143-
/// Computes the four quadrant arctangent of `self` (`y`) and `other` (`x`) in radians.
143+
/// Computes the four-quadrant arctangent of `y` and `x` in radians.
144144
///
145145
/// * `x = 0`, `y = 0`: `0`
146146
/// * `x >= 0`: `arctan(y/x)` -> `[-pi/2, pi/2]`
@@ -149,8 +149,8 @@ mod std_ops {
149149
///
150150
/// Precision is specified when the `libm` feature is enabled.
151151
#[inline(always)]
152-
pub fn atan2(x: f32, y: f32) -> f32 {
153-
f32::atan2(x, y)
152+
pub fn atan2(y: f32, x: f32) -> f32 {
153+
f32::atan2(y, x)
154154
}
155155

156156
/// Simultaneously computes the sine and cosine of the number, `x`. Returns
@@ -355,7 +355,7 @@ mod libm_ops {
355355
libm::atanf(x)
356356
}
357357

358-
/// Computes the four quadrant arctangent of `self` (`y`) and `other` (`x`) in radians.
358+
/// Computes the four-quadrant arctangent of `y` and `x` in radians.
359359
///
360360
/// * `x = 0`, `y = 0`: `0`
361361
/// * `x >= 0`: `arctan(y/x)` -> `[-pi/2, pi/2]`
@@ -364,8 +364,8 @@ mod libm_ops {
364364
///
365365
/// Precision is specified when the `libm` feature is enabled.
366366
#[inline(always)]
367-
pub fn atan2(x: f32, y: f32) -> f32 {
368-
libm::atan2f(x, y)
367+
pub fn atan2(y: f32, x: f32) -> f32 {
368+
libm::atan2f(y, x)
369369
}
370370

371371
/// Simultaneously computes the sine and cosine of the number, `x`. Returns

0 commit comments

Comments
 (0)