Class ShapeMultiPath

  • All Implemented Interfaces:
    java.awt.Shape

    public class ShapeMultiPath
    extends java.lang.Object
    implements java.awt.Shape
    The ShapeMultiPath is-a MultiPath and implements the java.awt.Shape interface. Here is an example of how to use a ShapeMultiPath:

     ControlPath cp = new ControlPath();
     cp.addPoint(...); // add points
     Curve c = new BezierCurve(cp, new GroupIterator("0:n-1"));
    
     ShapeMultiPath smp = new ShapeMultiPath();
     c.appendTo(smp);
    
     Graphics2D g = ...;
     g.draw(smp);
    
     
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.Object MOVE_TO  
    • Constructor Summary

      Constructors 
      Constructor Description
      ShapeMultiPath​(int dimension)
      Constructs a new ShapeMultiPath with the specified dimension requirement.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean contains​(double x, double y)
      Returns true if the point is contained inside the shape.
      boolean contains​(double x1, double y1, double w, double h)
      Returns true only if the shape contains all points of the rectangle.
      boolean contains​(java.awt.geom.Point2D p)
      See the contains(x, y) method.
      boolean contains​(java.awt.geom.Rectangle2D r)
      See the contains(x, y, w, h) method.
      double[] get​(int index)
      Returns a reference to the point at the specified index.
      int[] getBasisVectors()
      Returns a new integer array with the basis vectors.
      java.awt.Rectangle getBounds()
      See the getBounds2D() method.
      java.awt.geom.Rectangle2D getBounds2D()
      Computes the bounding box of the points.
      int getDimension()
      Returns the dimension.
      double getFlatness()
      Returns the flatness.
      int getNumPoints()
      Returns the size counter.
      java.awt.geom.PathIterator getPathIterator​(java.awt.geom.AffineTransform at)
      Returns a new PathIterator object.
      java.awt.geom.PathIterator getPathIterator​(java.awt.geom.AffineTransform at, double flatness)
      Returns a new PathIterator object.
      java.lang.Object getType​(int index)
      Returns the type of the point at the specified index.
      int getWindingRule()
      Returns the value of the winding rule.
      boolean intersects​(double x1, double y1, double w, double h)
      This method returns true if any line segment in this multi-path intersects any of the 4 line segments formed by the rectangle or any corner of the rectangle is inside the shape or any point of the shape is inside the rectangle.
      boolean intersects​(java.awt.geom.Rectangle2D r)
      See the intersects(x, y, w, h) method.
      void lineTo​(double[] p)
      Appends a point of type LINE_TO.
      void moveTo​(double[] p)
      Appends a point of type MOVE_TO.
      void setFlatness​(double f)
      Sets the flatness.
      • Methods inherited from class java.lang.Object

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

      • MOVE_TO

        public static final java.lang.Object MOVE_TO
    • Constructor Detail

      • ShapeMultiPath

        public ShapeMultiPath​(int dimension)
        Constructs a new ShapeMultiPath with the specified dimension requirement.
    • Method Detail

      • getBasisVectors

        public int[] getBasisVectors()
        Returns a new integer array with the basis vectors. The default basis vectors are {0, 1}.
      • getWindingRule

        public int getWindingRule()
        Returns the value of the winding rule. The default value is PathIterator.WIND_EVEN_ODD.
      • getPathIterator

        public java.awt.geom.PathIterator getPathIterator​(java.awt.geom.AffineTransform at)
        Returns a new PathIterator object.
        Specified by:
        getPathIterator in interface java.awt.Shape
      • getPathIterator

        public java.awt.geom.PathIterator getPathIterator​(java.awt.geom.AffineTransform at,
                                                          double flatness)
        Returns a new PathIterator object. The flatness parameter is ignored since a multi-path, by definition, is already flat.
        Specified by:
        getPathIterator in interface java.awt.Shape
      • getBounds

        public java.awt.Rectangle getBounds()
        See the getBounds2D() method.
        Specified by:
        getBounds in interface java.awt.Shape
        See Also:
        getBounds2D()
      • getBounds2D

        public java.awt.geom.Rectangle2D getBounds2D()
        Computes the bounding box of the points. When computing the bounding box, a point is considered if it is of type LINE_TO or it is of type MOVE_TO and the next point is of type LINE_TO. A value of null is returned if there is not enough data to define a bounding box.
        Specified by:
        getBounds2D in interface java.awt.Shape
      • contains

        public boolean contains​(double x,
                                double y)
        Returns true if the point is contained inside the shape. Otherwise false is returned.
        Specified by:
        contains in interface java.awt.Shape
      • contains

        public boolean contains​(java.awt.geom.Point2D p)
        See the contains(x, y) method.
        Specified by:
        contains in interface java.awt.Shape
        See Also:
        contains(double, double)
      • contains

        public boolean contains​(double x1,
                                double y1,
                                double w,
                                double h)
        Returns true only if the shape contains all points of the rectangle. First, if any of the four corners is not contained in the shape then false is returned. Now we know that all four corners are inside the shape. Next, we check to see if any line segment of this shape intersects any of the 4 line segments formed by the rectangle. If there is an intersection, then false is returned. Otherwise true is returned.
        Specified by:
        contains in interface java.awt.Shape
      • contains

        public boolean contains​(java.awt.geom.Rectangle2D r)
        See the contains(x, y, w, h) method.
        Specified by:
        contains in interface java.awt.Shape
        See Also:
        contains(double, double, double, double)
      • intersects

        public boolean intersects​(double x1,
                                  double y1,
                                  double w,
                                  double h)
        This method returns true if any line segment in this multi-path intersects any of the 4 line segments formed by the rectangle or any corner of the rectangle is inside the shape or any point of the shape is inside the rectangle. Otherwise false is returned.
        Specified by:
        intersects in interface java.awt.Shape
      • intersects

        public boolean intersects​(java.awt.geom.Rectangle2D r)
        See the intersects(x, y, w, h) method.
        Specified by:
        intersects in interface java.awt.Shape
        See Also:
        intersects(double, double, double, double)
      • getDimension

        public int getDimension()
        Returns the dimension. The dimension is used by the BinaryCurveApproximationAlgorithm to know what dimension of points to create. If the dimension of the multi-path is greater than the dimension of the control points for a curve, then an ArrayIndexOutOfBoundsException will occur when the curve is appended to the MultiPath.
      • getFlatness

        public double getFlatness()
        Returns the flatness. The flatness is used by the BinaryCurveApproximationAlgorithm to determine how closely the line segements formed by the points of this multi-path should approximate a given curve. The default flatness value is 1.0. When using curves in a graphics environment, the flatness usually inversely proportional to the scale.
        See Also:
        setFlatness(double)
      • setFlatness

        public void setFlatness​(double f)
        Sets the flatness. As the flatness value gets closer to zero, the BinaryCurveApproximationAlgorithm generates more points.
        See Also:
        getFlatness()
      • get

        public double[] get​(int index)
        Returns a reference to the point at the specified index.
      • getType

        public java.lang.Object getType​(int index)
        Returns the type of the point at the specified index. The type can other be MultiPath.MOVE_TO or MultiPath.LINE_TO.
      • getNumPoints

        public int getNumPoints()
        Returns the size counter.
      • lineTo

        public void lineTo​(double[] p)
        Appends a point of type LINE_TO. If the size counter is 0 then the request is interpretted as a MOVE_TO request.
        See Also:
        moveTo(double[])
      • moveTo

        public void moveTo​(double[] p)
        Appends a point of type MOVE_TO.
        See Also:
        lineTo(double[])