forked from MaximumADHD/Roblox-File-Format
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRegion3.cs
61 lines (48 loc) · 1.45 KB
/
Region3.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
using System;
namespace RobloxFiles.DataTypes
{
public class Region3
{
public readonly Vector3 Min, Max;
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)
{
Min = min;
Max = max;
}
public Region3 ExpandToGrid(float resolution)
{
Vector3 emin = new Vector3
(
(float)Math.Floor(Min.X) * resolution,
(float)Math.Floor(Min.Y) * resolution,
(float)Math.Floor(Min.Z) * resolution
);
Vector3 emax = new Vector3
(
(float)Math.Floor(Max.X) * resolution,
(float)Math.Floor(Max.Y) * resolution,
(float)Math.Floor(Max.Z) * resolution
);
return new Region3(emin, emax);
}
public override int GetHashCode()
{
int hash = Min.GetHashCode()
^ Max.GetHashCode();
return hash;
}
public override bool Equals(object obj)
{
if (!(obj is Region3 other))
return false;
if (!Min.Equals(other.Min))
return false;
if (!Max.Equals(other.Max))
return false;
return true;
}
}
}