| | | 1 | | //======================================================================= |
| | | 2 | | // WideAxis3.cs |
| | | 3 | | //======================================================================= |
| | | 4 | | // MIT License, Copyright (c) 2024-present David Oravsky (mrdav30) |
| | | 5 | | // See LICENSE file in the project root for full license information. |
| | | 6 | | //======================================================================= |
| | | 7 | | |
| | | 8 | | namespace FixedMathSharp.Geometry; |
| | | 9 | | |
| | | 10 | | /// <summary> |
| | | 11 | | /// Stores an exact three-component axis used by rigid wide geometry. |
| | | 12 | | /// </summary> |
| | | 13 | | internal readonly struct WideAxis3 |
| | | 14 | | { |
| | | 15 | | internal readonly Signed320 X; |
| | | 16 | | internal readonly Signed320 Y; |
| | | 17 | | internal readonly Signed320 Z; |
| | | 18 | | |
| | | 19 | | internal WideAxis3(Signed320 x, Signed320 y, Signed320 z) |
| | | 20 | | { |
| | 1483446 | 21 | | X = x; |
| | 1483446 | 22 | | Y = y; |
| | 1483446 | 23 | | Z = z; |
| | 1483446 | 24 | | } |
| | | 25 | | |
| | 39980 | 26 | | internal bool IsZero => X.IsZero && Y.IsZero && Z.IsZero; |
| | | 27 | | |
| | | 28 | | internal Signed576 SquaredLength => |
| | 146205 | 29 | | WideArithmetic.AddSigned576( |
| | 146205 | 30 | | WideArithmetic.AddSigned576( |
| | 146205 | 31 | | WideArithmetic.MultiplySigned320(X, X), |
| | 146205 | 32 | | WideArithmetic.MultiplySigned320(Y, Y)), |
| | 146205 | 33 | | WideArithmetic.MultiplySigned320(Z, Z)); |
| | | 34 | | |
| | | 35 | | internal static WideAxis3 Cross(in WideAxis3 left, in WideAxis3 right) => |
| | 53836 | 36 | | new( |
| | 53836 | 37 | | Signed320.NarrowValue(WideArithmetic.SubtractSigned576( |
| | 53836 | 38 | | WideArithmetic.MultiplySigned320(left.Y, right.Z), |
| | 53836 | 39 | | WideArithmetic.MultiplySigned320(left.Z, right.Y))), |
| | 53836 | 40 | | Signed320.NarrowValue(WideArithmetic.SubtractSigned576( |
| | 53836 | 41 | | WideArithmetic.MultiplySigned320(left.Z, right.X), |
| | 53836 | 42 | | WideArithmetic.MultiplySigned320(left.X, right.Z))), |
| | 53836 | 43 | | Signed320.NarrowValue(WideArithmetic.SubtractSigned576( |
| | 53836 | 44 | | WideArithmetic.MultiplySigned320(left.X, right.Y), |
| | 53836 | 45 | | WideArithmetic.MultiplySigned320(left.Y, right.X)))); |
| | | 46 | | |
| | | 47 | | // Equality needs the complete cross products, even when the resulting |
| | | 48 | | // direction would not fit this owner's Signed320 component storage. |
| | | 49 | | internal static bool AreParallel(in WideAxis3 left, in WideAxis3 right) => |
| | 15 | 50 | | WideArithmetic.SubtractSigned704(WideArithmetic.MultiplySigned576ToSigned704(Signed576.ExtendValue(left.Y), righ |
| | 15 | 51 | | WideArithmetic.MultiplySigned576ToSigned704(Signed576.ExtendValue(left.Z), right.Y)).IsZero |
| | 15 | 52 | | && WideArithmetic.SubtractSigned704(WideArithmetic.MultiplySigned576ToSigned704(Signed576.ExtendValue(left.Z), r |
| | 15 | 53 | | WideArithmetic.MultiplySigned576ToSigned704(Signed576.ExtendValue(left.X), right.Z)).IsZero |
| | 15 | 54 | | && WideArithmetic.SubtractSigned704(WideArithmetic.MultiplySigned576ToSigned704(Signed576.ExtendValue(left.X), r |
| | 15 | 55 | | WideArithmetic.MultiplySigned576ToSigned704(Signed576.ExtendValue(left.Y), right.X)).IsZero; |
| | | 56 | | |
| | | 57 | | internal static Signed576 Dot(in WideAxis3 left, in WideAxis3 right) => |
| | 157342 | 58 | | WideArithmetic.AddSigned576( |
| | 157342 | 59 | | WideArithmetic.AddSigned576( |
| | 157342 | 60 | | WideArithmetic.MultiplySigned320(left.X, right.X), |
| | 157342 | 61 | | WideArithmetic.MultiplySigned320(left.Y, right.Y)), |
| | 157342 | 62 | | WideArithmetic.MultiplySigned320(left.Z, right.Z)); |
| | | 63 | | |
| | | 64 | | public static WideAxis3 operator -(WideAxis3 value) => |
| | 1011 | 65 | | new( |
| | 1011 | 66 | | WideArithmetic.SubtractSigned320(default, value.X), |
| | 1011 | 67 | | WideArithmetic.SubtractSigned320(default, value.Y), |
| | 1011 | 68 | | WideArithmetic.SubtractSigned320(default, value.Z)); |
| | | 69 | | } |