computeExtremes method

Map<String, List<VertexNode>> computeExtremes()

Implementation

Map<String, List<VertexNode>> computeExtremes() {
  final min = Vector3();
  final max = Vector3();

  List<VertexNode> minVertices = [];
  List<VertexNode> maxVertices = [];

  int 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.setFrom(vertices[0].point);
  max.setFrom(vertices[0].point);

  // compute the min/max vertex on all six directions

  for (int i = 0, l = vertices.length; i < l; i++) {
    final vertex = vertices[i];
    final 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 *
      MathUtils.epsilon *
      (math.max<num>(min.x.abs(), max.x.abs()) +
          math.max(min.y.abs(), max.y.abs()) +
          math.max(min.z.abs(), max.z).abs());

  return {"min": minVertices, "max": maxVertices};
}