Class RMPath
- java.lang.Object
-
- com.inductiveautomation.rm.graphics.RMPath
-
- All Implemented Interfaces:
Archivable,java.awt.Shape,java.lang.Cloneable
public class RMPath extends java.lang.Object implements java.awt.Shape, java.lang.Cloneable, Archivable
RMPath - A graphics path (moveTo, lineTo, etc.). It provides the following functionality: - Allows for easy initialization with the path constructions methods (moveToPoint:, lineToPoint:, etc.). - Provides simple methods for path operations (stroke, fill, clip, etc.). Iterate over path like this:RMPoint points[] = new RMPoint[3]; for(int i=0, iMax=path.getElementCount(); i<iMax; i++) { int element = path.getElement(i, points); switch(element) { case RMPath.MOVE_TO: case RMPath.LINE_TO: case RMPath.QUAD_TO: case RMPath.CURVE_TO: case RMPath.CLOSE: } }
-
-
Field Summary
Fields Modifier and Type Field Description static byteCLOSEstatic byteCURVE_TOstatic byteLINE_TOstatic byteMOVE_TOstatic byteQUAD_TOstatic RMPathunitRectPathstatic byteWIND_EVEN_ODDstatic byteWIND_NON_ZERO
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddSegment(RMLine aSegment)Adds the list of segments to the path, starting with a moveto.voidaddSegments(java.util.List<? extends RMLine> theSegments)Adds the list of segments to the path, starting with a moveto.doublearcLength()Returns the total arc length of path segments.RMPathclone()Standard clone implementation.voidclosePath()Adds a Close element to the given path.booleancontains(double x, double y)Returns whether the given xy coordinate is inside the path.booleancontains(double x, double y, double w, double h)Returns whether the interior of the shape entirely contains the specified rectangular area.booleancontains(java.awt.geom.Point2D aPoint)Returns whether the given point is inside the path.booleancontains(java.awt.geom.Rectangle2D aRect)Returns whether the interior of the shape entirely contains the specified rectangular area.RMPathcreateTransformedPath(java.awt.geom.AffineTransform aTransform)Returns a transformed version of this path.voidcurveTo(double cp1x, double cp1y, double cp2x, double cp2y, double px, double py)Adds a CurveTo element to the path for the given point and control points.voidcurveTo(RMPoint cp1, RMPoint cp2, RMPoint p)Adds a CurveTo element to the path for the given point and control points.booleanequals(java.lang.Object anObj)Standard equals implementation.java.lang.ObjectfromXML(RXArchiver anArchiver, RXElement anElement)XML unarchival.java.awt.RectanglegetBounds()Returns the bounds for the path as an integer rect.RMRectgetBounds2D()Returns the bounds for the path.RMRectgetControlPointBounds()Returns the rectangle that encloses all the control points.bytegetElement(int anIndex)Returns the element type at the given index.bytegetElement(int anIndex, RMPoint[] points)Returns the element type at the given index and its associated points (returned in the given point array).intgetElementCount()Returns the number of elements in this path.intgetElementIndexForPointIndex(int index)Returns the element index for the given point index.bytegetElementLast()Returns the last element.intgetElementPointIndex(int anIndex)Returns the point index for a given element.doublegetHeight()Returns the height of the path.RMHitInfogetHitInfo(RMBezier aBezier, boolean findFirstHit)Returns the hit info for the given bezier curve against this path.RMHitInfogetHitInfo(RMLine aLine, boolean findFirstHit)Returns the hit info for the given line against this path.RMPathgetPathInRect(java.awt.geom.Rectangle2D aRect)Returns a copy of the path scaled to exactly fit in the given rect.java.awt.geom.PathIteratorgetPathIterator(java.awt.geom.AffineTransform aTransform)Returns a path iterator for this path and the given transform.java.awt.geom.PathIteratorgetPathIterator(java.awt.geom.AffineTransform aTransform, double flatness)Returns a path iterator for this path and the given transform and flatness.RMPointgetPoint(int anIndex)Returns the point at the given index.intgetPointCount()Returns the number of points in the path.RMPointgetPointLast()Returns the last point in the path.RMPathgetReversedPath()Returns a new path with the same points as this path, but in reverse order.java.util.List<? extends RMLine>getSegments()Converts a path into a list of RMLine/RMQuadratic/RMBezier.java.util.List<java.util.List<? extends RMLine>>getSubpathsSegments()Converts a path into a list subpath lists of RMLine/RMQuadratic/RMBezier.doublegetWidth()Returns the width of the path.bytegetWindingRule()Returns the winding rule which describes how inner path perimeters are filled and clipped.doublegetX()Returns the X of the path.doublegetY()Returns the Y of the path.inthandleAtPointForBounds(RMPoint aPoint, RMRect aRect, int selectedPoint, RMSize handleSize)Returns the handle index for a given point against this path scaled to the given rect.booleanhitHandle(RMPoint aPoint, int ptIndex, RMSize handleSize)Hit test the point (in path coords) against a given path point.booleanintersects(double x, double y, double w, double h)Returns whether the interior of the path intersects the interior of a specified rectangular area.booleanintersects(double x, double y, double w, double h, float lineWidth)Returns whether path drawn with given linewidth is hit by given rect.booleanintersects(RMPoint aPoint, float lineWidth)Returns whether path is hit by point for a path linewidth.booleanintersects(RMLine aLine)Returns whether path is hit by a line.booleanintersects(RMPath aPath, float lineWidth)Returns whether path drawn with given linewidth is hit by given path.booleanintersects(java.awt.geom.Rectangle2D aRect)Returns whether the interior of the path intersects the interior of a specified Rectangle2D.booleanisClosed()Returns whether path has any open subpaths.voidlineTo(double px, double py)Adds a LineTo element to the path for the given point.voidlineTo(RMPoint p)Adds a LineTo element to the path for the given point.voidmoveTo(double px, double py)Adds a MoveTo element to the path for the given point.voidmoveTo(RMPoint p)Adds a MoveTo element to the path for the given point.intpointCountForElementType(int element)Returns the total number of points associated with a given type of path element.RMPointpointInPathCoordsFromPoint(RMPoint aPoint, RMRect aRect)Returns the given point converted to path coords for given path bounds.booleanpointOnPath(int pointIndex)Returns true of the point at pointIndex is on the path, and false if it is on the convex hull.voidquadTo(double cpx, double cpy, double px, double py)Adds a QuadTo element to the path for the given point and control point.voidquadTo(RMPoint cp, RMPoint p)Adds a QuadTo element to the path for the given point and control point.voidrelativeCurveTo(RMPoint cp1, RMPoint cp2, RMPoint aPoint)Adds a CurveTo element to the path for the given point offset from the path's current point.voidrelativeLineTo(RMPoint aPoint)Adds a LineTo element to the path for the given point offset from the path's current point.voidrelativeMoveTo(RMPoint aPoint)Adds a MoveTo element to the path for the given point offset from the path's current point.voidremoveElement(int elementIndex)Removes an element, reconnecting the elements on either side of the deleted element.voidremoveLastElement()Removes the last element from the path.voidreset()Resets the current path with no elements or points.voidsetBounds(RMRect bounds)Sets the bounds that the path is relative to.voidsetPoint(int index, RMPoint point)Sets the path point at the given index to the given point.voidsetPointStructured(int index, RMPoint point)Resets the point at the given index to the given point, while preserving something.voidsetWindingRule(byte windingRule)Sets the winding rule which describes how inner path perimeters are filled and clipped.RXElementtoXML(RXArchiver anArchiver)XML archival.voidtransformBy(RMTransform aTransform)Transforms the points in the path by the given transform.
-
-
-
Field Detail
-
WIND_NON_ZERO
public static final byte WIND_NON_ZERO
- See Also:
- Constant Field Values
-
WIND_EVEN_ODD
public static final byte WIND_EVEN_ODD
- See Also:
- Constant Field Values
-
MOVE_TO
public static final byte MOVE_TO
- See Also:
- Constant Field Values
-
LINE_TO
public static final byte LINE_TO
- See Also:
- Constant Field Values
-
QUAD_TO
public static final byte QUAD_TO
- See Also:
- Constant Field Values
-
CURVE_TO
public static final byte CURVE_TO
- See Also:
- Constant Field Values
-
CLOSE
public static final byte CLOSE
- See Also:
- Constant Field Values
-
unitRectPath
public static final RMPath unitRectPath
-
-
Method Detail
-
moveTo
public void moveTo(RMPoint p)
Adds a MoveTo element to the path for the given point.
-
moveTo
public void moveTo(double px, double py)Adds a MoveTo element to the path for the given point.
-
lineTo
public void lineTo(RMPoint p)
Adds a LineTo element to the path for the given point.
-
lineTo
public void lineTo(double px, double py)Adds a LineTo element to the path for the given point.
-
quadTo
public void quadTo(RMPoint cp, RMPoint p)
Adds a QuadTo element to the path for the given point and control point.
-
quadTo
public void quadTo(double cpx, double cpy, double px, double py)Adds a QuadTo element to the path for the given point and control point.
-
curveTo
public void curveTo(RMPoint cp1, RMPoint cp2, RMPoint p)
Adds a CurveTo element to the path for the given point and control points.
-
curveTo
public void curveTo(double cp1x, double cp1y, double cp2x, double cp2y, double px, double py)Adds a CurveTo element to the path for the given point and control points.
-
closePath
public void closePath()
Adds a Close element to the given path.
-
reset
public void reset()
Resets the current path with no elements or points.
-
relativeMoveTo
public void relativeMoveTo(RMPoint aPoint)
Adds a MoveTo element to the path for the given point offset from the path's current point.
-
relativeLineTo
public void relativeLineTo(RMPoint aPoint)
Adds a LineTo element to the path for the given point offset from the path's current point.
-
relativeCurveTo
public void relativeCurveTo(RMPoint cp1, RMPoint cp2, RMPoint aPoint)
Adds a CurveTo element to the path for the given point offset from the path's current point.
-
getWindingRule
public byte getWindingRule()
Returns the winding rule which describes how inner path perimeters are filled and clipped.
-
setWindingRule
public void setWindingRule(byte windingRule)
Sets the winding rule which describes how inner path perimeters are filled and clipped.
-
getX
public double getX()
Returns the X of the path.
-
getY
public double getY()
Returns the Y of the path.
-
getWidth
public double getWidth()
Returns the width of the path.
-
getHeight
public double getHeight()
Returns the height of the path.
-
getBounds
public java.awt.Rectangle getBounds()
Returns the bounds for the path as an integer rect.- Specified by:
getBoundsin interfacejava.awt.Shape
-
getBounds2D
public RMRect getBounds2D()
Returns the bounds for the path.- Specified by:
getBounds2Din interfacejava.awt.Shape
-
setBounds
public void setBounds(RMRect bounds)
Sets the bounds that the path is relative to.
-
getControlPointBounds
public RMRect getControlPointBounds()
Returns the rectangle that encloses all the control points.
-
getElementCount
public int getElementCount()
Returns the number of elements in this path.
-
getElement
public byte getElement(int anIndex)
Returns the element type at the given index.
-
getElement
public byte getElement(int anIndex, RMPoint[] points)Returns the element type at the given index and its associated points (returned in the given point array).
-
getElementLast
public byte getElementLast()
Returns the last element.
-
getPointCount
public int getPointCount()
Returns the number of points in the path.
-
getPoint
public RMPoint getPoint(int anIndex)
Returns the point at the given index.
-
getPointLast
public RMPoint getPointLast()
Returns the last point in the path.
-
getElementPointIndex
public int getElementPointIndex(int anIndex)
Returns the point index for a given element.
-
getElementIndexForPointIndex
public int getElementIndexForPointIndex(int index)
Returns the element index for the given point index.
-
pointCountForElementType
public int pointCountForElementType(int element)
Returns the total number of points associated with a given type of path element.
-
pointOnPath
public boolean pointOnPath(int pointIndex)
Returns true of the point at pointIndex is on the path, and false if it is on the convex hull.
-
isClosed
public boolean isClosed()
Returns whether path has any open subpaths.
-
getPathInRect
public RMPath getPathInRect(java.awt.geom.Rectangle2D aRect)
Returns a copy of the path scaled to exactly fit in the given rect.
-
contains
public boolean contains(java.awt.geom.Point2D aPoint)
Returns whether the given point is inside the path.- Specified by:
containsin interfacejava.awt.Shape
-
contains
public boolean contains(double x, double y)Returns whether the given xy coordinate is inside the path.- Specified by:
containsin interfacejava.awt.Shape
-
contains
public boolean contains(java.awt.geom.Rectangle2D aRect)
Returns whether the interior of the shape entirely contains the specified rectangular area.- Specified by:
containsin interfacejava.awt.Shape
-
contains
public boolean contains(double x, double y, double w, double h)Returns whether the interior of the shape entirely contains the specified rectangular area.- Specified by:
containsin interfacejava.awt.Shape
-
intersects
public boolean intersects(java.awt.geom.Rectangle2D aRect)
Returns whether the interior of the path intersects the interior of a specified Rectangle2D.- Specified by:
intersectsin interfacejava.awt.Shape
-
intersects
public boolean intersects(double x, double y, double w, double h)Returns whether the interior of the path intersects the interior of a specified rectangular area.- Specified by:
intersectsin interfacejava.awt.Shape
-
intersects
public boolean intersects(RMPoint aPoint, float lineWidth)
Returns whether path is hit by point for a path linewidth.
-
intersects
public boolean intersects(RMLine aLine)
Returns whether path is hit by a line.
-
intersects
public boolean intersects(double x, double y, double w, double h, float lineWidth)Returns whether path drawn with given linewidth is hit by given rect.
-
intersects
public boolean intersects(RMPath aPath, float lineWidth)
Returns whether path drawn with given linewidth is hit by given path.
-
getHitInfo
public RMHitInfo getHitInfo(RMLine aLine, boolean findFirstHit)
Returns the hit info for the given line against this path.
-
getSegments
public java.util.List<? extends RMLine> getSegments()
Converts a path into a list of RMLine/RMQuadratic/RMBezier.
-
getSubpathsSegments
public java.util.List<java.util.List<? extends RMLine>> getSubpathsSegments()
Converts a path into a list subpath lists of RMLine/RMQuadratic/RMBezier.
-
addSegments
public void addSegments(java.util.List<? extends RMLine> theSegments)
Adds the list of segments to the path, starting with a moveto.
-
addSegment
public void addSegment(RMLine aSegment)
Adds the list of segments to the path, starting with a moveto.
-
arcLength
public double arcLength()
Returns the total arc length of path segments.
-
getHitInfo
public RMHitInfo getHitInfo(RMBezier aBezier, boolean findFirstHit)
Returns the hit info for the given bezier curve against this path.
-
handleAtPointForBounds
public int handleAtPointForBounds(RMPoint aPoint, RMRect aRect, int selectedPoint, RMSize handleSize)
Returns the handle index for a given point against this path scaled to the given rect. Only returns points that are on the path, except for the control points of selectedPoint (if not -1)
-
hitHandle
public boolean hitHandle(RMPoint aPoint, int ptIndex, RMSize handleSize)
Hit test the point (in path coords) against a given path point.
-
pointInPathCoordsFromPoint
public RMPoint pointInPathCoordsFromPoint(RMPoint aPoint, RMRect aRect)
Returns the given point converted to path coords for given path bounds.
-
removeLastElement
public void removeLastElement()
Removes the last element from the path.
-
removeElement
public void removeElement(int elementIndex)
Removes an element, reconnecting the elements on either side of the deleted element.
-
setPoint
public void setPoint(int index, RMPoint point)Sets the path point at the given index to the given point.
-
setPointStructured
public void setPointStructured(int index, RMPoint point)Resets the point at the given index to the given point, while preserving something.
-
getPathIterator
public java.awt.geom.PathIterator getPathIterator(java.awt.geom.AffineTransform aTransform)
Returns a path iterator for this path and the given transform.- Specified by:
getPathIteratorin interfacejava.awt.Shape
-
getPathIterator
public java.awt.geom.PathIterator getPathIterator(java.awt.geom.AffineTransform aTransform, double flatness)Returns a path iterator for this path and the given transform and flatness.- Specified by:
getPathIteratorin interfacejava.awt.Shape
-
transformBy
public void transformBy(RMTransform aTransform)
Transforms the points in the path by the given transform.
-
createTransformedPath
public RMPath createTransformedPath(java.awt.geom.AffineTransform aTransform)
Returns a transformed version of this path.
-
getReversedPath
public RMPath getReversedPath()
Returns a new path with the same points as this path, but in reverse order.
-
equals
public boolean equals(java.lang.Object anObj)
Standard equals implementation.- Overrides:
equalsin classjava.lang.Object
-
clone
public RMPath clone()
Standard clone implementation.- Overrides:
clonein classjava.lang.Object
-
toXML
public RXElement toXML(RXArchiver anArchiver)
XML archival.- Specified by:
toXMLin interfaceArchivable
-
fromXML
public java.lang.Object fromXML(RXArchiver anArchiver, RXElement anElement)
XML unarchival.- Specified by:
fromXMLin interfaceArchivable
-
-