Move duplication logic for positions into commons

This commit is contained in:
Liza 2023-02-07 21:25:09 +01:00
parent 53bd00285b
commit 136774eb71
2 changed files with 20 additions and 2 deletions

View File

@ -1,4 +1,5 @@
using ECommons.SplatoonAPI; using ECommons.SplatoonAPI;
using Pal.Common;
using Palace; using Palace;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@ -67,12 +68,12 @@ namespace Pal.Client
public override int GetHashCode() 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) 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) public static bool operator ==(Marker? a, object? b)

17
Pal.Common/PalaceMath.cs Normal file
View File

@ -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);
}
}
}