computeExtremes method
Implementation
Map<String, List<VertexNode>> computeExtremes() {
var min = Vector3.init();
var max = Vector3.init();
List<VertexNode> minVertices = [];
List<VertexNode> maxVertices = [];
var i, j;
// initially assume that the first vertex is the min/max
for (i = 0; i < 3; i++) {
// minVertices[ i ] = maxVertices[ i ] = this.vertices[ 0 ];
minVertices.add(vertices[0]);
maxVertices.add(vertices[0]);
}
min.copy(vertices[0].point);
max.copy(vertices[0].point);
// compute the min/max vertex on all six directions
for (var i = 0, l = vertices.length; i < l; i++) {
var vertex = vertices[i];
var point = vertex.point;
// update the min coordinates
for (j = 0; j < 3; j++) {
if (point.getComponent(j) < min.getComponent(j)) {
min.setComponent(j, point.getComponent(j));
minVertices[j] = vertex;
}
}
// update the max coordinates
for (j = 0; j < 3; j++) {
if (point.getComponent(j) > max.getComponent(j)) {
max.setComponent(j, point.getComponent(j));
maxVertices[j] = vertex;
}
}
}
// use min/max vectors to compute an optimal epsilon
tolerance = 3 *
Math.epsilon *
(Math.max<num>(Math.abs(min.x), Math.abs(max.x)) +
Math.max(Math.abs(min.y), Math.abs(max.y)) +
Math.max(Math.abs(min.z), Math.abs(max.z)));
return {"min": minVertices, "max": maxVertices};
}