Module org.dyn4j

Class VertexClusterReduction

  • All Implemented Interfaces:
    Direct Known Subclasses:
    DouglasPeucker, Visvalingam

    public class VertexClusterReduction
    extends AbstractSimplifier
    implements Simplifier
    Simple polygon (without holes) simplifier that reduces the number of vertices by inspecting the distance between adjacent vertices. If the distance between two adjacent vertices is less than the given tolerance, it's removed.

    This algorithm is typically used to pre-process a simple polygon before another simplification algorithm is used. Both the Visvalingam and DouglasPeucker implementations run this step before running their algorithm.

    This algorithm has O(n log n) complexity where n is the number of vertices in the source polygon (due to self-intersection prevention). This algorithm prevents self-intersections arising from the simplification process by skipping the simplification.

    This method does not require the polygon to have any defined winding, but does assume that it does not have holes and is not self-intersecting.

    This method handles null/empty lists, null elements, and all null elements. In these cases it's possible the returned list will be empty or have less than 3 vertices.

    NOTE: This algorithm's result is highly dependent on the given cluster tolerance and the input polygon. There's no guarantee that the result will have 3 or more vertices.

    William Bittle
    See Also:
    Vertex Cluster Reduction
    • Constructor Detail

      • VertexClusterReduction

        public VertexClusterReduction​(double clusterTolerance)
        Minimal constructor.
        clusterTolerance - the minimal distance allowed between adjacent vertices; must be zero or greater
        IllegalArgumentException - if clusterTolerance is less than zero
    • Method Detail

      • simplify

        public List<Vector2> simplify​(List<Vector2> vertices)
        Description copied from interface: Simplifier
        Simplifies the given simple polygon and returns a new simplified simple polygon.
        Specified by:
        simplify in interface Simplifier
        vertices - the simple polygon's vertices
      • buildVertexList

        protected final List<SimplePolygonVertex> buildVertexList​(List<Vector2> polygon)
        Builds a list of vertices without nulls.
        polygon - the polygon vertices