Package selector
Class PolyLineBuffer
java.lang.Object
selector.PolyLineBuffer
A mutable buffer of points for building up a PolyLine one point at a time.
-
Constructor Summary
ConstructorsConstructorDescriptionCreate an empty PolyLineBuffer with default capacity (suitable for general-purpose use).PolyLineBuffer
(int initialCapacity) Create an empty PolyLineBuffer with an initial capacity of `initialCapacity`. -
Method Summary
Modifier and TypeMethodDescriptionvoid
append
(int x, int y) Append the point `(x, y)` to the end of this buffer if it is distinct from the buffer's current endpoint.void
Append the point `p` to the end of this buffer if it is distinct from the buffer's current endpoint.end()
Return a copy of the last point in this buffer.static Polygon
makePolygon
(Iterable<PolyLineBuffer> segments) reverse()
Reverses the sequence of points in this buffer, then returns a reference to itself.int
size()
Return the number of points currently in this buffer.start()
Return a copy of the first point in this buffer.Return a PolyLine consisting of the points currently in this buffer.int[]
xs()
int[]
ys()
-
Constructor Details
-
PolyLineBuffer
public PolyLineBuffer()Create an empty PolyLineBuffer with default capacity (suitable for general-purpose use). -
PolyLineBuffer
public PolyLineBuffer(int initialCapacity) Create an empty PolyLineBuffer with an initial capacity of `initialCapacity`. If the approximate size of the PolyLine is known ahead of time, choosing a sufficiently large initial capacity can reduce allocation and copying overhead from resizing.
-
-
Method Details
-
append
Append the point `p` to the end of this buffer if it is distinct from the buffer's current endpoint. Its coordinate values are copied, avoiding rep exposure. -
append
public void append(int x, int y) Append the point `(x, y)` to the end of this buffer if it is distinct from the buffer's current endpoint. -
xs
public int[] xs() -
ys
public int[] ys() -
size
public int size()Return the number of points currently in this buffer. -
start
Return a copy of the first point in this buffer. Requires `size() > 0`. -
end
Return a copy of the last point in this buffer. Requires `size() > 0`. -
reverse
Reverses the sequence of points in this buffer, then returns a reference to itself. -
toPolyLine
Return a PolyLine consisting of the points currently in this buffer. Throws `IllegalStateException` if the buffer is empty.- Throws:
IllegalStateException
-
makePolygon
-