| | | 1 | | //======================================================================= |
| | | 2 | | // WideScaledHullPenetration.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 | | using System; |
| | | 9 | | |
| | | 10 | | namespace FixedMathSharp.Geometry; |
| | | 11 | | |
| | | 12 | | /// <summary>Exact signed exit retained before materializing a scaled hull's final contact.</summary> |
| | | 13 | | internal readonly struct WideScaledHullPenetration |
| | | 14 | | { |
| | | 15 | | internal readonly WideDirection3d Axis; |
| | | 16 | | internal readonly Signed832 Overlap, SquaredAxisLength; |
| | | 17 | | internal readonly Signed576 CommonDenominator; |
| | | 18 | | internal readonly bool Negate; |
| | | 19 | | internal bool HasValue { get; } |
| | | 20 | | internal WideScaledHullPenetration(WideDirection3d axis, bool negate, Signed832 overlap, |
| | | 21 | | Signed832 squaredAxisLength, Signed576 commonDenominator) |
| | | 22 | | { |
| | 644 | 23 | | Axis = axis; Negate = negate; Overlap = overlap; SquaredAxisLength = squaredAxisLength; |
| | 322 | 24 | | CommonDenominator = commonDenominator; HasValue = true; |
| | 161 | 25 | | } |
| | | 26 | | internal WideScaledHullPenetration(in WidePointSpanPenetration value) |
| | | 27 | | { |
| | 6 | 28 | | Axis = new(value.Axis); Negate = value.Negate; |
| | 3 | 29 | | Overlap = Signed832.ExtendValue(value.ExactOverlap); |
| | 3 | 30 | | SquaredAxisLength = Signed832.ExtendValue(value.ExactSquaredAxisLength); |
| | 3 | 31 | | CommonDenominator = Signed576.ExtendValue(value.ExactCommonDenominator); |
| | 3 | 32 | | HasValue = value.HasValue; |
| | 3 | 33 | | } |
| | | 34 | | internal bool ShouldReplace(Signed832 overlap, Signed832 squaredAxisLength, Signed576 denominator) => |
| | 7539 | 35 | | !HasValue || WideArithmetic.CompareNonNegativeNormalizedDepths(overlap, squaredAxisLength, denominator, |
| | 7539 | 36 | | Overlap, SquaredAxisLength, CommonDenominator) < 0; |
| | 10 | 37 | | internal Vector3d GetNormal() => Axis.GetNormal(Negate); |
| | 98 | 38 | | internal Fixed64 GetRoundedDepth(out bool isClamped) => WideArithmetic.GetRoundedNonNegativeNormalizedDepth( |
| | 98 | 39 | | Overlap, SquaredAxisLength, CommonDenominator, out isClamped); |
| | | 40 | | } |