forked from tparisi/Unity-glTF-Exporter
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathBoundsDouble.cs
114 lines (94 loc) · 2.21 KB
/
BoundsDouble.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
using UnityEngine;
using System;
using System.Collections;
public class BoundsDouble {
double[] min = new double[]{0, 0, 0};
double[] max = new double[]{0, 0, 0};
bool inited = false;
public BoundsDouble() {
}
public BoundsDouble(BoundsDouble b) {
for (int i = 0; i < 3; ++i) {
min[i] = b.min[i];
max[i] = b.max[i];
}
inited = true;
}
public BoundsDouble(double[] min, double[] max) {
this.min[0] = min[0];
this.min[1] = min[1];
this.min[2] = min[2];
this.max[0] = max[0];
this.max[1] = max[1];
this.max[2] = max[2];
inited = true;
}
public BoundsDouble(Vector3 min, Vector3 max) {
this.min[0] = min.x;
this.min[1] = min.y;
this.min[2] = min.z;
this.max[0] = max.x;
this.max[1] = max.y;
this.max[2] = max.z;
inited = true;
}
public void Encapsulate(BoundsDouble b) {
if (inited) {
min[0] = Math.Min(min[0], b.min[0]);
min[1] = Math.Min(min[1], b.min[1]);
min[2] = Math.Min(min[2], b.min[2]);
max[0] = Math.Max(max[0], b.max[0]);
max[1] = Math.Max(max[1], b.max[1]);
max[2] = Math.Max(max[2], b.max[2]);
} else {
min[0] = b.min[0];
min[1] = b.min[1];
min[2] = b.min[2];
max[0] = b.max[0];
max[1] = b.max[1];
max[2] = b.max[2];
inited = true;
}
}
public void Rotate(Matrix4x4 m) {
if (inited) {
double minx = m.m00 * min[0] + m.m01 * min[1] + m.m02 * min[2];
double miny = m.m10 * min[0] + m.m11 * min[1] + m.m12 * min[2];
double minz = m.m20 * min[0] + m.m21 * min[1] + m.m22 * min[2];
double maxx = m.m00 * max[0] + m.m01 * max[1] + m.m02 * max[2];
double maxy = m.m10 * max[0] + m.m11 * max[1] + m.m12 * max[2];
double maxz = m.m20 * max[0] + m.m21 * max[1] + m.m22 * max[2];
min[0] = Math.Min(minx, maxx);
min[1] = Math.Min(miny, maxy);
min[2] = Math.Min(minz, maxz);
max[0] = Math.Max(minx, maxx);
max[1] = Math.Max(miny, maxy);
max[2] = Math.Max(minz, maxz);
}
}
public void Translate(double x, double y, double z) {
if (inited) {
min[0] += x;
min[1] += y;
min[2] += z;
max[0] += x;
max[1] += y;
max[2] += z;
}
}
public bool Empty {
get {
return !inited;
}
}
public double[] Min {
get {
return min;
}
}
public double[] Max {
get {
return max;
}
}
}