Class PolygonConstraint
- java.lang.Object
-
- org.tinfour.common.PolyLineConstraintAdapter
-
- org.tinfour.common.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.
-
-
Field Summary
-
Fields inherited from class org.tinfour.common.PolyLineConstraintAdapter
applicationData, constraintIndex, constraintLinkingEdge, isComplete, length, list, maintainingTin
-
-
Constructor Summary
Constructors Constructor Description PolygonConstraint()Standard constructorPolygonConstraint(List<Vertex> vList)Constructs a constraint with the specified vertices.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
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcomplete()Called to indicate that the feature is complete and that no further vertices will be added to it.booleandefinesConstrainedRegion()Indicates whether the constraint applies a constrained region behavior when added to a TIN.doublegetArea()Get the computed square area for the constraint polygon.PolygonConstraintgetConstraintWithNewGeometry(List<Vertex> geometry)Gets a new constraint that has the attributes of this constraint and the specified geometry.doublegetNominalPointSpacing()Get the average distance between points for the feature.Path2DgetPath2D(AffineTransform transform)Gets a Java Path2D based on the geometry of the constraint mapped through an optional affine transform.List<Vertex>getVertices()Gets the vertices for this feature.booleanisPolygon()Indicates whether the instance represents a polygon.booleanisValid()Indicates that sufficient information has been stored in the polyline to establish a valid geometry.PolygonConstraintrefactor(Iterable<Vertex> geometry)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.StringtoString()-
Methods inherited from class org.tinfour.common.PolyLineConstraintAdapter
add, densify, getApplicationData, getBounds, getConstraintIndex, getConstraintLinkingEdge, getLength, getManagingTin, isPointInsideConstraint, iterator, setApplicationData, setConstraintIndex, setConstraintLinkingEdge
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.tinfour.common.IConstraint
densify, getApplicationData, getConstraintIndex, getConstraintLinkingEdge, getManagingTin, isPointInsideConstraint, setApplicationData, setConstraintIndex, setConstraintLinkingEdge
-
Methods inherited from interface java.lang.Iterable
forEach, iterator, spliterator
-
-
-
-
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 polygonv1- the second vertex of the polygonv2- the third vertex of the polygonv3- the final vertex of the polygon
-
-
Method Detail
-
getVertices
public List<Vertex> getVertices()
Description copied from interface:IPolylineGets 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:
getVerticesin interfaceIPolyline- Overrides:
getVerticesin classPolyLineConstraintAdapter- Returns:
- a valid list of two or more unique vertices.
-
complete
public final void complete()
Description copied from interface:IPolylineCalled 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.
-
isPolygon
public boolean isPolygon()
Description copied from interface:IPolylineIndicates whether the instance represents a polygon. Some implementations may define a constant value for this method, others may determine it dynamically.
-
definesConstrainedRegion
public boolean definesConstrainedRegion()
Indicates whether the constraint applies a constrained region behavior when added to a TIN.- Specified by:
definesConstrainedRegionin interfaceIConstraint- 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:IPolylineGet the average distance between points for the feature.- Specified by:
getNominalPointSpacingin interfaceIPolyline- 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:IConstraintGets 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:
getConstraintWithNewGeometryin interfaceIConstraint- Parameters:
geometry- a valid set of vertices.- Returns:
- a new constraint.
-
refactor
public PolygonConstraint refactor(Iterable<Vertex> geometry)
Description copied from interface:IPolylineCreates 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.
-
isValid
public boolean isValid()
Description copied from interface:IPolylineIndicates that sufficient information has been stored in the polyline to establish a valid geometry.
-
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:
getPath2Din interfaceIConstraint- Parameters:
transform- a valid transform, or the null to use the identity transform.- Returns:
- a valid instance of a Java Path2D
-
-