Class mxCurve


  • public class mxCurve
    extends java.lang.Object
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String CORE_CURVE
      Defines the key for the central curve index
      protected java.util.Map<java.lang.String,​java.lang.Double> curveLengths
      The curve lengths of the curves
      java.util.List<mxPoint> guidePoints
      The points this curve is drawn through.
      protected java.util.Map<java.lang.String,​double[]> intervals
      An array of arrays of intervals.
      static mxLine INVALID_POSITION
      Indicates that an invalid position on a curve was requested
      static java.lang.String LABEL_CURVE
      Defines the key for the label curve index
      protected double labelBuffer
      Offset of the label curve from the curve the label curve is based on.
      protected double maxXBounds  
      protected double maxYBounds  
      protected double minXBounds  
      protected double minYBounds  
      protected java.util.Map<java.lang.String,​mxPoint[]> points
      A collection of arrays of curve points
      protected boolean valid
      Whether or not the curve currently holds valid values
    • Constructor Summary

      Constructors 
      Constructor Description
      mxCurve()  
      mxCurve​(java.util.List<mxPoint> points)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      mxPoint collisionMove​(java.lang.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 createCoreCurve()
      Creates the core curve that is based on the guide points passed into this class instance
      protected void createLabelCurve()  
      protected mxPoint[] getBaseLabelCurve()
      Returns the curve the label curve is too be based on
      mxRectangle getBounds()  
      double getCurveLength​(java.lang.String index)  
      mxLine getCurveParallel​(java.lang.String index, double distance)
      Returns a unit vector parallel to the curve at the specified distance along the curve.
      mxPoint[] getCurvePoints​(java.lang.String index)
      Obtains the points that make up the curve for the specified curve index.
      mxPoint[] getCurveSection​(java.lang.String index, double start, double end)
      Returns a section of the curve as an array of points
      java.util.List<mxPoint> getGuidePoints()  
      double[] getIntervals​(java.lang.String index)  
      protected int getLowerIndexOfSegment​(java.lang.String index, double distance)
      Calculates the index of the lower point on the segment that contains the point distance along the
      mxRectangle getRelativeFromAbsPoint​(mxPoint absPoint, java.lang.String index)
      Calculates the position of an absolute in terms relative to this curve.
      protected mxPoint intersectRectPerimeterPoint​(java.lang.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​(java.lang.String index, mxRectangle rect)
      Utility method to determine within which segment the specified rectangle intersects the specified curve
      protected int intersectRectPerimeterSeg​(java.lang.String index, mxRectangle rect, int startSegment)
      Utility method to determine within which segment the specified rectangle intersects the specified curve.
      boolean intersectsRect​(java.awt.Rectangle rect)
      Returns whether or not the rectangle passed in hits any part of this curve.
      mxPoint intersectsRectPerimeter​(java.lang.String index, mxRectangle rect)
      Returns the point at which this curve intersects the boundary of the given rectangle, if it does so.
      double intersectsRectPerimeterDist​(java.lang.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 isLabelReversed()
      Whether or not the label curve starts from the end target and traces to the start of the branch
      protected void populateIntervals​(java.lang.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 point
      void updateCurve​(java.util.List<mxPoint> newPoints)
      Updates the existing curve using the points passed in.
      protected boolean validateCurve()
      Method must be called before any attempt to access curve information
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • points

        protected java.util.Map<java.lang.String,​mxPoint[]> 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

        protected java.util.Map<java.lang.String,​double[]> intervals
        An array of arrays of intervals. These intervals define the distance along the edge (0 to 1) that each point lies
      • curveLengths

        protected java.util.Map<java.lang.String,​java.lang.Double> curveLengths
        The curve lengths of the curves
      • CORE_CURVE

        public static java.lang.String CORE_CURVE
        Defines the key for the central curve index
      • LABEL_CURVE

        public static java.lang.String LABEL_CURVE
        Defines the key for the label curve index
      • INVALID_POSITION

        public static mxLine INVALID_POSITION
        Indicates that an invalid position on a curve was requested
      • labelBuffer

        protected double labelBuffer
        Offset 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

        public java.util.List<mxPoint> 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 valid
        Whether or not the curve currently holds valid values
    • Constructor Detail

      • mxCurve

        public mxCurve()
      • mxCurve

        public mxCurve​(java.util.List<mxPoint> points)
    • Method Detail

      • setLabelBuffer

        public void setLabelBuffer​(double buffer)
      • getLowerIndexOfSegment

        protected int getLowerIndexOfSegment​(java.lang.String index,
                                             double distance)
        Calculates the index of the lower point on the segment that contains the point distance along the
      • getCurveParallel

        public mxLine getCurveParallel​(java.lang.String index,
                                       double distance)
        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 analyse
        distance - 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

        public mxPoint[] getCurveSection​(java.lang.String index,
                                         double start,
                                         double end)
        Returns a section of the curve as an array of points
        Parameters:
        index - the curve index specifying the curve to analyse
        start - 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

        public boolean intersectsRect​(java.awt.Rectangle rect)
        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

        public mxPoint intersectsRectPerimeter​(java.lang.String index,
                                               mxRectangle rect)
        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 analyse
        rect - 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

        public double intersectsRectPerimeterDist​(java.lang.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. 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 analyse
        rect - 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

        public mxPoint collisionMove​(java.lang.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. NOTE: Curves are scaled, the input rectangle should be also.
        Parameters:
        index - the curve index specifying the curve to analyse
        rect - the rectangle that is to be moved
        buffer - 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

        protected int intersectRectPerimeterSeg​(java.lang.String index,
                                                mxRectangle rect)
        Utility method to determine within which segment the specified rectangle intersects the specified curve
        Parameters:
        index - the curve index specifying the curve to analyse
        rect - 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

        protected int intersectRectPerimeterSeg​(java.lang.String index,
                                                mxRectangle rect,
                                                int startSegment)
        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 analyse
        rect - the whose boundary is to be tested for intersection with this curve
        startSegment - 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

        protected mxPoint intersectRectPerimeterPoint​(java.lang.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. If it does not intersect, null is returned.
        Parameters:
        curveIndex - the curve index specifying the curve to analyse
        rect - the whose boundary is to be tested for intersection with this curve
        indexSeg - 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

        public mxRectangle getRelativeFromAbsPoint​(mxPoint absPoint,
                                                   java.lang.String index)
        Calculates the position of an absolute in terms relative to this curve.
        Parameters:
        absPoint - the point whose relative point is to calculated
        index - 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

        protected mxPoint[] getBaseLabelCurve()
        Returns the curve the label curve is too be based on
      • populateIntervals

        protected void populateIntervals​(java.lang.String index)
      • updateCurve

        public void updateCurve​(java.util.List<mxPoint> newPoints)
        Updates the existing curve using the points passed in.
        Parameters:
        newPoints - the new guide points
      • getCurvePoints

        public mxPoint[] getCurvePoints​(java.lang.String index)
        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

        public double[] getIntervals​(java.lang.String index)
      • getCurveLength

        public double getCurveLength​(java.lang.String index)
      • 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

        public java.util.List<mxPoint> getGuidePoints()
        Returns:
        the guidePoints