Package selector
Class PolyLine
java.lang.Object
selector.PolyLine
Represents an immutable path made up of straight line segments. While it is intended to be
immutable, its interface sacrifices some encapsulation in order to be used efficiently for AWT
graphics (that is, it does not create defensive copies of arrays), so clients must not modify the
contents of arrays returned by instances of this class.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionend()
Return the last (ending) point along this poly-line.boolean
int
hashCode()
static Polygon
makePolygon
(List<PolyLine> segments) Return an AWT Polygon enclosed by the sequence of poly-lines in `segments`.int
size()
Return the number of points along this poly-line, including both endpoints.start()
Return the first (starting) point along this poly-line.toString()
int[]
xs()
Return the sequence of the x coordinates of the points along this poly-line, in start-to-end order.int[]
ys()
Return the sequence of the y coordinates of the points along this poly-line, in start-to-end order.
-
Constructor Details
-
PolyLine
Create a straight line segment starting at `start` and ending at `end`. Does not store any references to its (mutable) arguments. -
PolyLine
public PolyLine(int[] xs, int[] ys) Create a poly-line whose points have x-coordinates `xs` and y-coordinates `ys`. Rep exposure: the new object takes ownership of the argument arrays (it does not make defensive copies), so clients must not mutate the contents of these arguments after construction. Requires that `xs` and `ys` have the same length no less than 2.
-
-
Method Details
-
xs
public int[] xs()Return the sequence of the x coordinates of the points along this poly-line, in start-to-end order. Rep exposure: clients must not mutate the contents of the returned array. -
ys
public int[] ys()Return the sequence of the y coordinates of the points along this poly-line, in start-to-end order. Rep exposure: clients must not mutate the contents of the returned array. -
size
public int size()Return the number of points along this poly-line, including both endpoints. Will be at least 2. The number of straight-line segments is therefore `size() - 1`. -
start
Return the first (starting) point along this poly-line. -
end
Return the last (ending) point along this poly-line. -
equals
-
hashCode
public int hashCode() -
makePolygon
Return an AWT Polygon enclosed by the sequence of poly-lines in `segments`. The end of the last segment in the sequence will be joined to the start of the first segment in the sequence. Any duplicate points where segments join are omitted. Requires `segments` is non-empty. -
toString
-