| | | 1 | | //======================================================================= |
| | | 2 | | // PlanarRotation.cs |
| | | 3 | | //======================================================================= |
| | | 4 | | // MIT License, Copyright (c) 2026–present David Oravsky (mrdav30) |
| | | 5 | | // See LICENSE file in the project root for full license information. |
| | | 6 | | //======================================================================= |
| | | 7 | | |
| | | 8 | | using FixedMathSharp; |
| | | 9 | | using System.Runtime.CompilerServices; |
| | | 10 | | |
| | | 11 | | namespace Gravitas; |
| | | 12 | | |
| | | 13 | | internal static class PlanarRotation |
| | | 14 | | { |
| | | 15 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 16 | | internal static Fixed64 Canonicalize(Fixed64 rotation) |
| | | 17 | | { |
| | 69529 | 18 | | if (rotation >= -Fixed64.Pi && rotation < Fixed64.Pi) |
| | 69419 | 19 | | return rotation; |
| | | 20 | | |
| | 110 | 21 | | rotation %= Fixed64.TwoPi; |
| | 110 | 22 | | if (rotation >= Fixed64.Pi) |
| | 74 | 23 | | return rotation - Fixed64.TwoPi; |
| | 36 | 24 | | if (rotation < -Fixed64.Pi) |
| | 6 | 25 | | return rotation + Fixed64.TwoPi; |
| | 30 | 26 | | return rotation; |
| | | 27 | | } |
| | | 28 | | |
| | | 29 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 30 | | internal static Fixed64 Combine(Fixed64 first, Fixed64 second) => |
| | 292 | 31 | | Canonicalize(Canonicalize(first) + Canonicalize(second)); |
| | | 32 | | } |