| | | 1 | | //======================================================================= |
| | | 2 | | // ContactSelectionPolicy.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 System.Runtime.CompilerServices; |
| | | 9 | | |
| | | 10 | | namespace Gravitas.CollisionHandling; |
| | | 11 | | |
| | | 12 | | /// <summary> |
| | | 13 | | /// Selects contact candidates by penetration depth, accounting for clamped values on ties. |
| | | 14 | | /// </summary> |
| | | 15 | | internal static class ContactSelectionPolicy |
| | | 16 | | { |
| | | 17 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 18 | | internal static bool ShouldReplaceWithDeeper(Contact2D candidate, bool found, Contact2D current) => |
| | 65 | 19 | | !found |
| | 65 | 20 | | || candidate.Depth > current.Depth |
| | 65 | 21 | | || (candidate.Depth == current.Depth |
| | 65 | 22 | | && candidate.DepthIsClamped |
| | 65 | 23 | | && !current.DepthIsClamped); |
| | | 24 | | |
| | | 25 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 26 | | internal static bool ShouldReplaceWithShallower(MixedContact candidate, bool found, MixedContact current) => |
| | 6 | 27 | | !found |
| | 6 | 28 | | || candidate.Depth < current.Depth |
| | 6 | 29 | | || (candidate.Depth == current.Depth |
| | 6 | 30 | | && current.DepthIsClamped |
| | 6 | 31 | | && !candidate.DepthIsClamped); |
| | | 32 | | } |