Port NBT impl from LibAC Dart
This commit is contained in:
parent
0a022634c1
commit
ad7b619706
55 changed files with 3226 additions and 2983 deletions
96
Utilities/Vector3d.cs
Normal file
96
Utilities/Vector3d.cs
Normal file
|
@ -0,0 +1,96 @@
|
|||
using System;
|
||||
|
||||
namespace LibAC.Utilities
|
||||
{
|
||||
public class Vector3d
|
||||
{
|
||||
public static readonly Vector3d ZERO = new Vector3d(0, 0, 0);
|
||||
public double X { get; set; }
|
||||
public double Y { get; set; }
|
||||
public double Z { get; set; }
|
||||
|
||||
public Vector3d(double X = 0.0, double Y = 0.0, double Z = 0.0)
|
||||
{
|
||||
this.X = X;
|
||||
this.Y = Y;
|
||||
this.Z = Z;
|
||||
}
|
||||
|
||||
public override bool Equals(object other)
|
||||
{
|
||||
if (other is Vector3d)
|
||||
{
|
||||
Vector3d otherVector = (Vector3d)other;
|
||||
return X == otherVector.X && Y == otherVector.Y && Z == otherVector.Z;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static Vector3d operator +(Vector3d v1, Vector3d v2)
|
||||
{
|
||||
Vector3d result = v1.Clone();
|
||||
result.X += v2.X;
|
||||
result.Y += v2.Y;
|
||||
result.Z += v2.Z;
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Vector3d operator -(Vector3d v1, Vector3d v2)
|
||||
{
|
||||
Vector3d result = v1.Clone();
|
||||
result.X -= v2.X;
|
||||
result.Y -= v2.Y;
|
||||
result.Z -= v2.Z;
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Vector3d operator *(Vector3d v1, Vector3d v2)
|
||||
{
|
||||
Vector3d result = v1.Clone();
|
||||
result.X *= v2.X;
|
||||
result.Y *= v2.Y;
|
||||
result.Z *= v2.Z;
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Vector3d operator /(Vector3d v1, Vector3d v2)
|
||||
{
|
||||
Vector3d result = v1.Clone();
|
||||
result.X /= v2.X;
|
||||
result.Y /= v2.Y;
|
||||
result.Z /= v2.Z;
|
||||
return result;
|
||||
}
|
||||
|
||||
public static bool operator >(Vector3d v1, Vector3d v2)
|
||||
{
|
||||
return (v1.X > v2.X) || (v1.Y > v2.Y) || (v1.X > v2.Z);
|
||||
}
|
||||
|
||||
public static bool operator <(Vector3d v1, Vector3d v2)
|
||||
{
|
||||
return (v1.X < v2.X) || (v1.Y < v2.Y) || (v1.X < v2.Z);
|
||||
}
|
||||
|
||||
public Vector3d Clone()
|
||||
{
|
||||
return new Vector3d(X, Y, Z);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"<{X}, {Y}, {Z}>";
|
||||
}
|
||||
|
||||
public bool Inside(Vector3d min, Vector3d max)
|
||||
{
|
||||
return (min.X <= X && max.X >= X) && (min.Y <= Y && max.Y >= Y) && (min.Z <= Z && max.Z >= Z);
|
||||
}
|
||||
|
||||
// Override GetHashCode if you override Equals
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return HashCode.Combine(X, Y, Z);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue