java.lang.Object
org.jfree.chart.util.ShapeUtils
Utility methods for
Shape
objects.-
Method Summary
Modifier and TypeMethodDescriptionstatic Shape
Returns a clone of the specified shape, ornull
.static boolean
contains
(Rectangle2D rect1, Rectangle2D rect2) Checks, whether the given rectangle1 fully contains rectangle 2 (even if rectangle 2 has a height or width of zero!).static Shape
createDiagonalCross
(float l, float t) Creates a diagonal cross shape.static Shape
createDiamond
(float s) Creates a diamond shape.static Shape
createDownTriangle
(float s) Creates a triangle shape that points downwards.static Shape
createLineRegion
(Line2D line, float width) Creates a region surrounding a line segment by 'widening' the line segment.static Shape
createRegularCross
(float l, float t) Creates a diagonal cross shape.static Shape
createTranslatedShape
(Shape shape, double transX, double transY) Creates and returns a translated shape.static Shape
createTranslatedShape
(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 Shape
createUpTriangle
(float s) Creates a triangle shape that points upwards.static void
drawRotatedShape
(Graphics2D g2, Shape shape, double angle, float x, float y) Draws a shape with the specified rotation about(x, y)
.static boolean
Compares two arcs and returnstrue
if they are equal or bothnull
.static boolean
Compares two ellipses and returnstrue
if they are equal or bothnull
.static boolean
equal
(GeneralPath p1, GeneralPath p2) Tests two polygons for equality.static boolean
Compares two lines are returnstrue
if they are equal or bothnull
.static boolean
Tests two polygons for equality.static boolean
Tests two shapes for equality.static Point2D
getPointInRectangle
(double x, double y, Rectangle2D area) Returns a point based on (x, y) but constrained to be within the bounds of a given rectangle.static boolean
intersects
(Rectangle2D rect1, Rectangle2D rect2) Checks, whether the given rectangle1 fully contains rectangle 2 (even if rectangle 2 has a height or width of zero!).static boolean
isPointInRect
(Rectangle2D rect, double x, double y) Returnstrue
if the specified point (x, y) falls within or on the boundary of the specified rectangle.static Shape
rotateShape
(Shape base, double angle, float x, float y) Rotates a shape about the specified coordinates.
-
Method Details
-
clone
Returns a clone of the specified shape, ornull
. At the current time, this method supports cloning for instances ofLine2D
,RectangularShape
,Area
andGeneralPath
.RectangularShape
includesArc2D
,Ellipse2D
,Rectangle2D
,RoundRectangle2D
.- Parameters:
shape
- the shape to clone (null
permitted, returnsnull
).- Returns:
- A clone or
null
.
-
equal
Tests two shapes for equality. If both shapes arenull
, this method will returntrue
.In the current implementation, the following shapes are supported:
Ellipse2D
,Line2D
andRectangle2D
(implicit).- Parameters:
s1
- the first shape (null
permitted).s2
- the second shape (null
permitted).- Returns:
- A boolean.
-
equal
Compares two lines are returnstrue
if they are equal or bothnull
.- Parameters:
l1
- the first line (null
permitted).l2
- the second line (null
permitted).- Returns:
- A boolean.
-
equal
Compares two ellipses and returnstrue
if they are equal or bothnull
.- Parameters:
e1
- the first ellipse (null
permitted).e2
- the second ellipse (null
permitted).- Returns:
- A boolean.
-
equal
Compares two arcs and returnstrue
if they are equal or bothnull
.- Parameters:
a1
- the first arc (null
permitted).a2
- the second arc (null
permitted).- Returns:
- A boolean.
-
equal
Tests two polygons for equality. If both arenull
this method returnstrue
.- Parameters:
p1
- polygon 1 (null
permitted).p2
- polygon 2 (null
permitted).- Returns:
- A boolean.
-
equal
Tests two polygons for equality. If both arenull
this method returnstrue
.- Parameters:
p1
- path 1 (null
permitted).p2
- path 2 (null
permitted).- Returns:
- A boolean.
-
createTranslatedShape
Creates and returns a translated shape.- Parameters:
shape
- the shape (null
not permitted).transX
- the x translation (in Java2D space).transY
- the y translation (in Java2D space).- Returns:
- The translated shape.
-
createTranslatedShape
public static Shape createTranslatedShape(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 (null
not permitted).anchor
- the anchor (null
not permitted).locationX
- the x-coordinate (in Java2D space).locationY
- the y-coordinate (in Java2D space).- Returns:
- A new and translated shape.
-
rotateShape
Rotates a shape about the specified coordinates.- Parameters:
base
- the shape (null
permitted, 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
Draws a shape with the specified rotation about(x, y)
.- Parameters:
g2
- the graphics device (null
not permitted).shape
- the shape (null
not permitted).angle
- the angle (in radians).x
- the x coordinate for the rotation point.y
- the y coordinate for the rotation point.
-
createDiagonalCross
Creates a diagonal cross shape.- Parameters:
l
- the length of each 'arm'.t
- the thickness.- Returns:
- A diagonal cross shape.
-
createRegularCross
Creates a diagonal cross shape.- Parameters:
l
- the length of each 'arm'.t
- the thickness.- Returns:
- A diagonal cross shape.
-
createDiamond
Creates a diamond shape.- Parameters:
s
- the size factor (equal to half the height of the diamond).- Returns:
- A diamond shape.
-
createUpTriangle
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
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
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 (null
not permitted).width
- the width of the region.- Returns:
- A region that surrounds the line.
-
getPointInRectangle
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 (null
not permitted).- Returns:
- A point within the rectangle.
- Throws:
NullPointerException
- ifarea
isnull
.
-
contains
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
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
Returnstrue
if the specified point (x, y) falls within or on the boundary of the specified rectangle.- Parameters:
rect
- the rectangle (null
not permitted).x
- the x-coordinate.y
- the y-coordinate.- Returns:
- A boolean.
-