Class PolygonConstraint

  • All Implemented Interfaces:
    Iterable<Vertex>, IConstraint, IPolyline

    public class PolygonConstraint
    extends PolyLineConstraintAdapter
    implements IConstraint
    An implementation of the IConstraint interface intended to store constraints comprised of a polygon. The polygon is allowed to be non-convex, but the segments comprising the polygon must be not intersect except at segment endpoints (e.g. the polygon must be a simple, non intersecting closed loop). All segments in the chain must be non-zero-length.

    For polygons defining an area, the interior of the area is defined as being bounded by a counter-clockwise polygon. Thus a clockwise polygon would define a "hole" in the area. It is worth noting that this convention is just the opposite of that taken by ESRI's Shapefile format, though it is consistent with conventions used in general computational geometry.

    Organizing the list of vertices that defines the polygon Some implementations of polygon geometries include an extra "closure" vertex so that the last vertex in the list of vertices that defines the polygon is also the first. Although that approach has some advantages, this class does not use it. Each vertex in the polygon geometry is assumed to be unique. Thus, if the polygon represents a triangle, the getVertices and Vertex iterator methods will return exactly three vertices.

    • Constructor Detail

      • PolygonConstraint

        public PolygonConstraint()
        Standard constructor
      • PolygonConstraint

        public PolygonConstraint​(Vertex v0,
                                 Vertex v1,
                                 Vertex v2,
                                 Vertex v3)
        A convenience constructor intended for the frequently occurring case in which an application wishes to define a constraint as a rectangle or four-vertex polygon
        Parameters:
        v0 - the initial vertex of the polygon
        v1 - the second vertex of the polygon
        v2 - the third vertex of the polygon
        v3 - the final vertex of the polygon
      • PolygonConstraint

        public PolygonConstraint​(List<Vertex> vList)
        Constructs a constraint with the specified vertices. This approach is generally faster than adding the vertices one at a time.
        Parameters:
        vList - a valid list containing at least 3 distinct points.
    • Method Detail

      • getVertices

        public List<Vertex> getVertices()
        Description copied from interface: IPolyline
        Gets the vertices for this feature. The vertices define a non-self-intersecting chain of line segments (that is, no line segments intersect except at their endpoints). The vertices are assumed to be unique and far enough apart that they are stable in numeric operations.
        Specified by:
        getVertices in interface IPolyline
        Overrides:
        getVertices in class PolyLineConstraintAdapter
        Returns:
        a valid list of two or more unique vertices.
      • complete

        public final void complete()
        Description copied from interface: IPolyline
        Called to indicate that the feature is complete and that no further vertices will be added to it. Some implementing classes may perform lightweight sanity checking on the feature instance.

        Multiple calls to complete are benign and will be ignored. If vertices are added after complete is called, the behavior is undefined.

        Specified by:
        complete in interface IPolyline
      • isPolygon

        public boolean isPolygon()
        Description copied from interface: IPolyline
        Indicates whether the instance represents a polygon. Some implementations may define a constant value for this method, others may determine it dynamically.
        Specified by:
        isPolygon in interface IPolyline
        Returns:
        true if the instance is a polygon; otherwise, false.
      • definesConstrainedRegion

        public boolean definesConstrainedRegion()
        Indicates whether the constraint applies a constrained region behavior when added to a TIN.
        Specified by:
        definesConstrainedRegion in interface IConstraint
        Returns:
        for this implementation, this method returns a value of true
      • getArea

        public double getArea()
        Get the computed square area for the constraint polygon. The area is not available until the complete() method is called. It is assumed that the area of a polygon with a counterclockwise orientation is positive and that the area of a polygon with a clockwise orientation is negative.
        Returns:
        if available, a non-zero (potentially negative) square area for the constraint; otherwise, a zero
      • getNominalPointSpacing

        public double getNominalPointSpacing()
        Description copied from interface: IPolyline
        Get the average distance between points for the feature.
        Specified by:
        getNominalPointSpacing in interface IPolyline
        Returns:
        if the feature contains more than one point, a floating point value greater than zero; otherwise a NaN.
      • getConstraintWithNewGeometry

        public PolygonConstraint getConstraintWithNewGeometry​(List<Vertex> geometry)
        Description copied from interface: IConstraint
        Gets a new constraint that has the attributes of this constraint and the specified geometry. This method is primarily used in cases where a geometry is very similar (or identical) to the input but either simplified or with replacement vertices.
        Specified by:
        getConstraintWithNewGeometry in interface IConstraint
        Parameters:
        geometry - a valid set of vertices.
        Returns:
        a new constraint.
      • refactor

        public PolygonConstraint refactor​(Iterable<Vertex> geometry)
        Description copied from interface: IPolyline
        Creates a new polyline feature with the specified geometry and transfers any data elements defined by the implementing class from the current object to the newly created one.

        This method is intended to be used in cases where application code performs some kind of transformation on the geometry of the existing object and produces a new object. In doing so, the application code treats the existing object on a read-only basis, but is free to transfer any implementation-specific data from the old object to the new. Examples of possible transformations include an implementation of a point-reduction technique such as Visvalingam's algorithm or point-addition techniques such as curve smoothing.

        Specified by:
        refactor in interface IPolyline
        Parameters:
        geometry - a list or other iterable instance that can be used as a source of vertices.
        Returns:
        if successful, a new instance of the implementing class.
      • isValid

        public boolean isValid()
        Description copied from interface: IPolyline
        Indicates that sufficient information has been stored in the polyline to establish a valid geometry.
        Specified by:
        isValid in interface IPolyline
        Returns:
        true if the polyline has a valid geometry; otherwise, false.
      • getPath2D

        public Path2D getPath2D​(AffineTransform transform)
        Gets a Java Path2D based on the geometry of the constraint mapped through an optional affine transform.
        Specified by:
        getPath2D in interface IConstraint
        Parameters:
        transform - a valid transform, or the null to use the identity transform.
        Returns:
        a valid instance of a Java Path2D