Package selector

Class PolyLineBuffer

java.lang.Object
selector.PolyLineBuffer

public class PolyLineBuffer extends Object
A mutable buffer of points for building up a PolyLine one point at a time.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Create 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 Type
    Method
    Description
    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.
    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
     
    Reverses the sequence of points in this buffer, then returns a reference to itself.
    int
    Return the number of points currently in this buffer.
    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()
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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

      public void append(Point p)
      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

      public Point start()
      Return a copy of the first point in this buffer. Requires `size() > 0`.
    • end

      public Point end()
      Return a copy of the last point in this buffer. Requires `size() > 0`.
    • reverse

      public PolyLineBuffer reverse()
      Reverses the sequence of points in this buffer, then returns a reference to itself.
    • toPolyLine

      public PolyLine toPolyLine() throws IllegalStateException
      Return a PolyLine consisting of the points currently in this buffer. Throws `IllegalStateException` if the buffer is empty.
      Throws:
      IllegalStateException
    • makePolygon

      public static Polygon makePolygon(Iterable<PolyLineBuffer> segments)