77 lines
1.5 KiB
C#
77 lines
1.5 KiB
C#
using System;
|
|
using System.Globalization;
|
|
|
|
namespace ReallifeGamemode.Server.Core.API
|
|
{
|
|
public class Position
|
|
{
|
|
public double X { get; set; }
|
|
|
|
public double Y { get; set; }
|
|
|
|
public double Z { get; set; }
|
|
|
|
public Position()
|
|
{
|
|
X = 0.0;
|
|
Y = 0.0;
|
|
Z = 0.0;
|
|
}
|
|
|
|
public Position(double x, double y, double z)
|
|
{
|
|
X = x;
|
|
Y = y;
|
|
Z = z;
|
|
}
|
|
|
|
public Position(float x, float y, float z)
|
|
{
|
|
X = x;
|
|
Y = y;
|
|
Z = z;
|
|
}
|
|
public Position(decimal x, decimal y, decimal z)
|
|
{
|
|
X = (double)x;
|
|
Y = (double)y;
|
|
Z = (double)z;
|
|
}
|
|
|
|
public Position(int x, int y, int z)
|
|
{
|
|
X = x;
|
|
Y = y;
|
|
Z = z;
|
|
}
|
|
|
|
public Position Add(Position toAdd)
|
|
{
|
|
return new Position(X + toAdd.X, Y + toAdd.Y, Z + toAdd.Z);
|
|
}
|
|
|
|
public Position Subtract(Position toSubtract)
|
|
{
|
|
return new Position(X - toSubtract.X, Y - toSubtract.Y, Z - toSubtract.Z);
|
|
}
|
|
|
|
public double DistanceTo(Position position)
|
|
{
|
|
var x = position.X - X;
|
|
var y = position.Y - Y;
|
|
var z = position.Z - Z;
|
|
|
|
return Math.Sqrt(x * x + y * y + z * z);
|
|
}
|
|
|
|
public override string ToString()
|
|
{
|
|
var x = Math.Round(this.X, 2).ToString(CultureInfo.InvariantCulture);
|
|
var y = Math.Round(this.Y, 2).ToString(CultureInfo.InvariantCulture);
|
|
var z = Math.Round(this.Z, 2).ToString(CultureInfo.InvariantCulture);
|
|
|
|
return $"{x}, {y}, {z}";
|
|
}
|
|
}
|
|
}
|