Package com.mxgraph.util
Class mxCurve
java.lang.Object
com.mxgraph.util.mxCurve
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic String
Defines the key for the central curve indexThe curve lengths of the curvesThe points this curve is drawn through.An array of arrays of intervals.static mxLine
Indicates that an invalid position on a curve was requestedstatic String
Defines the key for the label curve indexprotected double
Offset of the label curve from the curve the label curve is based on.protected double
protected double
protected double
protected double
A collection of arrays of curve pointsprotected boolean
Whether or not the curve currently holds valid values -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncollisionMove
(String index, mxRectangle rect, double buffer) Returns a point to move the input rectangle to, in order to attempt to place the rectangle away from the curve.protected void
Creates the core curve that is based on the guide points passed into this class instanceprotected void
protected mxPoint[]
Returns the curve the label curve is too be based ondouble
getCurveLength
(String index) getCurveParallel
(String index, double distance) Returns a unit vector parallel to the curve at the specified distance along the curve.mxPoint[]
getCurvePoints
(String index) Obtains the points that make up the curve for the specified curve index.mxPoint[]
getCurveSection
(String index, double start, double end) Returns a section of the curve as an array of pointsdouble[]
getIntervals
(String index) protected int
getLowerIndexOfSegment
(String index, double distance) Calculates the index of the lower point on the segment that contains the point distance along thegetRelativeFromAbsPoint
(mxPoint absPoint, String index) Calculates the position of an absolute in terms relative to this curve.protected mxPoint
intersectRectPerimeterPoint
(String curveIndex, mxRectangle rect, int indexSeg) Returns the point at which this curve segment intersects the boundary of the given rectangle, if it does so.protected int
intersectRectPerimeterSeg
(String index, mxRectangle rect) Utility method to determine within which segment the specified rectangle intersects the specified curveprotected int
intersectRectPerimeterSeg
(String index, mxRectangle rect, int startSegment) Utility method to determine within which segment the specified rectangle intersects the specified curve.boolean
intersectsRect
(Rectangle rect) Returns whether or not the rectangle passed in hits any part of this curve.intersectsRectPerimeter
(String index, mxRectangle rect) Returns the point at which this curve intersects the boundary of the given rectangle, if it does so.double
intersectsRectPerimeterDist
(String index, mxRectangle rect) Returns the distance from the start of the curve at which this curve intersects the boundary of the given rectangle, if it does so.boolean
Whether or not the label curve starts from the end target and traces to the start of the branchprotected void
populateIntervals
(String index) void
setLabelBuffer
(double buffer) protected void
updateBounds
(double pointX, double pointY) Updates the total bounds of this curve, increasing any dimensions, if necessary, to fit in the specified pointvoid
updateCurve
(List<mxPoint> newPoints) Updates the existing curve using the points passed in.protected boolean
Method must be called before any attempt to access curve information
-
Field Details
-
points
A collection of arrays of curve points -
minXBounds
protected double minXBounds -
maxXBounds
protected double maxXBounds -
minYBounds
protected double minYBounds -
maxYBounds
protected double maxYBounds -
intervals
An array of arrays of intervals. These intervals define the distance along the edge (0 to 1) that each point lies -
curveLengths
The curve lengths of the curves -
CORE_CURVE
Defines the key for the central curve index -
LABEL_CURVE
Defines the key for the label curve index -
INVALID_POSITION
Indicates that an invalid position on a curve was requested -
labelBuffer
protected double labelBufferOffset of the label curve from the curve the label curve is based on. If you wish to set this value, do so directly after creation of the curve. The first time the curve is used the label curve will be created with whatever value is contained in this variable. Changes to it after that point will have no effect. -
guidePoints
The points this curve is drawn through. These are typically control points and are at distances from each other that straight lines between them do not describe a smooth curve. This class takes these guiding points and creates a finer set of internal points that visually appears to be a curve when linked by straight lines -
valid
protected boolean validWhether or not the curve currently holds valid values
-
-
Constructor Details
-
mxCurve
public mxCurve() -
mxCurve
-
-
Method Details
-
setLabelBuffer
public void setLabelBuffer(double buffer) -
getBounds
-
getLowerIndexOfSegment
Calculates the index of the lower point on the segment that contains the point distance along the -
getCurveParallel
Returns a unit vector parallel to the curve at the specified distance along the curve. To obtain the angle the vector makes with (1,0) perform Math.atan(segVectorY/segVectorX).- Parameters:
index
- the curve index specifying the curve to analysedistance
- the distance from start to end of curve (0.0...1.0)- Returns:
- a unit vector at the specified point on the curve represented
as a line, parallel with the curve. If the distance or curve is
invalid,
mxCurve.INVALID_POSITION
is returned
-
getCurveSection
Returns a section of the curve as an array of points- Parameters:
index
- the curve index specifying the curve to analysestart
- the start position of the curve segment (0.0...1.0)end
- the end position of the curve segment (0.0...1.0)- Returns:
- a sequence of point representing the curve section or null if it cannot be calculated
-
intersectsRect
Returns whether or not the rectangle passed in hits any part of this curve.- Parameters:
rect
- the rectangle to detect for a hit- Returns:
- whether or not the rectangle hits this curve
-
intersectsRectPerimeter
Returns the point at which this curve intersects the boundary of the given rectangle, if it does so. If it does not intersect, null is returned. If it intersects multiple times, the first intersection from the start end of the curve is returned.- Parameters:
index
- the curve index specifying the curve to analyserect
- the whose boundary is to be tested for intersection with this curve- Returns:
- the point at which this curve intersects the boundary of the given rectangle, if it does so. If it does not intersect, null is returned.
-
intersectsRectPerimeterDist
Returns the distance from the start of the curve at which this curve intersects the boundary of the given rectangle, if it does so. If it does not intersect, -1 is returned. If it intersects multiple times, the first intersection from the start end of the curve is returned.- Parameters:
index
- the curve index specifying the curve to analyserect
- the whose boundary is to be tested for intersection with this curve- Returns:
- the distance along the curve from the start at which the intersection occurs
-
collisionMove
Returns a point to move the input rectangle to, in order to attempt to place the rectangle away from the curve. NOTE: Curves are scaled, the input rectangle should be also.- Parameters:
index
- the curve index specifying the curve to analyserect
- the rectangle that is to be movedbuffer
- the amount by which the rectangle is to be moved, beyond the dimensions of the rect- Returns:
- the point to move the top left of the input rect to , otherwise null if no point can be determined
-
intersectRectPerimeterSeg
Utility method to determine within which segment the specified rectangle intersects the specified curve- Parameters:
index
- the curve index specifying the curve to analyserect
- the whose boundary is to be tested for intersection with this curve- Returns:
- the point at which this curve intersects the boundary of the given rectangle, if it does so. If it does not intersect, -1 is returned
-
intersectRectPerimeterSeg
Utility method to determine within which segment the specified rectangle intersects the specified curve. This method specifies which segment to start searching at.- Parameters:
index
- the curve index specifying the curve to analyserect
- the whose boundary is to be tested for intersection with this curvestartSegment
- the segment to start searching at. To start at the beginning of the curve, use 1, not 0.- Returns:
- the point at which this curve intersects the boundary of the given rectangle, if it does so. If it does not intersect, -1 is returned
-
intersectRectPerimeterPoint
Returns the point at which this curve segment intersects the boundary of the given rectangle, if it does so. If it does not intersect, null is returned.- Parameters:
curveIndex
- the curve index specifying the curve to analyserect
- the whose boundary is to be tested for intersection with this curveindexSeg
- the segments on this curve being checked- Returns:
- the point at which this curve segment intersects the boundary of the given rectangle, if it does so. If it does not intersect, null is returned.
-
getRelativeFromAbsPoint
Calculates the position of an absolute in terms relative to this curve.- Parameters:
absPoint
- the point whose relative point is to calculatedindex
- the index of the curve whom the relative position is to be calculated from- Returns:
- an mxRectangle where the x is the distance along the curve (0 to 1), y is the orthogonal offset from the closest segment on the curve and (width, height) is an additional Cartesian offset applied after the other calculations
-
createCoreCurve
protected void createCoreCurve()Creates the core curve that is based on the guide points passed into this class instance -
isLabelReversed
public boolean isLabelReversed()Whether or not the label curve starts from the end target and traces to the start of the branch- Returns:
- whether the label curve is reversed
-
createLabelCurve
protected void createLabelCurve() -
getBaseLabelCurve
Returns the curve the label curve is too be based on -
populateIntervals
-
updateCurve
Updates the existing curve using the points passed in.- Parameters:
newPoints
- the new guide points
-
getCurvePoints
Obtains the points that make up the curve for the specified curve index. If that curve, or the core curve that other curves are based on have not yet been created, then they are lazily created. If creation is impossible, null is returned- Parameters:
index
- the key specifying the curve- Returns:
- the points making up that curve, or null
-
getIntervals
-
getCurveLength
-
validateCurve
protected boolean validateCurve()Method must be called before any attempt to access curve information- Returns:
- whether or not the curve may be used
-
updateBounds
protected void updateBounds(double pointX, double pointY) Updates the total bounds of this curve, increasing any dimensions, if necessary, to fit in the specified point -
getGuidePoints
- Returns:
- the guidePoints
-