| | | 1 | | //======================================================================= |
| | | 2 | | // ContactManifold2D.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.Collections; |
| | | 9 | | using System.Collections.Generic; |
| | | 10 | | using System.Runtime.CompilerServices; |
| | | 11 | | using FixedMathSharp; |
| | | 12 | | using Gravitas.Materials; |
| | | 13 | | |
| | | 14 | | namespace Gravitas.CollisionHandling; |
| | | 15 | | |
| | | 16 | | /// <summary> |
| | | 17 | | /// Pair-owned deterministic contact manifold with up to two samples per |
| | | 18 | | /// geometric surface group and no fixed pair-wide group or contact limit. |
| | | 19 | | /// </summary> |
| | | 20 | | /// <remarks> |
| | | 21 | | /// Inspection flattens canonical structural group order, then ascending contact |
| | | 22 | | /// identity within each group. Index zero is not necessarily the deepest contact; |
| | | 23 | | /// use <see cref="PrimaryContact"/> for that purpose. Overflow capacity is retained |
| | | 24 | | /// across updates and resets; reaching a new high-water mark can allocate. |
| | | 25 | | /// </remarks> |
| | | 26 | | public sealed partial class ContactManifold2D : IEnumerable<ManifoldContact2D> |
| | | 27 | | { |
| | | 28 | | /// <summary>Maximum number of point samples retained per geometric surface group.</summary> |
| | | 29 | | public const int MaxContactsPerGroup = 2; |
| | | 30 | | |
| | | 31 | | /// <summary>Maximum samples in the default group; independent groups have no pair-wide cap.</summary> |
| | | 32 | | public const int MaxContactCount = MaxContactsPerGroup; |
| | | 33 | | |
| | | 34 | | private ContactGroup2D _firstGroup; |
| | | 35 | | private SwiftCollections.SwiftList<ContactGroup2D>? _additionalGroups; |
| | | 36 | | private int _count; |
| | | 37 | | internal bool NeedsSurfaceRecovery; |
| | 1898 | 38 | | private long _lastUpdatedFrame = -1; |
| | | 39 | | |
| | | 40 | | /// <summary>Number of independent surface regions currently retained; this has no fixed pair-wide cap.</summary> |
| | | 41 | | public int GroupCount { get; private set; } |
| | | 42 | | |
| | | 43 | | /// <summary>Gets the first flattened point index of a group in canonical structural order.</summary> |
| | | 44 | | public int GetGroupStartIndex(int groupIndex) |
| | | 45 | | { |
| | 6 | 46 | | ChronicleGuard.ThrowIfListIndexInvalid(groupIndex, GroupCount); |
| | 6 | 47 | | int start = 0; |
| | 24 | 48 | | for (int i = 0; i < groupIndex; i++) |
| | 6 | 49 | | start += GetGroup(i).Count; |
| | 6 | 50 | | return start; |
| | | 51 | | } |
| | | 52 | | |
| | | 53 | | /// <summary>Gets the number of retained samples in a group, from one through <see cref="MaxContactsPerGroup"/>.</su |
| | | 54 | | public int GetGroupContactCount(int groupIndex) |
| | | 55 | | { |
| | 6 | 56 | | ChronicleGuard.ThrowIfListIndexInvalid(groupIndex, GroupCount); |
| | 6 | 57 | | return GetGroup(groupIndex).Count; |
| | | 58 | | } |
| | | 59 | | |
| | | 60 | | internal ref ContactGroup2D GetGroup(int index) |
| | | 61 | | { |
| | 163296 | 62 | | if (index == 0) return ref _firstGroup; |
| | 10748 | 63 | | return ref _additionalGroups!.InnerArray[index - 1]; |
| | | 64 | | } |
| | | 65 | | |
| | | 66 | | internal int FindGroup(in ContactGroupKey key) |
| | | 67 | | { |
| | 18810 | 68 | | int low = 0, high = GroupCount - 1; |
| | 9648 | 69 | | while (low <= high) |
| | | 70 | | { |
| | 9639 | 71 | | int middle = low + ((high - low) >> 1); |
| | 9639 | 72 | | int order = GetGroup(middle).Key.CompareTo(key); |
| | 19035 | 73 | | if (order == 0) return middle; |
| | 406 | 74 | | if (order < 0) low = middle + 1; |
| | 80 | 75 | | else high = middle - 1; |
| | | 76 | | } |
| | 9 | 77 | | return -1; |
| | | 78 | | } |
| | | 79 | | |
| | | 80 | | internal void ReserveGroups(int capacity) |
| | | 81 | | { |
| | 926 | 82 | | ChronicleGuard.ThrowIfNegative(capacity, nameof(capacity)); |
| | 1124 | 83 | | if (capacity <= 1) return; |
| | 728 | 84 | | _additionalGroups ??= new SwiftCollections.SwiftList<ContactGroup2D>(capacity - 1); |
| | 728 | 85 | | _additionalGroups.EnsureCapacity(capacity - 1); |
| | 728 | 86 | | } |
| | | 87 | | |
| | | 88 | | /// <summary> |
| | | 89 | | /// Total number of active samples across all groups, without a fixed pair-wide cap. |
| | | 90 | | /// </summary> |
| | | 91 | | public int Count |
| | | 92 | | { |
| | | 93 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | 14076 | 94 | | get => _count; |
| | | 95 | | } |
| | | 96 | | |
| | | 97 | | /// <summary> |
| | | 98 | | /// Gets whether this manifold currently contains narrow-phase contact data. |
| | | 99 | | /// </summary> |
| | | 100 | | public bool HasContact |
| | | 101 | | { |
| | | 102 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | 37331 | 103 | | get => _count > 0; |
| | | 104 | | } |
| | | 105 | | |
| | | 106 | | /// <summary> |
| | | 107 | | /// Simulation frame in which the active contacts were last rebuilt. |
| | | 108 | | /// </summary> |
| | | 109 | | public long LastUpdatedFrame |
| | | 110 | | { |
| | | 111 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | 6336 | 112 | | get => _lastUpdatedFrame; |
| | | 113 | | } |
| | | 114 | | |
| | | 115 | | /// <summary> |
| | | 116 | | /// Deepest contact in the manifold. Ties use the lowest contact identity. |
| | | 117 | | /// </summary> |
| | | 118 | | public ManifoldContact2D PrimaryContact |
| | | 119 | | { |
| | | 120 | | get |
| | | 121 | | { |
| | 180 | 122 | | ChronicleGuard.ThrowIfListIndexInvalid(0, _count); |
| | | 123 | | |
| | 180 | 124 | | ManifoldContact2D best = _firstGroup[0]; |
| | 776 | 125 | | foreach (ManifoldContact2D candidate in this) |
| | | 126 | | { |
| | 208 | 127 | | if (candidate.Depth > best.Depth |
| | 208 | 128 | | || candidate.Depth == best.Depth && (candidate.DepthIsClamped && !best.DepthIsClamped |
| | 208 | 129 | | || candidate.DepthIsClamped == best.DepthIsClamped && candidate.ContactId < best.ContactId)) |
| | | 130 | | { |
| | 4 | 131 | | best = candidate; |
| | | 132 | | } |
| | | 133 | | } |
| | | 134 | | |
| | 180 | 135 | | return best; |
| | | 136 | | } |
| | | 137 | | } |
| | | 138 | | |
| | | 139 | | /// <summary>Gets a contact in flattened structural-group/ascending-contact-identity order.</summary> |
| | | 140 | | public ManifoldContact2D this[int index] |
| | | 141 | | { |
| | | 142 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 143 | | get |
| | | 144 | | { |
| | 7172 | 145 | | ChronicleGuard.ThrowIfListIndexInvalid(index, _count); |
| | 7756 | 146 | | for (int group = 0; ; group++) |
| | | 147 | | { |
| | 7756 | 148 | | ref ContactGroup2D current = ref GetGroup(group); |
| | 14928 | 149 | | if (index < current.Count) return current[index]; |
| | 584 | 150 | | index -= current.Count; |
| | | 151 | | } |
| | | 152 | | } |
| | | 153 | | } |
| | | 154 | | |
| | | 155 | | /// <summary> |
| | | 156 | | /// Clears contacts and records the frame for a new narrow-phase pass. |
| | | 157 | | /// </summary> |
| | | 158 | | public void BeginUpdate(long frame) |
| | | 159 | | { |
| | 8066 | 160 | | ClearContacts(); |
| | 8066 | 161 | | _lastUpdatedFrame = frame; |
| | 8066 | 162 | | } |
| | | 163 | | |
| | | 164 | | /// <summary> |
| | | 165 | | /// Clears all contact data. |
| | | 166 | | /// </summary> |
| | | 167 | | public void Reset() |
| | | 168 | | { |
| | 3384 | 169 | | ClearContacts(); |
| | 3384 | 170 | | _lastUpdatedFrame = -1; |
| | 3384 | 171 | | } |
| | | 172 | | |
| | | 173 | | /// <summary> |
| | | 174 | | /// Replaces the manifold with one contact. |
| | | 175 | | /// </summary> |
| | | 176 | | public void SetContact(Vector2d pointA, Vector2d pointB, Fixed64 depth, Vector2d normal) |
| | | 177 | | { |
| | 151 | 178 | | ClearContacts(); |
| | 151 | 179 | | AddContact(pointA, pointB, depth, normal); |
| | 151 | 180 | | } |
| | | 181 | | |
| | | 182 | | /// <summary> |
| | | 183 | | /// Replaces the manifold with one rigid-frame contact. |
| | | 184 | | /// </summary> |
| | | 185 | | public void SetContact( |
| | | 186 | | ContactAnchor2D anchorA, |
| | | 187 | | ContactAnchor2D anchorB, |
| | | 188 | | Fixed64 depth, |
| | | 189 | | Vector2d normal, |
| | | 190 | | bool depthIsClamped = false) |
| | | 191 | | { |
| | 14 | 192 | | ClearContacts(); |
| | 14 | 193 | | AddContact(anchorA, anchorB, depth, normal, depthIsClamped); |
| | 14 | 194 | | } |
| | | 195 | | |
| | | 196 | | /// <summary> |
| | | 197 | | /// Adds a contact, keeping up to two samples in the default surface group and exposing them by stable contact ident |
| | | 198 | | /// </summary> |
| | | 199 | | public void AddContact(Vector2d pointA, Vector2d pointB, Fixed64 depth, Vector2d normal) |
| | | 200 | | { |
| | 218 | 201 | | AddContact( |
| | 218 | 202 | | ContactAnchor2D.FromWorldPoint(pointA), |
| | 218 | 203 | | ContactAnchor2D.FromWorldPoint(pointB), |
| | 218 | 204 | | depth, |
| | 218 | 205 | | normal); |
| | 218 | 206 | | } |
| | | 207 | | |
| | | 208 | | /// <summary> |
| | | 209 | | /// Adds a rigid-frame contact, keeping up to two samples in the default surface group and |
| | | 210 | | /// exposing them by stable anchor identity. |
| | | 211 | | /// </summary> |
| | | 212 | | public void AddContact( |
| | | 213 | | ContactAnchor2D anchorA, |
| | | 214 | | ContactAnchor2D anchorB, |
| | | 215 | | Fixed64 depth, |
| | | 216 | | Vector2d normal, |
| | | 217 | | bool depthIsClamped = false) |
| | | 218 | | { |
| | 239 | 219 | | AddContactCore( |
| | 239 | 220 | | anchorA, |
| | 239 | 221 | | anchorB, |
| | 239 | 222 | | depth, |
| | 239 | 223 | | normal, |
| | 239 | 224 | | hasMaterialOverride: false, |
| | 239 | 225 | | default, |
| | 239 | 226 | | default, |
| | 239 | 227 | | depthIsClamped, |
| | 239 | 228 | | featureNamespaceA: 0, |
| | 239 | 229 | | featureNamespaceB: 0); |
| | 239 | 230 | | } |
| | | 231 | | |
| | | 232 | | internal void AddContact( |
| | | 233 | | Vector2d pointA, |
| | | 234 | | Vector2d pointB, |
| | | 235 | | Fixed64 depth, |
| | | 236 | | Vector2d normal, |
| | | 237 | | PhysicsMaterial materialA, |
| | | 238 | | PhysicsMaterial materialB, |
| | | 239 | | bool depthIsClamped = false) |
| | | 240 | | { |
| | 2 | 241 | | AddContactCore( |
| | 2 | 242 | | ContactAnchor2D.FromWorldPoint(pointA), |
| | 2 | 243 | | ContactAnchor2D.FromWorldPoint(pointB), |
| | 2 | 244 | | depth, |
| | 2 | 245 | | normal, |
| | 2 | 246 | | hasMaterialOverride: true, |
| | 2 | 247 | | materialA, |
| | 2 | 248 | | materialB, |
| | 2 | 249 | | depthIsClamped, |
| | 2 | 250 | | featureNamespaceA: 0, |
| | 2 | 251 | | featureNamespaceB: 0); |
| | 2 | 252 | | } |
| | | 253 | | |
| | | 254 | | internal void AddContact( |
| | | 255 | | ContactAnchor2D anchorA, |
| | | 256 | | ContactAnchor2D anchorB, |
| | | 257 | | Fixed64 depth, |
| | | 258 | | Vector2d normal, |
| | | 259 | | PhysicsMaterial materialA, |
| | | 260 | | PhysicsMaterial materialB, |
| | | 261 | | bool depthIsClamped = false, |
| | | 262 | | int featureNamespaceA = 0, |
| | | 263 | | int featureNamespaceB = 0, |
| | | 264 | | ContactGroupKey group = default) |
| | | 265 | | { |
| | 10947 | 266 | | AddContactCore( |
| | 10947 | 267 | | anchorA, |
| | 10947 | 268 | | anchorB, |
| | 10947 | 269 | | depth, |
| | 10947 | 270 | | normal, |
| | 10947 | 271 | | hasMaterialOverride: true, |
| | 10947 | 272 | | materialA, |
| | 10947 | 273 | | materialB, |
| | 10947 | 274 | | depthIsClamped, |
| | 10947 | 275 | | featureNamespaceA, |
| | 10947 | 276 | | featureNamespaceB, |
| | 10947 | 277 | | group); |
| | 10947 | 278 | | } |
| | | 279 | | |
| | | 280 | | private void AddContactCore( |
| | | 281 | | ContactAnchor2D anchorA, |
| | | 282 | | ContactAnchor2D anchorB, |
| | | 283 | | Fixed64 depth, |
| | | 284 | | Vector2d normal, |
| | | 285 | | bool hasMaterialOverride, |
| | | 286 | | PhysicsMaterial materialA, |
| | | 287 | | PhysicsMaterial materialB, |
| | | 288 | | bool depthIsClamped, |
| | | 289 | | int featureNamespaceA, |
| | | 290 | | int featureNamespaceB, |
| | | 291 | | ContactGroupKey group = default) |
| | | 292 | | { |
| | 11188 | 293 | | ulong contactId = CreateContactId( |
| | 11188 | 294 | | anchorA, |
| | 11188 | 295 | | featureNamespaceA, |
| | 11188 | 296 | | anchorB, |
| | 11188 | 297 | | featureNamespaceB); |
| | 11188 | 298 | | var contact = new ManifoldContact2D( |
| | 11188 | 299 | | contactId, |
| | 11188 | 300 | | anchorA, |
| | 11188 | 301 | | anchorB, |
| | 11188 | 302 | | depth, |
| | 11188 | 303 | | normal, |
| | 11188 | 304 | | hasMaterialOverride, |
| | 11188 | 305 | | materialA, |
| | 11188 | 306 | | materialB, |
| | 11188 | 307 | | depthIsClamped, |
| | 11188 | 308 | | featureNamespaceA, |
| | 11188 | 309 | | featureNamespaceB); |
| | | 310 | | |
| | | 311 | | // Ordinary compound parts share the established two-sample owner pool; |
| | | 312 | | // only declared structural groups retain independent constraints. |
| | 11188 | 313 | | AddContact(group.CompareTo(default) == 0 ? default |
| | 11188 | 314 | | : group.Remap(featureNamespaceA, featureNamespaceB, reverse: false), contact); |
| | 11188 | 315 | | } |
| | | 316 | | |
| | | 317 | | internal void AddContact(in ContactGroupKey key, in ManifoldContact2D contact) |
| | | 318 | | { |
| | 11308 | 319 | | if (GroupCount == 0) |
| | | 320 | | { |
| | | 321 | | // BeginUpdate already cleared the inline group; avoid clearing its |
| | | 322 | | // two large anchors again on every ordinary first contact. |
| | 9046 | 323 | | _firstGroup.Key = key; |
| | 9046 | 324 | | _count = _firstGroup.Add(contact); |
| | 9046 | 325 | | GroupCount = 1; |
| | 9046 | 326 | | return; |
| | | 327 | | } |
| | 2262 | 328 | | int group = 0; |
| | 3557 | 329 | | while (group < GroupCount && GetGroup(group).Key.CompareTo(key) < 0) |
| | 1295 | 330 | | group++; |
| | 2262 | 331 | | if (group == GroupCount || GetGroup(group).Key.CompareTo(key) != 0) |
| | | 332 | | { |
| | 642 | 333 | | ReserveGroups(GroupCount + 1); |
| | 642 | 334 | | _additionalGroups!.Add(default); |
| | 1334 | 335 | | for (int i = GroupCount; i > group; i--) |
| | 25 | 336 | | GetGroup(i) = GetGroup(i - 1); |
| | 642 | 337 | | GetGroup(group) = new ContactGroup2D { Key = key }; |
| | 642 | 338 | | GroupCount++; |
| | | 339 | | } |
| | 2262 | 340 | | _count += GetGroup(group).Add(contact); |
| | 2262 | 341 | | } |
| | | 342 | | |
| | | 343 | | internal void CopyFrom(ContactManifold2D source, long frame) |
| | | 344 | | { |
| | 288 | 345 | | if (ReferenceEquals(this, source)) return; |
| | 284 | 346 | | BeginUpdate(frame); |
| | 284 | 347 | | ReserveGroups(source.GroupCount); |
| | 1546 | 348 | | for (int i = 0; i < source.GroupCount; i++) |
| | | 349 | | { |
| | 769 | 350 | | if (i == 0) _firstGroup = source.GetGroup(i); |
| | 209 | 351 | | else _additionalGroups!.Add(source.GetGroup(i)); |
| | | 352 | | } |
| | 284 | 353 | | GroupCount = source.GroupCount; |
| | 284 | 354 | | _count = source._count; |
| | 284 | 355 | | NeedsSurfaceRecovery = source.NeedsSurfaceRecovery; |
| | 284 | 356 | | } |
| | | 357 | | |
| | | 358 | | internal bool HasSameContacts(ContactManifold2D source) |
| | | 359 | | { |
| | 51 | 360 | | if (GroupCount != source.GroupCount || NeedsSurfaceRecovery != source.NeedsSurfaceRecovery) return false; |
| | 100 | 361 | | for (int group = 0; group < GroupCount; group++) |
| | | 362 | | { |
| | 39 | 363 | | ref ContactGroup2D previous = ref GetGroup(group); |
| | 39 | 364 | | ref ContactGroup2D incoming = ref source.GetGroup(group); |
| | 43 | 365 | | if (previous.Key.CompareTo(incoming.Key) != 0 || previous.Count != incoming.Count) return false; |
| | 88 | 366 | | for (int index = 0; index < previous.Count; index++) |
| | 61 | 367 | | if (!SameConstraint(previous[index], incoming[index])) return false; |
| | | 368 | | } |
| | 11 | 369 | | return true; |
| | | 370 | | } |
| | | 371 | | |
| | | 372 | | private static bool SameConstraint(in ManifoldContact2D previous, in ManifoldContact2D incoming) => |
| | 35 | 373 | | previous.ContactId == incoming.ContactId && previous.FeatureNamespaceA == incoming.FeatureNamespaceA |
| | 35 | 374 | | && previous.FeatureNamespaceB == incoming.FeatureNamespaceB && previous.Normal == incoming.Normal |
| | 35 | 375 | | && previous.Depth == incoming.Depth && previous.DepthIsClamped == incoming.DepthIsClamped |
| | 35 | 376 | | && previous.HasMaterialOverride == incoming.HasMaterialOverride |
| | 35 | 377 | | && previous.MaterialA == incoming.MaterialA && previous.MaterialB == incoming.MaterialB |
| | 35 | 378 | | && SamePoint(previous.AnchorA, incoming.AnchorA) && SamePoint(previous.AnchorB, incoming.AnchorB); |
| | | 379 | | |
| | | 380 | | private static bool SamePoint(in ContactAnchor2D previous, in ContactAnchor2D incoming) |
| | | 381 | | { |
| | 30 | 382 | | ExactLever3D delta = previous.GetXZLeverFrom(incoming); |
| | 30 | 383 | | return delta.XNumerator.IsZero && delta.ZNumerator.IsZero; |
| | | 384 | | } |
| | | 385 | | |
| | | 386 | | internal bool ReferencesSuppliers(SwiftCollections.SwiftHashSet<int> suppliers, bool first, int fallbackSource) |
| | | 387 | | { |
| | 164 | 388 | | for (int group = 0; group < GroupCount; group++) |
| | | 389 | | { |
| | 68 | 390 | | ContactGroupKey key = GetGroup(group).Key; |
| | 68 | 391 | | int source = first ? key.SourceIdA : key.SourceIdB; |
| | 128 | 392 | | if (suppliers.Contains(source == 0 ? fallbackSource : source)) return true; |
| | | 393 | | } |
| | 14 | 394 | | return false; |
| | | 395 | | } |
| | | 396 | | |
| | | 397 | | private void ClearContacts() |
| | | 398 | | { |
| | 11615 | 399 | | _count = GroupCount = 0; |
| | 11615 | 400 | | NeedsSurfaceRecovery = false; |
| | 11615 | 401 | | _firstGroup = default; |
| | 11615 | 402 | | _additionalGroups?.FastClear(); |
| | 1764 | 403 | | } |
| | | 404 | | |
| | | 405 | | /// <summary>Returns an allocation-free enumerator over the active contacts.</summary> |
| | 511 | 406 | | public Enumerator GetEnumerator() => new(this); |
| | | 407 | | |
| | 107 | 408 | | IEnumerator<ManifoldContact2D> IEnumerable<ManifoldContact2D>.GetEnumerator() => GetEnumerator(); |
| | 10 | 409 | | IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); |
| | | 410 | | |
| | | 411 | | private static ulong CreateContactId( |
| | | 412 | | ContactAnchor2D anchorA, |
| | | 413 | | int featureNamespaceA, |
| | | 414 | | ContactAnchor2D anchorB, |
| | | 415 | | int featureNamespaceB) |
| | | 416 | | { |
| | 11188 | 417 | | if (CompareLocalFeature( |
| | 11188 | 418 | | featureNamespaceB, |
| | 11188 | 419 | | anchorB, |
| | 11188 | 420 | | featureNamespaceA, |
| | 11188 | 421 | | anchorA) < 0) |
| | | 422 | | { |
| | 6416 | 423 | | (anchorA, anchorB) = (anchorB, anchorA); |
| | 6416 | 424 | | (featureNamespaceA, featureNamespaceB) = |
| | 6416 | 425 | | (featureNamespaceB, featureNamespaceA); |
| | | 426 | | } |
| | | 427 | | |
| | 11188 | 428 | | ulong hash = 14695981039346656037UL; |
| | 11188 | 429 | | Mix(ref hash, featureNamespaceA); |
| | 11188 | 430 | | MixLocalFeature(ref hash, anchorA); |
| | 11188 | 431 | | Mix(ref hash, featureNamespaceB); |
| | 11188 | 432 | | MixLocalFeature(ref hash, anchorB); |
| | 11188 | 433 | | return hash; |
| | | 434 | | } |
| | | 435 | | |
| | | 436 | | private static int CompareLocalFeature( |
| | | 437 | | int leftNamespace, |
| | | 438 | | ContactAnchor2D left, |
| | | 439 | | int rightNamespace, |
| | | 440 | | ContactAnchor2D right) |
| | | 441 | | { |
| | 11188 | 442 | | int comparison = leftNamespace.CompareTo(rightNamespace); |
| | 11188 | 443 | | return comparison != 0 |
| | 11188 | 444 | | ? comparison |
| | 11188 | 445 | | : left.CompareLocalFeature(right); |
| | | 446 | | } |
| | | 447 | | |
| | | 448 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 449 | | private static void Mix(ref ulong hash, long value) |
| | | 450 | | { |
| | | 451 | | unchecked |
| | | 452 | | { |
| | 44752 | 453 | | hash ^= (ulong)value; |
| | 44752 | 454 | | hash *= 1099511628211UL; |
| | | 455 | | } |
| | 44752 | 456 | | } |
| | | 457 | | |
| | | 458 | | private static void MixLocalFeature( |
| | | 459 | | ref ulong hash, |
| | | 460 | | ContactAnchor2D anchor) |
| | | 461 | | { |
| | 22376 | 462 | | Mix( |
| | 22376 | 463 | | ref hash, |
| | 22376 | 464 | | unchecked((long)anchor.GetLocalFeatureHash64())); |
| | 22376 | 465 | | } |
| | | 466 | | |
| | | 467 | | |
| | | 468 | | } |