| | | 1 | | //======================================================================= |
| | | 2 | | // ColliderShapeSnapshot.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 FixedMathSharp; |
| | | 9 | | using System; |
| | | 10 | | using System.Runtime.CompilerServices; |
| | | 11 | | |
| | | 12 | | namespace Gravitas.Colliders; |
| | | 13 | | |
| | | 14 | | internal readonly struct ColliderShapeSnapshot : IEquatable<ColliderShapeSnapshot> |
| | | 15 | | { |
| | | 16 | | public ColliderShapeSnapshot( |
| | | 17 | | Vector3d center, |
| | | 18 | | FixedQuaternion rotation, |
| | | 19 | | Vector3d ownerScale, |
| | | 20 | | Vector3d partScale, |
| | | 21 | | Vector3d localOffset, |
| | | 22 | | Vector3d size, |
| | | 23 | | Fixed64 radius) |
| | | 24 | | { |
| | 75115 | 25 | | Center = center; |
| | 75115 | 26 | | Rotation = rotation; |
| | 75115 | 27 | | OwnerScale = ownerScale; |
| | 75115 | 28 | | PartScale = partScale; |
| | 75115 | 29 | | LocalOffset = localOffset; |
| | 75115 | 30 | | Size = size; |
| | 75115 | 31 | | Radius = radius; |
| | 75115 | 32 | | } |
| | | 33 | | |
| | | 34 | | public Vector3d Center { get; } |
| | | 35 | | |
| | | 36 | | public FixedQuaternion Rotation { get; } |
| | | 37 | | |
| | | 38 | | public Vector3d OwnerScale { get; } |
| | | 39 | | |
| | | 40 | | public Vector3d PartScale { get; } |
| | | 41 | | |
| | | 42 | | public Vector3d LocalOffset { get; } |
| | | 43 | | |
| | | 44 | | public Vector3d Size { get; } |
| | | 45 | | |
| | | 46 | | public Fixed64 Radius { get; } |
| | | 47 | | |
| | | 48 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 49 | | public bool Equals(ColliderShapeSnapshot other) => |
| | 62062 | 50 | | Center == other.Center |
| | 62062 | 51 | | && Rotation == other.Rotation |
| | 62062 | 52 | | && OwnerScale == other.OwnerScale |
| | 62062 | 53 | | && PartScale == other.PartScale |
| | 62062 | 54 | | && LocalOffset == other.LocalOffset |
| | 62062 | 55 | | && Size == other.Size |
| | 62062 | 56 | | && Radius == other.Radius; |
| | | 57 | | |
| | | 58 | | public override bool Equals(object? obj) => |
| | 4 | 59 | | obj is ColliderShapeSnapshot other && Equals(other); |
| | | 60 | | |
| | | 61 | | public override int GetHashCode() |
| | | 62 | | { |
| | | 63 | | unchecked |
| | | 64 | | { |
| | 2 | 65 | | int hash = 17; |
| | 2 | 66 | | hash = Mix(hash, Center); |
| | 2 | 67 | | hash = (hash * 31) + Rotation.X.GetHashCode(); |
| | 2 | 68 | | hash = (hash * 31) + Rotation.Y.GetHashCode(); |
| | 2 | 69 | | hash = (hash * 31) + Rotation.Z.GetHashCode(); |
| | 2 | 70 | | hash = (hash * 31) + Rotation.W.GetHashCode(); |
| | 2 | 71 | | hash = Mix(hash, OwnerScale); |
| | 2 | 72 | | hash = Mix(hash, PartScale); |
| | 2 | 73 | | hash = Mix(hash, LocalOffset); |
| | 2 | 74 | | hash = Mix(hash, Size); |
| | 2 | 75 | | hash = (hash * 31) + Radius.GetHashCode(); |
| | 2 | 76 | | return hash; |
| | | 77 | | } |
| | | 78 | | } |
| | | 79 | | |
| | | 80 | | private static int Mix(int hash, Vector3d value) |
| | | 81 | | { |
| | 10 | 82 | | hash = (hash * 31) + value.X.GetHashCode(); |
| | 10 | 83 | | hash = (hash * 31) + value.Y.GetHashCode(); |
| | 10 | 84 | | return (hash * 31) + value.Z.GetHashCode(); |
| | | 85 | | } |
| | | 86 | | |
| | 1 | 87 | | public static bool operator ==(ColliderShapeSnapshot left, ColliderShapeSnapshot right) => left.Equals(right); |
| | | 88 | | |
| | 2 | 89 | | public static bool operator !=(ColliderShapeSnapshot left, ColliderShapeSnapshot right) => !left.Equals(right); |
| | | 90 | | } |