-
Notifications
You must be signed in to change notification settings - Fork 0
/
Form.java
76 lines (68 loc) · 1.82 KB
/
Form.java
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
import java.util.Comparator;
/** Forms are any object with volume
* @author Carol Chen
*/
public abstract class Form {
public abstract boolean hit(Ray r, double minT, double maxT, FormHit hit);
public abstract boolean boundingBox(double t0, double t1, AABB box);
}
/** Class to sort boxes by x values
* @author Carol Chen
*/
class SortBoxX implements Comparator<Form>{
public int compare(Form a, Form b){
AABB boxLeft = new AABB();
AABB boxRight = new AABB();
if (!a.boundingBox(0,0, boxLeft) || !b.boundingBox(0,0, boxRight)) {
throw new java.lang.RuntimeException("no bounding box");
}
if (boxLeft.min().x() == boxRight.min().x()) {
return 0;
}
if (boxLeft.min().x() < boxRight.min().x()) {
return -1;
} else {
return 1;
}
}
}
/** Class to sort boxes by y values
* @author Carol Chen
*/
class SortBoxY implements Comparator<Form>{
public int compare(Form a, Form b) {
AABB boxLeft = new AABB();
AABB boxRight = new AABB();
if (!a.boundingBox(0,0, boxLeft) || !b.boundingBox(0,0, boxRight)) {
throw new java.lang.RuntimeException("no bounding box");
}
if (boxLeft.min().y() == boxRight.min().y()) {
return 0;
}
if (boxLeft.min().y() < boxRight.min().y()) {
return -1;
} else {
return 1;
}
}
}
/** Class to sort boxes by z values
* @author Carol Chen
*/
class SortBoxZ implements Comparator<Form>{
public int compare(Form a, Form b) {
AABB boxLeft = new AABB();
AABB boxRight = new AABB();
if (!a.boundingBox(0,0, boxLeft) || !b.boundingBox(0,0, boxRight)){
throw new java.lang.RuntimeException("no bounding box");
}
if (boxLeft.min().z() == boxRight.min().z()) {
return 0;
}
if (boxLeft.min().z() < boxRight.min().z()) {
return -1;
} else {
return 1;
}
}
}