clone
public static Shape clone(Shape shape)
Returns a clone of the specified shape, or
null. At the
current time, this method supports cloning for instances of
Line2D,
RectangularShape,
Area
and
GeneralPath.
RectangularShape includes
Arc2D,
Ellipse2D,
Rectangle2D,
RoundRectangle2D.
shape - the shape to clone (null permitted,
returns null).
contains
public 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!).
rect1 - the first rectangle.rect2 - the second rectangle.
createDiagonalCross
public static Shape createDiagonalCross(float l,
float t) Creates a diagonal cross shape.
l - the length of each 'arm'.t - the thickness.
createDiamond
public static Shape createDiamond(float s)
Creates a diamond shape.
s - the size factor (equal to half the height of the diamond).
createDownTriangle
public static Shape createDownTriangle(float s)
Creates a triangle shape that points downwards.
s - the size factor (equal to half the height of the triangle).
createLineRegion
public static Shape createLineRegion(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.
line - the line (null not permitted).width - the width of the region.
- A region that surrounds the line.
createRegularCross
public static Shape createRegularCross(float l,
float t) Creates a diagonal cross shape.
l - the length of each 'arm'.t - the thickness.
createTranslatedShape
public static Shape createTranslatedShape(Shape shape,
double transX,
double transY) Creates and returns a translated shape.
shape - the shape (null not permitted).transX - the x translation (in Java2D space).transY - the y translation (in Java2D space).
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.
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).
- A new and translated shape.
createUpTriangle
public static Shape createUpTriangle(float s)
Creates a triangle shape that points upwards.
s - the size factor (equal to half the height of the triangle).
drawRotatedShape
public static void drawRotatedShape(Graphics2D g2,
Shape shape,
double angle,
float x,
float y) Draws a shape with the specified rotation about (x, y).
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.
equal
public static boolean equal(Arc2D a1,
Arc2D a2) Compares two arcs and returns true if they are equal or
both null.
a1 - the first arc (null permitted).a2 - the second arc (null permitted).
equal
public static boolean equal(Ellipse2D e1,
Ellipse2D e2) Compares two ellipses and returns true if they are equal or
both null.
e1 - the first ellipse (null permitted).e2 - the second ellipse (null permitted).
equal
public static boolean equal(GeneralPath p1,
GeneralPath p2) Tests two polygons for equality. If both are null this
method returns true.
p1 - path 1 (null permitted).p2 - path 2 (null permitted).
equal
public static boolean equal(Line2D l1,
Line2D l2) Compares two lines are returns true if they are equal or
both null.
l1 - the first line (null permitted).l2 - the second line (null permitted).
equal
public static boolean equal(Polygon p1,
Polygon p2) Tests two polygons for equality. If both are null this
method returns true.
p1 - polygon 1 (null permitted).p2 - polygon 2 (null permitted).
equal
public static boolean equal(Shape s1,
Shape s2) Tests two shapes for equality. If both shapes are
null,
this method will return
true.
In the current implementation, the following shapes are supported:
Ellipse2D,
Line2D and
Rectangle2D
(implicit).
s1 - the first shape (null permitted).s2 - the second shape (null permitted).
getPointInRectangle
public 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.
x - the x-coordinate.y - the y-coordinate.area - the constraining rectangle (null not
permitted).
- A point within the rectangle.
intersects
public 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!).
rect1 - the first rectangle.rect2 - the second rectangle.
rotateShape
public static Shape rotateShape(Shape base,
double angle,
float x,
float y) Rotates a shape about the specified coordinates.
base - the shape (null permitted, returns
null).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).