Package org.jfree.chart.util
Class ShapeUtils
- java.lang.Object
-
- org.jfree.chart.util.ShapeUtils
-
public class ShapeUtils extends java.lang.ObjectUtility methods forShapeobjects.
-
-
Field Summary
Fields Modifier and Type Field Description private static floatSQRT2A useful constant used internally.
-
Constructor Summary
Constructors Modifier Constructor Description privateShapeUtils()Prevents instantiation.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.awt.Shapeclone(java.awt.Shape shape)Returns a clone of the specified shape, ornull.static booleancontains(java.awt.geom.Rectangle2D rect1, java.awt.geom.Rectangle2D rect2)Checks, whether the given rectangle1 fully contains rectangle 2 (even if rectangle 2 has a height or width of zero!).static java.awt.ShapecreateDiagonalCross(float l, float t)Creates a diagonal cross shape.static java.awt.ShapecreateDiamond(float s)Creates a diamond shape.static java.awt.ShapecreateDownTriangle(float s)Creates a triangle shape that points downwards.static java.awt.ShapecreateLineRegion(java.awt.geom.Line2D line, float width)Creates a region surrounding a line segment by 'widening' the line segment.static java.awt.ShapecreateRegularCross(float l, float t)Creates a diagonal cross shape.static java.awt.ShapecreateTranslatedShape(java.awt.Shape shape, double transX, double transY)Creates and returns a translated shape.static java.awt.ShapecreateTranslatedShape(java.awt.Shape shape, RectangleAnchor anchor, double locationX, double locationY)Translates a shape to a new location such that the anchor point (relative to the rectangular bounds of the shape) aligns with the specified (x, y) coordinate in Java2D space.static java.awt.ShapecreateUpTriangle(float s)Creates a triangle shape that points upwards.static voiddrawRotatedShape(java.awt.Graphics2D g2, java.awt.Shape shape, double angle, float x, float y)Draws a shape with the specified rotation about(x, y).static booleanequal(java.awt.geom.Arc2D a1, java.awt.geom.Arc2D a2)Compares two arcs and returnstrueif they are equal or bothnull.static booleanequal(java.awt.geom.Ellipse2D e1, java.awt.geom.Ellipse2D e2)Compares two ellipses and returnstrueif they are equal or bothnull.static booleanequal(java.awt.geom.GeneralPath p1, java.awt.geom.GeneralPath p2)Tests two polygons for equality.static booleanequal(java.awt.geom.Line2D l1, java.awt.geom.Line2D l2)Compares two lines are returnstrueif they are equal or bothnull.static booleanequal(java.awt.Polygon p1, java.awt.Polygon p2)Tests two polygons for equality.static booleanequal(java.awt.Shape s1, java.awt.Shape s2)Tests two shapes for equality.static java.awt.geom.Point2DgetPointInRectangle(double x, double y, java.awt.geom.Rectangle2D area)Returns a point based on (x, y) but constrained to be within the bounds of a given rectangle.static booleanintersects(java.awt.geom.Rectangle2D rect1, java.awt.geom.Rectangle2D rect2)Checks, whether the given rectangle1 fully contains rectangle 2 (even if rectangle 2 has a height or width of zero!).static booleanisPointInRect(java.awt.geom.Rectangle2D rect, double x, double y)Returnstrueif the specified point (x, y) falls within or on the boundary of the specified rectangle.static java.awt.ShaperotateShape(java.awt.Shape base, double angle, float x, float y)Rotates a shape about the specified coordinates.
-
-
-
Method Detail
-
clone
public static java.awt.Shape clone(java.awt.Shape shape)
Returns a clone of the specified shape, ornull. At the current time, this method supports cloning for instances ofLine2D,RectangularShape,AreaandGeneralPath.RectangularShapeincludesArc2D,Ellipse2D,Rectangle2D,RoundRectangle2D.- Parameters:
shape- the shape to clone (nullpermitted, returnsnull).- Returns:
- A clone or
null.
-
equal
public static boolean equal(java.awt.Shape s1, java.awt.Shape s2)Tests two shapes for equality. If both shapes arenull, this method will returntrue.In the current implementation, the following shapes are supported:
Ellipse2D,Line2DandRectangle2D(implicit).- Parameters:
s1- the first shape (nullpermitted).s2- the second shape (nullpermitted).- Returns:
- A boolean.
-
equal
public static boolean equal(java.awt.geom.Line2D l1, java.awt.geom.Line2D l2)Compares two lines are returnstrueif they are equal or bothnull.- Parameters:
l1- the first line (nullpermitted).l2- the second line (nullpermitted).- Returns:
- A boolean.
-
equal
public static boolean equal(java.awt.geom.Ellipse2D e1, java.awt.geom.Ellipse2D e2)Compares two ellipses and returnstrueif they are equal or bothnull.- Parameters:
e1- the first ellipse (nullpermitted).e2- the second ellipse (nullpermitted).- Returns:
- A boolean.
-
equal
public static boolean equal(java.awt.geom.Arc2D a1, java.awt.geom.Arc2D a2)Compares two arcs and returnstrueif they are equal or bothnull.- Parameters:
a1- the first arc (nullpermitted).a2- the second arc (nullpermitted).- Returns:
- A boolean.
-
equal
public static boolean equal(java.awt.Polygon p1, java.awt.Polygon p2)Tests two polygons for equality. If both arenullthis method returnstrue.- Parameters:
p1- polygon 1 (nullpermitted).p2- polygon 2 (nullpermitted).- Returns:
- A boolean.
-
equal
public static boolean equal(java.awt.geom.GeneralPath p1, java.awt.geom.GeneralPath p2)Tests two polygons for equality. If both arenullthis method returnstrue.- Parameters:
p1- path 1 (nullpermitted).p2- path 2 (nullpermitted).- Returns:
- A boolean.
-
createTranslatedShape
public static java.awt.Shape createTranslatedShape(java.awt.Shape shape, double transX, double transY)Creates and returns a translated shape.- Parameters:
shape- the shape (nullnot permitted).transX- the x translation (in Java2D space).transY- the y translation (in Java2D space).- Returns:
- The translated shape.
-
createTranslatedShape
public static java.awt.Shape createTranslatedShape(java.awt.Shape shape, RectangleAnchor anchor, double locationX, double locationY)Translates a shape to a new location such that the anchor point (relative to the rectangular bounds of the shape) aligns with the specified (x, y) coordinate in Java2D space.- Parameters:
shape- the shape (nullnot permitted).anchor- the anchor (nullnot permitted).locationX- the x-coordinate (in Java2D space).locationY- the y-coordinate (in Java2D space).- Returns:
- A new and translated shape.
-
rotateShape
public static java.awt.Shape rotateShape(java.awt.Shape base, double angle, float x, float y)Rotates a shape about the specified coordinates.- Parameters:
base- the shape (nullpermitted, returnsnull).angle- the angle (in radians).x- the x coordinate for the rotation point (in Java2D space).y- the y coordinate for the rotation point (in Java2D space).- Returns:
- the rotated shape.
-
drawRotatedShape
public static void drawRotatedShape(java.awt.Graphics2D g2, java.awt.Shape shape, double angle, float x, float y)Draws a shape with the specified rotation about(x, y).- Parameters:
g2- the graphics device (nullnot permitted).shape- the shape (nullnot permitted).angle- the angle (in radians).x- the x coordinate for the rotation point.y- the y coordinate for the rotation point.
-
createDiagonalCross
public static java.awt.Shape createDiagonalCross(float l, float t)Creates a diagonal cross shape.- Parameters:
l- the length of each 'arm'.t- the thickness.- Returns:
- A diagonal cross shape.
-
createRegularCross
public static java.awt.Shape createRegularCross(float l, float t)Creates a diagonal cross shape.- Parameters:
l- the length of each 'arm'.t- the thickness.- Returns:
- A diagonal cross shape.
-
createDiamond
public static java.awt.Shape createDiamond(float s)
Creates a diamond shape.- Parameters:
s- the size factor (equal to half the height of the diamond).- Returns:
- A diamond shape.
-
createUpTriangle
public static java.awt.Shape createUpTriangle(float s)
Creates a triangle shape that points upwards.- Parameters:
s- the size factor (equal to half the height of the triangle).- Returns:
- A triangle shape.
-
createDownTriangle
public static java.awt.Shape createDownTriangle(float s)
Creates a triangle shape that points downwards.- Parameters:
s- the size factor (equal to half the height of the triangle).- Returns:
- A triangle shape.
-
createLineRegion
public static java.awt.Shape createLineRegion(java.awt.geom.Line2D line, float width)Creates a region surrounding a line segment by 'widening' the line segment. A typical use for this method is the creation of a 'clickable' region for a line that is displayed on-screen.- Parameters:
line- the line (nullnot permitted).width- the width of the region.- Returns:
- A region that surrounds the line.
-
getPointInRectangle
public static java.awt.geom.Point2D getPointInRectangle(double x, double y, java.awt.geom.Rectangle2D area)Returns a point based on (x, y) but constrained to be within the bounds of a given rectangle.- Parameters:
x- the x-coordinate.y- the y-coordinate.area- the constraining rectangle (nullnot permitted).- Returns:
- A point within the rectangle.
- Throws:
java.lang.NullPointerException- ifareaisnull.
-
contains
public static boolean contains(java.awt.geom.Rectangle2D rect1, java.awt.geom.Rectangle2D rect2)Checks, whether the given rectangle1 fully contains rectangle 2 (even if rectangle 2 has a height or width of zero!).- Parameters:
rect1- the first rectangle.rect2- the second rectangle.- Returns:
- A boolean.
-
intersects
public static boolean intersects(java.awt.geom.Rectangle2D rect1, java.awt.geom.Rectangle2D rect2)Checks, whether the given rectangle1 fully contains rectangle 2 (even if rectangle 2 has a height or width of zero!).- Parameters:
rect1- the first rectangle.rect2- the second rectangle.- Returns:
- A boolean.
-
isPointInRect
public static boolean isPointInRect(java.awt.geom.Rectangle2D rect, double x, double y)Returnstrueif the specified point (x, y) falls within or on the boundary of the specified rectangle.- Parameters:
rect- the rectangle (nullnot permitted).x- the x-coordinate.y- the y-coordinate.- Returns:
- A boolean.
-
-