| | | 1 | | //======================================================================= |
| | | 2 | | // ColliderShapeSnapshot2D.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; |
| | | 9 | | using System.Runtime.CompilerServices; |
| | | 10 | | using FixedMathSharp; |
| | | 11 | | |
| | | 12 | | namespace Gravitas.Colliders; |
| | | 13 | | |
| | | 14 | | /// <summary> |
| | | 15 | | /// Captures the planar pose, shape version, and mixed slab inputs used to track geometry changes. |
| | | 16 | | /// </summary> |
| | | 17 | | internal readonly struct ColliderShapeSnapshot2D : IEquatable<ColliderShapeSnapshot2D> |
| | | 18 | | { |
| | | 19 | | public ColliderShapeSnapshot2D( |
| | | 20 | | Vector2d center, |
| | | 21 | | Fixed64 rotation, |
| | | 22 | | Vector2d ownerScale, |
| | | 23 | | Vector2d partScale, |
| | | 24 | | Vector2d localOffset, |
| | | 25 | | uint shapeVersion, |
| | | 26 | | Fixed64 mixedSlabCenterY, |
| | | 27 | | Fixed64 mixedHalfThickness) |
| | | 28 | | { |
| | 97447 | 29 | | Center = center; |
| | 97447 | 30 | | Rotation = rotation; |
| | 97447 | 31 | | OwnerScale = ownerScale; |
| | 97447 | 32 | | PartScale = partScale; |
| | 97447 | 33 | | LocalOffset = localOffset; |
| | 97447 | 34 | | ShapeVersion = shapeVersion; |
| | 97447 | 35 | | MixedSlabCenterY = mixedSlabCenterY; |
| | 97447 | 36 | | MixedHalfThickness = mixedHalfThickness; |
| | 97447 | 37 | | } |
| | | 38 | | |
| | | 39 | | public Vector2d Center { get; } |
| | | 40 | | |
| | | 41 | | public Fixed64 Rotation { get; } |
| | | 42 | | |
| | | 43 | | public Vector2d OwnerScale { get; } |
| | | 44 | | |
| | | 45 | | public Vector2d PartScale { get; } |
| | | 46 | | |
| | | 47 | | public Vector2d LocalOffset { get; } |
| | | 48 | | |
| | | 49 | | public uint ShapeVersion { get; } |
| | | 50 | | |
| | | 51 | | public Fixed64 MixedSlabCenterY { get; } |
| | | 52 | | |
| | | 53 | | public Fixed64 MixedHalfThickness { get; } |
| | | 54 | | |
| | | 55 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 56 | | public bool Equals(ColliderShapeSnapshot2D other) => |
| | 65772 | 57 | | Center == other.Center |
| | 65772 | 58 | | && Rotation == other.Rotation |
| | 65772 | 59 | | && OwnerScale == other.OwnerScale |
| | 65772 | 60 | | && PartScale == other.PartScale |
| | 65772 | 61 | | && LocalOffset == other.LocalOffset |
| | 65772 | 62 | | && ShapeVersion == other.ShapeVersion |
| | 65772 | 63 | | && MixedSlabCenterY == other.MixedSlabCenterY |
| | 65772 | 64 | | && MixedHalfThickness == other.MixedHalfThickness; |
| | | 65 | | |
| | | 66 | | public override bool Equals(object? obj) => |
| | 4 | 67 | | obj is ColliderShapeSnapshot2D other && Equals(other); |
| | | 68 | | |
| | | 69 | | public override int GetHashCode() |
| | | 70 | | { |
| | | 71 | | unchecked |
| | | 72 | | { |
| | 2 | 73 | | int hash = 17; |
| | 2 | 74 | | hash = hash * 31 + Center.X.GetHashCode(); |
| | 2 | 75 | | hash = hash * 31 + Center.Y.GetHashCode(); |
| | 2 | 76 | | hash = hash * 31 + Rotation.GetHashCode(); |
| | 2 | 77 | | hash = hash * 31 + OwnerScale.X.GetHashCode(); |
| | 2 | 78 | | hash = hash * 31 + OwnerScale.Y.GetHashCode(); |
| | 2 | 79 | | hash = hash * 31 + PartScale.X.GetHashCode(); |
| | 2 | 80 | | hash = hash * 31 + PartScale.Y.GetHashCode(); |
| | 2 | 81 | | hash = hash * 31 + LocalOffset.X.GetHashCode(); |
| | 2 | 82 | | hash = hash * 31 + LocalOffset.Y.GetHashCode(); |
| | 2 | 83 | | hash = hash * 31 + ShapeVersion.GetHashCode(); |
| | 2 | 84 | | hash = hash * 31 + MixedSlabCenterY.GetHashCode(); |
| | 2 | 85 | | hash = hash * 31 + MixedHalfThickness.GetHashCode(); |
| | 2 | 86 | | return hash; |
| | | 87 | | } |
| | | 88 | | } |
| | | 89 | | } |