123 lines
2.4 KiB
C#
123 lines
2.4 KiB
C#
using System;
|
|
using UnityEngine;
|
|
|
|
namespace ErosionBrushPlugin
|
|
{
|
|
[Serializable]
|
|
public struct Coord
|
|
{
|
|
public int x;
|
|
|
|
public int z;
|
|
|
|
public int Minimal
|
|
{
|
|
get
|
|
{
|
|
return Mathf.Min(x, z);
|
|
}
|
|
}
|
|
|
|
public int SqrMagnitude
|
|
{
|
|
get
|
|
{
|
|
return x * x + z * z;
|
|
}
|
|
}
|
|
|
|
public Coord(int x, int z)
|
|
{
|
|
this.x = x;
|
|
this.z = z;
|
|
}
|
|
|
|
public static bool operator >(Coord c1, Coord c2)
|
|
{
|
|
return c1.x > c2.x && c1.z > c2.z;
|
|
}
|
|
|
|
public static bool operator <(Coord c1, Coord c2)
|
|
{
|
|
return c1.x < c2.x && c1.z < c2.z;
|
|
}
|
|
|
|
public static bool operator ==(Coord c1, Coord c2)
|
|
{
|
|
return c1.x == c2.x && c1.z == c2.z;
|
|
}
|
|
|
|
public static bool operator !=(Coord c1, Coord c2)
|
|
{
|
|
return c1.x != c2.x && c1.z != c2.z;
|
|
}
|
|
|
|
public static Coord operator +(Coord c, int s)
|
|
{
|
|
return new Coord(c.x + s, c.z + s);
|
|
}
|
|
|
|
public static Coord operator +(Coord c1, Coord c2)
|
|
{
|
|
return new Coord(c1.x + c2.x, c1.z + c2.z);
|
|
}
|
|
|
|
public static Coord operator -(Coord c, int s)
|
|
{
|
|
return new Coord(c.x - s, c.z - s);
|
|
}
|
|
|
|
public static Coord operator -(Coord c1, Coord c2)
|
|
{
|
|
return new Coord(c1.x - c2.x, c1.z - c2.z);
|
|
}
|
|
|
|
public static Coord operator *(Coord c, int s)
|
|
{
|
|
return new Coord(c.x * s, c.z * s);
|
|
}
|
|
|
|
public static Coord operator /(Coord c, int s)
|
|
{
|
|
return new Coord(c.x / s, c.z / s);
|
|
}
|
|
|
|
public override bool Equals(object obj)
|
|
{
|
|
return base.Equals(obj);
|
|
}
|
|
|
|
public override int GetHashCode()
|
|
{
|
|
return x * 10000000 + z;
|
|
}
|
|
|
|
public void Round(int val, bool ceil = false)
|
|
{
|
|
x = ((!ceil) ? Mathf.FloorToInt(1f * (float)x / (float)val) : Mathf.CeilToInt(1f * (float)x / (float)val)) * val;
|
|
z = ((!ceil) ? Mathf.FloorToInt(1f * (float)z / (float)val) : Mathf.CeilToInt(1f * (float)z / (float)val)) * val;
|
|
}
|
|
|
|
public void Round(Coord c, bool ceil = false)
|
|
{
|
|
x = ((!ceil) ? Mathf.CeilToInt(1f * (float)x / (float)c.x) : Mathf.FloorToInt(1f * (float)x / (float)c.x)) * c.x;
|
|
z = ((!ceil) ? Mathf.CeilToInt(1f * (float)z / (float)c.z) : Mathf.FloorToInt(1f * (float)z / (float)c.z)) * c.z;
|
|
}
|
|
|
|
public static Coord Min(Coord c1, Coord c2)
|
|
{
|
|
return new Coord(Mathf.Min(c1.x, c2.x), Mathf.Min(c1.z, c2.z));
|
|
}
|
|
|
|
public static Coord Max(Coord c1, Coord c2)
|
|
{
|
|
return new Coord(Mathf.Max(c1.x, c2.x), Mathf.Max(c1.z, c2.z));
|
|
}
|
|
|
|
public override string ToString()
|
|
{
|
|
return base.ToString() + " x:" + x + " z:" + z;
|
|
}
|
|
}
|
|
}
|