2019-01-26 00:39:37 +00:00
|
|
|
|
using System;
|
|
|
|
|
|
2019-02-01 17:19:20 +00:00
|
|
|
|
namespace RobloxFiles.DataTypes
|
2019-01-26 00:39:37 +00:00
|
|
|
|
{
|
2019-02-01 18:40:39 +00:00
|
|
|
|
public class Region3
|
2019-01-26 00:39:37 +00:00
|
|
|
|
{
|
2019-11-01 02:40:31 +00:00
|
|
|
|
public readonly Vector3 Min, Max;
|
2019-01-26 00:39:37 +00:00
|
|
|
|
|
2019-11-01 02:40:31 +00:00
|
|
|
|
public Vector3 Size => (Max - Min);
|
|
|
|
|
public CFrame CFrame => new CFrame((Min + Max) / 2);
|
|
|
|
|
|
|
|
|
|
public override string ToString() => $"{CFrame}; {Size}";
|
|
|
|
|
|
|
|
|
|
public Region3(Vector3 min, Vector3 max)
|
2019-01-26 00:39:37 +00:00
|
|
|
|
{
|
2019-11-01 02:40:31 +00:00
|
|
|
|
Min = min;
|
|
|
|
|
Max = max;
|
2019-01-26 00:39:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-11-01 02:40:31 +00:00
|
|
|
|
internal Region3(Attribute attr)
|
2019-01-26 00:39:37 +00:00
|
|
|
|
{
|
2019-11-01 02:40:31 +00:00
|
|
|
|
Min = new Vector3(attr);
|
|
|
|
|
Max = new Vector3(attr);
|
2019-01-26 00:39:37 +00:00
|
|
|
|
}
|
2019-11-01 02:40:31 +00:00
|
|
|
|
|
2019-01-26 00:39:37 +00:00
|
|
|
|
public Region3 ExpandToGrid(float resolution)
|
|
|
|
|
{
|
|
|
|
|
Vector3 emin = new Vector3
|
|
|
|
|
(
|
2019-11-01 02:40:31 +00:00
|
|
|
|
(float)Math.Floor(Min.X) * resolution,
|
|
|
|
|
(float)Math.Floor(Min.Y) * resolution,
|
|
|
|
|
(float)Math.Floor(Min.Z) * resolution
|
2019-01-26 00:39:37 +00:00
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
Vector3 emax = new Vector3
|
|
|
|
|
(
|
2019-11-01 02:40:31 +00:00
|
|
|
|
(float)Math.Floor(Max.X) * resolution,
|
|
|
|
|
(float)Math.Floor(Max.Y) * resolution,
|
|
|
|
|
(float)Math.Floor(Max.Z) * resolution
|
2019-01-26 00:39:37 +00:00
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return new Region3(emin, emax);
|
|
|
|
|
}
|
2020-09-13 01:16:19 +00:00
|
|
|
|
|
|
|
|
|
public override int GetHashCode()
|
|
|
|
|
{
|
|
|
|
|
int hash = Min.GetHashCode()
|
|
|
|
|
^ Max.GetHashCode();
|
|
|
|
|
|
|
|
|
|
return hash;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override bool Equals(object obj)
|
|
|
|
|
{
|
|
|
|
|
if (!(obj is Region3))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
var other = obj as Region3;
|
|
|
|
|
|
|
|
|
|
if (!Min.Equals(other.Min))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if (!Max.Equals(other.Max))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2019-01-26 00:39:37 +00:00
|
|
|
|
}
|
|
|
|
|
}
|