Class PolylineBuffer
java.lang.Object
org.apache.sis.internal.processing.isoline.PolylineBuffer
Coordinates of a polyline under construction. Coordinates can be appended in only one direction.
If the polyline may growth on both directions (which happens if the polyline crosses the bottom
side and the right side of a cell), then the two directions are handled by two distinct instances
connected by their
opposite
field.
When a polyline has been completed, its content is copied to Tracer.Level.path
and the PolylineBuffer
object is recycled for a new polyline.
- Since:
- 1.1
- Version:
- 1.3
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) double[]
Coordinates as (x,y) tuples.(package private) static final int
Number of coordinates in a tuple.(package private) PolylineBuffer
If the polyline has points added to its two extremities, the other extremity.(package private) int
Number of valid elements in thecoordinates
array. -
Constructor Summary
ConstructorsConstructorDescriptionCreates an initially empty polyline.PolylineBuffer
(double[] data) Creates a new polyline wrapping the given coordinates. -
Method Summary
Modifier and TypeMethodDescription(package private) final void
append
(double x, double y) Appends given coordinates to this polyline.(package private) final PolylineBuffer
attach
(PolylineBuffer other) Declares that the specified polyline will add points in the direction opposite to this polyline.(package private) final void
clear()
Discards all coordinates in this polyline.(package private) final boolean
isEmpty()
Returns whether this polyline is empty.(package private) final void
toRawPath
(Map<PolylineStage, Path2D> appendTo) Appends the pixel coordinates of this polyline to the given path, for debugging purposes only.toString()
Returns a string representation of thisPolyline
for debugging purposes.(package private) final PolylineBuffer
transferFrom
(PolylineBuffer source) Transfers all coordinates from given polylines to this polylines, in same order.(package private) final boolean
Transfers all coordinates from this polyline to the polyline going in opposite direction.
-
Field Details
-
DIMENSION
static final int DIMENSIONNumber of coordinates in a tuple.- See Also:
-
coordinates
double[] coordinatesCoordinates as (x,y) tuples. This array is expanded as needed. -
size
int sizeNumber of valid elements in thecoordinates
array. This is twice the number of points. -
opposite
PolylineBuffer oppositeIf the polyline has points added to its two extremities, the other extremity. Otherwisenull
. The first point ofopposite
polyline is connected to the first point of this polyline. Consequently, when those two polylines are joined in a single polyline, the coordinates of eitherthis
oropposite
must be iterated in reverse order.
-
-
Constructor Details
-
PolylineBuffer
PolylineBuffer()Creates an initially empty polyline. -
PolylineBuffer
PolylineBuffer(double[] data) Creates a new polyline wrapping the given coordinates. Used for wrappingFragments
instances in objects expected byTracer.writeTo(Joiner, Polyline[], boolean)
. ThosePolyline
instances are temporary.
-
-
Method Details
-
clear
final void clear()Discards all coordinates in this polyline. This method does not clear theopposite
polyline; it is caller's responsibility to do so. -
isEmpty
final boolean isEmpty()Returns whether this polyline is empty. This method is used only forassert isEmpty()
statement because of the check foropposite == null
: an empty polyline should not have a non-nullopposite
value. -
attach
Declares that the specified polyline will add points in the direction opposite to this polyline. This happens when the polyline crosses the bottom side and the right side of a cell (assuming an iteration from left to right and top to bottom).This method is typically invoked in the following pattern (but this is not mandatory). An important aspect is that
this
andother
should be on perpendicular axes:- Returns:
this
for method calls chaining.
-
transferFrom
Transfers all coordinates from given polylines to this polylines, in same order. This is used when polyline on the left side continues on bottom side, or conversely when polyline on the top side continues on right side. This polyline shall be empty before this method is invoked. The given source will become empty after this method returned.- Parameters:
source
- the source from which to take data.- Returns:
this
for method calls chaining.
-
transferToOpposite
final boolean transferToOpposite()Transfers all coordinates from this polyline to the polyline going in opposite direction. This is used when this polyline reached the right image border, in which case its data will be lost if we do not copy them somewhere.- Returns:
true
if coordinates have been transferred, orfalse
if there is no opposite direction.
-
append
final void append(double x, double y) Appends given coordinates to this polyline.- Parameters:
x
- first coordinate of the (x,y) tuple to add.y
- second coordinate of the (x,y) tuple to add.
-
toString
Returns a string representation of thisPolyline
for debugging purposes. -
toRawPath
Appends the pixel coordinates of this polyline to the given path, for debugging purposes only. The#gridToCRS
transform is not applied by this method. For avoiding confusing behavior, that transform should be null.- Parameters:
appendTo
- where to append the coordinates.- See Also:
-