Module org.dyn4j

Class AbstractSimplifier

  • All Implemented Interfaces:
    Simplifier
    Direct Known Subclasses:
    VertexClusterReduction

    public abstract class AbstractSimplifier
    extends Object
    implements Simplifier
    Abstract simplifier providing some shared logic for all simplifiers.
    Since:
    4.2.0
    Version:
    4.2.0
    Author:
    William Bittle
    • Constructor Detail

      • AbstractSimplifier

        public AbstractSimplifier()
    • Method Detail

      • simplify

        public Vector2[] simplify​(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
        Parameters:
        vertices - the simple polygon's vertices
        Returns:
        Vector2[]
      • buildSegmentTree

        protected final SegmentTree buildSegmentTree​(SimplePolygonVertex start)
        Builds a SegmentTree used to prevent self-intersection during simplification.
        Parameters:
        start - the start vertex
        Returns:
        SegmentTree
      • buildResult

        protected final List<Vector2> buildResult​(SimplePolygonVertex start)
        Builds a polygon from the remaining vertices in the queue.
        Parameters:
        start - the vertex to begin building the result from
        Returns:
        List<Vector2>
      • isSelfIntersectionProduced

        protected final boolean isSelfIntersectionProduced​(SimplePolygonVertex vertex,
                                                           SegmentTree tree)
        Returns true if removing the given vertex will generate a line segment that causes self intersection.
        Parameters:
        vertex - the vertex that will be removed
        tree - the segment tree for accelerated detection
        Returns:
        boolean
      • isSelfIntersectionProduced

        protected final boolean isSelfIntersectionProduced​(SimplePolygonVertex vertex1,
                                                           SimplePolygonVertex vertex2,
                                                           SegmentTree tree)
        Returns true if the given segment will generate a self-intersection assuming all vertices between the two given vertices are removed.
        Parameters:
        vertex1 - the first vertex of the segment to be created
        vertex2 - the second vertex of the segment to be created
        tree - the segment tree for accelerated detection
        Returns:
        boolean
      • intersects

        protected final boolean intersects​(Vector2 a1,
                                           Vector2 a2,
                                           Vector2 b1,
                                           Vector2 b2)
        Returns true if the given segments intersect each other.
        Parameters:
        a1 - the first point of the first segment
        a2 - the second point of the first segment
        b1 - the first point of the second segment
        b2 - the second point of the second segment
        Returns:
        boolean