Merge pull request #292 from corwinkuiper/fix-fast-normalise

take absolute values of the x, y coordinate
This commit is contained in:
Corwin 2022-08-08 19:45:22 +01:00 committed by GitHub
commit 3dda6fb0da
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 2 deletions

View file

@ -10,6 +10,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Custom allocator support using the `Allocator` trait for `HashMap`. This means the `HashMap` can be used with `InternalAllocator` to allocate to IWRAM or the `ExternalAllocator` to explicitly allocate to EWRAM.
- Support for using windows on the GBA. Windows are used to selectively enable rendering of certain layers or effects.
## Fixed
- Fixed the fast magnitude function in agb_fixnum. This is also used in fast_normalise. Previously only worked for positive (x, y).
## [0.11.1] - 2022/08/02
Version 0.11.1 brings documentation for fixed point numbers. We recommend all users upgrade to this version since it also includes fixes to a few functions in fixnum. See changed section for breaking changes.

View file

@ -693,8 +693,8 @@ impl<const N: usize> Vector2D<Num<i32, N>> {
/// ```
#[must_use]
pub fn fast_magnitude(self) -> Num<i32, N> {
let max = core::cmp::max(self.x, self.y);
let min = core::cmp::min(self.x, self.y);
let max = core::cmp::max(self.x.abs(), self.y.abs());
let min = core::cmp::min(self.x.abs(), self.y.abs());
max * num!(0.960433870103) + min * num!(0.397824734759)
}