Class Contour
- java.lang.Object
-
- org.tinfour.contour.Contour
-
public class Contour extends Object
Provides methods and elements for constructing a contour. Tinfour defines contours as specifying a boundary between two regions in a plane. The region to the left of the contour is treated as including points with vertical coordinates greater than or equal to the contour's vertical coordinate. The values to the right are treated as including points with vertical coordinates less than the contour's vertical coordinate. Thus, in an elevation set, a hill would be represented with a set of closed-loop contours taken in counterclockwise order. A valley would be represented as a set of closed-loop contours taken in clockwise order.The complete() method should always be called when a contour is fully populated (e.g. it is complete). The complete call trims the internal buffers and performs any sanity checking required for contour management.
A closed-loop contour is expected to always include a "closure point" so that the first point in the contour matches the last. This approach is taken to simplify internal logic in the contour building routines. The complete() method ensures that a closure point is added to closed-loop contours if none is provided by the application.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classContour.ContourTypeAn enumeration that indicates the type of a contour
-
Constructor Summary
Constructors Constructor Description Contour(int leftIndex, int rightIndex, double z, boolean closedLoop)Constructs an instance of a contour
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(double x, double y)Add an coordinate point to the contour.voidcomplete()Called when the construction of a contour is complete to trim the memory for the internal point collection.Rectangle2DgetBounds()Get the bounds of the contour.intgetContourId()Gets the serialized identification code for the contour.intgetContourIndex()Gets the index for the value of the input contour array that was used to build this contour, or a notional value if this instance is a boundary contour.Contour.ContourTypegetContourType()Indicates whether the contour is an interior or perimeter contour.double[]getCoordinates()Gets a safe copy of the coordinates for the contour.intgetLeftIndex()Get the index for the region lying to the left of the contour.Path2DgetPath2D(AffineTransform transform)Gets a Path2D suitable for rendering purposes.intgetRightIndex()Get the index for the region lying to the right of the contour.double[]getXY()Gets a safe copy of the coordinates for the contour.doublegetZ()Gets the z value associated with the contourbooleanisBoundary()Indicates whether the contour is a boundary contour.booleanisClosed()Indicates that the contour forms a closed loopbooleanisEmpty()Indicates whether the contour is empty.intsize()Indicates the number of points stored in the contourStringtoString()
-
-
-
Constructor Detail
-
Contour
public Contour(int leftIndex, int rightIndex, double z, boolean closedLoop)Constructs an instance of a contour- Parameters:
leftIndex- the contour-interval index of the area to the left of the contour.rightIndex- the contour-interval index of the area to the right of the contour.z- the vertical coordinate for the contourclosedLoop- indicates if the contour is to be treated as a closed loop.
-
-
Method Detail
-
add
public void add(double x, double y)Add an coordinate point to the contour.- Parameters:
x- the Cartesian x-coordinate for the pointy- the Cartesian y-coordinate for the point
-
getCoordinates
public double[] getCoordinates()
Gets a safe copy of the coordinates for the contour. This method is scheduled for replacement in a future release. Please use getXY().- Returns:
- a valid, potentially zero-length array giving x and y coordinates for a series of points.
-
getXY
public double[] getXY()
Gets a safe copy of the coordinates for the contour. Coordinates are stored in a one-dimensional array of doubles in the order:{ (x0,y0), (x1,y1), (x2,y2), etc. }.- Returns:
- a valid, potentially zero-length array giving x and y coordinates for a series of points.
-
getZ
public double getZ()
Gets the z value associated with the contour- Returns:
- the z value used to construct the contour.
-
isEmpty
public boolean isEmpty()
Indicates whether the contour is empty.- Returns:
- true if the contour has no geometry defined; otherwise false.
-
size
public int size()
Indicates the number of points stored in the contour- Returns:
- a positive integer value, potentially zero.
-
complete
public void complete()
Called when the construction of a contour is complete to trim the memory for the internal point collection. This method also ensures that a closed-loop contour includes a closure point.References to edges and contour-building elements are not affected by this call.
-
getContourId
public int getContourId()
Gets the serialized identification code for the contour. When used with the ContourBuilder, this value gives a unique serial ID assigned when the contour is constructed. This value should not be confused with the contour interval or the left and right side index values.- Returns:
- an integer value.
-
getPath2D
public Path2D getPath2D(AffineTransform transform)
Gets a Path2D suitable for rendering purposes.- Parameters:
transform- a valid AffineTransform, typically specified to map the Cartesian coordinates of the contour to pixel coordinate.- Returns:
- a valid instance
-
getContourType
public Contour.ContourType getContourType()
Indicates whether the contour is an interior or perimeter contour. Note: future implementations may include additional types.- Returns:
- a valid enumeration instance
-
isBoundary
public boolean isBoundary()
Indicates whether the contour is a boundary contour.- Returns:
- true if the contour is a boundary; otherwise, false.
-
isClosed
public boolean isClosed()
Indicates that the contour forms a closed loop- Returns:
- true if the contour forms a closed loop; otherwise false
-
getBounds
public Rectangle2D getBounds()
Get the bounds of the contour.- Returns:
- a valid instance.
-
getContourIndex
public int getContourIndex()
Gets the index for the value of the input contour array that was used to build this contour, or a notional value if this instance is a boundary contour.It is strongly recommended that application code check to see if this instance is a boundary contour before using the contour index.
- Returns:
- a value in the range 0 to the length of the input z contour array.
-
getLeftIndex
public int getLeftIndex()
Get the index for the region lying to the left of the contour.- Returns:
- an integer in the range 0 to nContour, or -1 if the contour borders a null-data area
-
getRightIndex
public int getRightIndex()
Get the index for the region lying to the right of the contour.- Returns:
- an integer in the range 0 to nContour, or -1 if the contour borders a null-data area
-
-