From 136774eb71e0dd02141c9511a216a530d9640d13 Mon Sep 17 00:00:00 2001 From: Liza Carvelli Date: Tue, 7 Feb 2023 21:25:09 +0100 Subject: [PATCH] Move duplication logic for positions into commons --- Pal.Client/Marker.cs | 5 +++-- Pal.Common/PalaceMath.cs | 17 +++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 Pal.Common/PalaceMath.cs diff --git a/Pal.Client/Marker.cs b/Pal.Client/Marker.cs index a212973..29f4932 100644 --- a/Pal.Client/Marker.cs +++ b/Pal.Client/Marker.cs @@ -1,4 +1,5 @@ using ECommons.SplatoonAPI; +using Pal.Common; using Palace; using System; using System.Collections.Generic; @@ -67,12 +68,12 @@ namespace Pal.Client public override int GetHashCode() { - return HashCode.Combine(Type, (int)Position.X, (int)Position.Y, (int)Position.Z); + return HashCode.Combine(Type, PalaceMath.GetHashCode(Position)); } public override bool Equals(object? obj) { - return obj is Marker otherMarker && Type == otherMarker.Type && (int)Position.X == (int)otherMarker.Position.X && (int)Position.Y == (int)otherMarker.Position.Y && (int)Position.Z == (int)otherMarker.Position.Z; + return obj is Marker otherMarker && Type == otherMarker.Type && PalaceMath.IsNearlySamePosition(Position, otherMarker.Position); } public static bool operator ==(Marker? a, object? b) diff --git a/Pal.Common/PalaceMath.cs b/Pal.Common/PalaceMath.cs new file mode 100644 index 0000000..2a7636e --- /dev/null +++ b/Pal.Common/PalaceMath.cs @@ -0,0 +1,17 @@ +using System.Numerics; + +namespace Pal.Common +{ + public class PalaceMath + { + public static bool IsNearlySamePosition(Vector3 a, Vector3 b) + { + return (int)a.X == (int)b.X && (int)a.Y == (int)b.Y && (int)a.Z == (int)b.Z; + } + + public static int GetHashCode(Vector3 v) + { + return HashCode.Combine((int)v.X, (int)v.Y, (int)v.Z); + } + } +}