Package com.graphbuilder.curve
Class ShapeMultiPath
java.lang.Object
com.graphbuilder.curve.MultiPath
com.graphbuilder.curve.ShapeMultiPath
- All Implemented Interfaces:
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
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs a new ShapeMultiPath with a dimension of 2.ShapeMultiPath(int dimension) Constructs a new ShapeMultiPath with the specified dimension requirement. -
Method Summary
Modifier and TypeMethodDescriptionbooleancontains(double x, double y) Returns true if the point is contained inside the shape.booleancontains(double x1, double y1, double w, double h) Returns true only if the shape contains all points of the rectangle.booleanSee the contains(x, y) method.booleanSee the contains(x, y, w, h) method.int[]Returns a new integer array with the basis vectors.See the getBounds2D() method.Computes the bounding box of the points.doublegetDistSq(double x, double y) Returns the minimum distance^2 from the specified point to the line segments of this multi-path.Returns a new PathIterator object.getPathIterator(AffineTransform at, double flatness) Returns a new PathIterator object.intReturns the value of the winding rule.booleanintersects(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.booleanSee the intersects(x, y, w, h) method.voidsetBasisVectors(int[] b) The basis vectors specify which index corresponds to the x-axis and which index corresponds to the y-axis.voidsetWindingRule(int rule) Sets the winding rule.Methods inherited from class com.graphbuilder.curve.MultiPath
ensureCapacity, get, getCapacity, getDimension, getDistSq, getFlatness, getNumPoints, getType, lineTo, moveTo, set, setFlatness, setNumPoints, setType, trimArray
-
Constructor Details
-
ShapeMultiPath
public ShapeMultiPath()Constructs a new ShapeMultiPath with a dimension of 2. -
ShapeMultiPath
public ShapeMultiPath(int dimension) Constructs a new ShapeMultiPath with the specified dimension requirement.- Throws:
IllegalArgumentException- If the specified dimension is less than 2.
-
-
Method Details
-
setBasisVectors
public void setBasisVectors(int[] b) The basis vectors specify which index corresponds to the x-axis and which index corresponds to the y-axis. The value of the x-axis is at index location 0 and the value of the y-axis is at index location 1.- Throws:
IllegalArgumentException- If the axis values are less than 0 or greater than or equal to the dimension.- See Also:
-
getBasisVectors
public int[] getBasisVectors()Returns a new integer array with the basis vectors. The default basis vectors are {0, 1}.- See Also:
-
getDistSq
public double getDistSq(double x, double y) Returns the minimum distance^2 from the specified point to the line segments of this multi-path. -
getWindingRule
public int getWindingRule()Returns the value of the winding rule. The default value is PathIterator.WIND_EVEN_ODD.- See Also:
-
setWindingRule
public void setWindingRule(int rule) Sets the winding rule. The winding rule can either by PathIterator.WIND_EVEN_ODD or PathIterator.WIND_NON_ZERO, otherwise an IllegalArgumentException is thrown. -
getPathIterator
Returns a new PathIterator object.- Specified by:
getPathIteratorin interfaceShape
-
getPathIterator
Returns a new PathIterator object. The flatness parameter is ignored since a multi-path, by definition, is already flat.- Specified by:
getPathIteratorin interfaceShape
-
getBounds
See the getBounds2D() method. -
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:
getBounds2Din interfaceShape
-
contains
public boolean contains(double x, double y) Returns true if the point is contained inside the shape. Otherwise false is returned. -
contains
See the contains(x, y) method. -
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. -
contains
See the contains(x, y, w, h) method. -
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:
intersectsin interfaceShape
-
intersects
See the intersects(x, y, w, h) method.- Specified by:
intersectsin interfaceShape- See Also:
-