- Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathShape.java
More file actions
Latest commit
137 lines (118 loc) · 2.97 KB
/
Copy pathShape.java
File metadata and controls
137 lines (118 loc) · 2.97 KB
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
packagepackalg;
/**
* PackAlg
* By Arwid Bancewicz, October 19, 2009
*/
// Imports
importjava.util.Comparator;
importjava.util.List;
/**
* Shape.java - A class representing a 3-dimensional shape with position but
* empty dimensions.
*
* @author Arwid Bancewicz
* @version 1.1, (09/19/09)
*/
publicabstractclassShape {
// Fields
protectedintiiX, iiY, iiZ; // position (default 0)
/**
* Sets the position according to the specified parameters
*/
publicfinalvoidsetPosition(intaiX, intaiY, intaiZ) {
this.iiX = aiX;
this.iiY = aiY;
this.iiZ = aiZ;
}
/**
* Sets the position equal to that of the specified shape.
*/
publicfinalvoidmatchPositionOf(ShapeaoShape) {
this.setPosition(aoShape.iiX, aoShape.iiY, aoShape.iiZ);
}
/**
* Returns the object's bottom area (along XY plane).
*/
publicabstractintgetArea();
/**
* Returns the object's volume.
*/
publicabstractintgetVolume();
/**
* Rotate along the XY plane.
*/
publicabstractvoidrotateXY();
/**
* Whether this can contain the specified shape at its current rotation.
*/
publicabstractbooleancanContain(ShapeaoShape);
/**
* Whether this can contain the specified shape at any rotation. The said
* shape will be left using the fitted rotation. Otherwise, it's left as
* before.
*/
publicabstractbooleanattemptToContain(ShapeaoShape);
/**
* Break this object up into unoccupied regions around the specified shape
* (The shape must fit this object).
* @param aoOccupied the occupied region
* @return the unoccupied regions
*/
publicabstractList<Shape> breakUp(ShapeaoOccupied);
/**
* Full string which includes toString() of super class.
*/
publicabstractStringtoFullString();
/**
* @see java.lang.Object#toString()
*/
@Override
publicStringtoString() {
return"[X=" + iiX + ", Y=" + iiY + ", Z=" + iiZ + "]";
}
/**
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
publicbooleanequals(Objectobj) {
Shapeother = (Shape) obj;
if (iiX != other.iiX || iiY != other.iiY || iiZ != other.iiZ)
returnfalse;
returntrue;
}
// Other Members
/**
* Compute total volume of specified shapes.
*
* @param aoShapes the shapes to compute
* @return the total volume of the shapes
*/
publicstaticfinalintgetTotalVolume(List<Shape> aoShapes) {
intliTotalVolume = 0;
for (ShapeloShape : aoShapes) {
liTotalVolume += loShape.getVolume();
}
returnliTotalVolume;
}
}
// Other Classes
/**
* Dimension comparator for Shape area sort (ascending)
* @see Comparator
*/
classshapeAreaComparatorimplementsComparator<Shape> {
@Override
publicintcompare(Shapeo1, Shapeo2) {
return (o1.getArea() - o2.getArea());
}
}
/**
* Dimension comparator for Shape volume sort (ascending)
* @see Comparator
*/
classshapeVolumeComparatorimplementsComparator<Shape> {
@Override
publicintcompare(Shapeo1, Shapeo2) {
return (o1.getVolume() - o2.getVolume());
}
}