| | | 1 | | //======================================================================= |
| | | 2 | | // WidePointSpanPenetration.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 | | /// Retains one exact point-span SAT penetration for ranking and materialization. |
| | | 12 | | /// </summary> |
| | | 13 | | internal readonly struct WidePointSpanPenetration |
| | | 14 | | { |
| | | 15 | | internal readonly WideAxis3 Axis; |
| | | 16 | | internal readonly bool Negate; |
| | | 17 | | internal readonly Signed576 ExactOverlap; |
| | | 18 | | internal readonly Signed576 ExactSquaredAxisLength; |
| | | 19 | | internal readonly Signed320 ExactCommonDenominator; |
| | | 20 | | |
| | | 21 | | internal WidePointSpanPenetration( |
| | | 22 | | WideAxis3 axis, |
| | | 23 | | bool negate, |
| | | 24 | | Signed576 exactOverlap, |
| | | 25 | | Signed576 exactSquaredAxisLength, |
| | | 26 | | Signed320 exactCommonDenominator) |
| | | 27 | | { |
| | 978 | 28 | | Axis = axis; |
| | 978 | 29 | | Negate = negate; |
| | 978 | 30 | | ExactOverlap = exactOverlap; |
| | 978 | 31 | | ExactSquaredAxisLength = exactSquaredAxisLength; |
| | 978 | 32 | | ExactCommonDenominator = exactCommonDenominator; |
| | 978 | 33 | | HasValue = true; |
| | 978 | 34 | | } |
| | | 35 | | |
| | | 36 | | internal bool HasValue { get; } |
| | | 37 | | |
| | | 38 | | internal bool ShouldReplace( |
| | | 39 | | Signed576 overlap, |
| | | 40 | | Signed576 squaredAxisLength, |
| | | 41 | | Signed320 commonDenominator) |
| | | 42 | | { |
| | 9391 | 43 | | if (!HasValue) |
| | 409 | 44 | | return true; |
| | 8982 | 45 | | return WideArithmetic.CompareNonNegativeNormalizedDepths( |
| | 8982 | 46 | | overlap, |
| | 8982 | 47 | | squaredAxisLength, |
| | 8982 | 48 | | commonDenominator, |
| | 8982 | 49 | | ExactOverlap, |
| | 8982 | 50 | | ExactSquaredAxisLength, |
| | 8982 | 51 | | ExactCommonDenominator) < 0; |
| | | 52 | | } |
| | | 53 | | |
| | | 54 | | internal Fixed64 GetRoundedDepth(out bool isClamped) => |
| | 381 | 55 | | WideArithmetic.GetRoundedNonNegativeNormalizedDepth( |
| | 381 | 56 | | ExactOverlap, |
| | 381 | 57 | | ExactSquaredAxisLength, |
| | 381 | 58 | | ExactCommonDenominator, |
| | 381 | 59 | | out isClamped); |
| | | 60 | | } |