nextVertexToAdd method

VertexNode? nextVertexToAdd()

Implementation

VertexNode? nextVertexToAdd() {
  // if the 'assigned' list of vertices is empty, no vertices are left. return with 'undefined'
  VertexNode? eyeVertex;
  if (assigned.isEmpty() == false) {
    num maxDistance = 0;

    // grap the first available face and start with the first visible vertex of that face

    Face2 eyeFace2 = assigned.first()!.face!;
    VertexNode? vertex = eyeFace2.outside;

    // now calculate the farthest vertex that face can see

    do {
      final distance = eyeFace2.distanceToPoint(vertex!.point);

      if (distance > maxDistance) {
        maxDistance = distance;
        eyeVertex = vertex;
      }

      vertex = vertex.next;
    } while (vertex != null && vertex.face == eyeFace2);
  }
  return eyeVertex;
}