| | | 1 | | //======================================================================= |
| | | 2 | | // CurvedPrismContactSelection.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>One exactly ranked curved support feature against the complete prism.</summary> |
| | | 13 | | internal ref struct CurvedPrismContactSelection |
| | | 14 | | { |
| | | 15 | | internal const int Bottom = -1, Free = 0, Top = 1; |
| | | 16 | | internal readonly Span<ulong> Values; |
| | | 17 | | internal readonly Span<int> Signs; |
| | | 18 | | internal int GapSign, Vertex, Feature; |
| | | 19 | | internal bool HasValue; |
| | | 20 | | internal int Window, Certificate; |
| | | 21 | | internal readonly PrismCurvedContactDomain Domain; |
| | | 22 | | |
| | | 23 | | internal CurvedPrismContactSelection(Span<ulong> values, Span<int> signs) |
| | | 24 | | { |
| | 3998 | 25 | | Values = values; Signs = signs; |
| | 7996 | 26 | | GapSign = Vertex = Feature = Window = 0; HasValue = false; Certificate = -1; Domain = default; |
| | 1999 | 27 | | } |
| | | 28 | | |
| | | 29 | | internal CurvedPrismContactSelection(Span<ulong> values, Span<int> signs, PrismCurvedContactDomain domain) |
| | 192 | 30 | | : this(values, signs) { Domain = domain; } |
| | | 31 | | |
| | 15965 | 32 | | internal readonly ConvexContactCandidate Candidate => new(Values, Signs, GapSign); |
| | | 33 | | |
| | | 34 | | internal void Keep(in CurvedPrismContactGeometry geometry, scoped ReadOnlySpan<ulong> values, scoped ReadOnlySpan<in |
| | | 35 | | int gapSign, int vertex, int feature, int fieldWords = ConvexContactCandidate.Words) |
| | | 36 | | { |
| | | 37 | | System.Diagnostics.Debug.Assert(!Domain.Enabled || fieldWords == ConvexContactCandidate.Words); |
| | 18039 | 38 | | if (HasValue && WideConvexPrismRelations.CompareConvexContactCandidates( |
| | 18039 | 39 | | new ConvexContactCandidate(values, signs, gapSign, fieldWords), Candidate) >= 0) |
| | 14211 | 40 | | return; |
| | 7656 | 41 | | int window = 0, certificate = -1; |
| | 3828 | 42 | | if (Domain.Enabled && !CurvedPrismContact.TryAdmitAnalyticCandidate(geometry, Domain, values, signs, |
| | 5944 | 43 | | gapSign, vertex, feature, out window, out certificate)) return; |
| | 1787 | 44 | | if (fieldWords == ConvexContactCandidate.Words) values.CopyTo(Values); |
| | 1637 | 45 | | else CopyPadded(values, fieldWords, Values); |
| | 5136 | 46 | | signs.CopyTo(Signs); Window = window; Certificate = certificate; |
| | 6848 | 47 | | GapSign = gapSign; Vertex = vertex; Feature = feature; HasValue = true; |
| | 1712 | 48 | | } |
| | | 49 | | private static void CopyPadded(scoped ReadOnlySpan<ulong> source, int words, scoped Span<ulong> target) |
| | | 50 | | { |
| | 1637 | 51 | | target.Clear(); |
| | 39288 | 52 | | for (int slot = 0; slot < ConvexContactCandidate.Slots; slot++) |
| | 18007 | 53 | | source.Slice(slot * words, words).CopyTo(target.Slice(slot * ConvexContactCandidate.Words, words)); |
| | 1637 | 54 | | } |
| | | 55 | | |
| | | 56 | | } |