Skip to content

Commit 1afa661

Browse files
Merge pull request #29 from ArtifactForms/working
Rollback. Bug fix. Bounds calculation was not working as expected.
2 parents f9d67a5 + a0e3ab9 commit 1afa661

File tree

1 file changed

+20
-19
lines changed

1 file changed

+20
-19
lines changed

src/main/java/mesh/Mesh3D.java

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -94,25 +94,26 @@ public Mesh3D translateZ(float tz) {
9494
* the mesh. The bounding box extends from the minimum vertex coordinate
9595
* to the maximum vertex coordinate.
9696
*/
97-
public Bounds3 calculateBounds() {
98-
if (vertices.isEmpty())
99-
return new Bounds3();
100-
101-
Vector3f min = new Vector3f(vertices.get(0));
102-
Vector3f max = new Vector3f(vertices.get(0));
103-
104-
for (Vector3f v : vertices) {
105-
min.setX(Math.min(min.getX(), v.getX()));
106-
min.setY(Math.min(min.getY(), v.getY()));
107-
min.setZ(Math.min(min.getZ(), v.getZ()));
108-
109-
max.setX(Math.max(max.getX(), v.getX()));
110-
max.setY(Math.max(max.getY(), v.getY()));
111-
max.setZ(Math.max(max.getZ(), v.getZ()));
112-
}
113-
114-
return new Bounds3(min, max);
115-
}
97+
public Bounds3 calculateBounds() {
98+
if (vertices.isEmpty())
99+
return new Bounds3();
100+
101+
Vector3f min = new Vector3f(getVertexAt(0));
102+
Vector3f max = new Vector3f(getVertexAt(0));
103+
Bounds3 bounds = new Bounds3();
104+
for (Vector3f v : vertices) {
105+
float minX = v.getX() < min.getX() ? v.getX() : min.getX();
106+
float minY = v.getY() < min.getY() ? v.getY() : min.getY();
107+
float minZ = v.getZ() < min.getZ() ? v.getZ() : min.getZ();
108+
float maxX = v.getX() > max.getX() ? v.getX() : max.getX();
109+
float maxY = v.getY() > max.getY() ? v.getY() : max.getY();
110+
float maxZ = v.getZ() > max.getZ() ? v.getZ() : max.getZ();
111+
min.set(minX, minY, minZ);
112+
max.set(maxX, maxY, maxZ);
113+
}
114+
bounds.setMinMax(min, max);
115+
return bounds;
116+
}
116117

117118
public Vector3f calculateFaceNormal(Face3D face) {
118119
Vector3f faceNormal = new Vector3f();

0 commit comments

Comments
 (0)