Package org.eclipse.gef.geometry.planar
Class RoundedRectangle
java.lang.Object
org.eclipse.gef.geometry.planar.RoundedRectangle
- All Implemented Interfaces:
Serializable
,Cloneable
,IGeometry
,IRotatable<PolyBezier>
,IScalable<RoundedRectangle>
,IShape
,ITranslatable<RoundedRectangle>
Represents the geometric shape of a rounded rectangle, i.e. a rectangle with
rounded corners.
arc-width width .-------------------. .--------. +----+-----+-----+----+ / / | ^ ^ | arc- | | | | | | height | | + <- arc end point -> + | | | | | \ | | height | + + | | | | | | | + <- arc end point -> + | | | | | \ | v v | +----+-----+-----+----+The maximum value for the arc-width is the width of the rectangle and the maximum value for the arc-height is the height of the rectangle. For the maximal values, the end points of the arcs are at the centers of the sides of the rectangle.
Note that while all manipulations (e.g. within shrink, expand) within this
class are based on double precision, all comparisons (e.g. within contains,
intersects, equals, etc.) are based on a limited precision (with an accuracy
defined within PrecisionUtils
) to compensate for rounding effects.
- See Also:
-
Constructor Summary
ConstructorDescriptionRoundedRectangle
(double x, double y, double width, double height, double arcWidth, double arcHeight) Constructs a newRoundedRectangle
from the given bounds and arc values.RoundedRectangle
(Rectangle r, double arcWidth, double arcHeight) Constructs a newRoundedRectangle
from the bounds of the givenRectangle
and the given arc values. -
Method Summary
Modifier and TypeMethodDescriptionclone()
Overridden with public visibility as recommended withinCloneable
.boolean
boolean
boolean
expand
(double h, double v) Expands the horizontal and vertical sides of thisAbstractRectangleBasedGeometry
with the values provided as input, and returnsthis
for convenience.expand
(double left, double top, double right, double bottom) Expands thisAbstractRectangleBasedGeometry
by the given amounts, and returns this for convenience.double
Returns the arc height of thisRoundedRectangle
, which is the height of the arc used to define its rounded corners.double
Returns the arc width of thisRoundedRectangle
, which is the width of the arc used to define its rounded corners.Returns the bottom edge of thisRoundedRectangle
.Returns the bottom leftArc
of thisRoundedRectangle
.Returns the bottom rightArc
of thisRoundedRectangle
.Returns the centerPoint
of thisAbstractRectangleBasedGeometry
.getCopy()
Returns a new identical copy of thisIGeometry
.protected double
Returns the effective arc height, i.e. clamped to the range[0;height]
.protected double
Returns the effective arc width, i.e. clamped to the range[0;width]
.getExpanded
(double h, double v) Returns a new expandedAbstractRectangleBasedGeometry
, where the sides are incremented by the horizontal and vertical values provided.getExpanded
(double left, double top, double right, double bottom) Creates and returns a newAbstractRectangleBasedGeometry
with the bounds of thisAbstractRectangleBasedGeometry
expanded by the given insets.final double
Returns the height of thisAbstractRectangleBasedGeometry
.getLeft()
Returns the left edge of thisRoundedRectangle
.Returns aPoint
specifying the x and y coordinates of thisAbstractRectangleBasedGeometry
.getRight()
Returns the right edge of thisRoundedRectangle
.getRotatedCCW
(Angle angle) getRotatedCCW
(Angle angle, double cx, double cy) getRotatedCCW
(Angle angle, Point center) getRotatedCW
(Angle angle) getRotatedCW
(Angle angle, double cx, double cy) getRotatedCW
(Angle angle, Point center) getScaled
(double factor) Scales a copy of the calling object by the given factor relative to its centerPoint
.getScaled
(double factorX, double factorY) Scales a copy of the calling object by the given factors relative to its centerPoint
.getScaled
(double factor, double centerX, double centerY) Scales a copy of the calling object by the given factor relative to the given centerPoint
(cx, cy).getScaled
(double factorX, double factorY, double centerX, double centerY) Scales a copy of the calling object by the given factors relative to the given centerPoint
(cx, cy).Scales a copy of the calling object by the given factors relative to the given centerPoint
.Scales a copy of the calling object by the given factor relative to the given centerPoint
.getShrinked
(double h, double v) Returns a newAbstractRectangleBasedGeometry
, where the sides are shrinked by the horizontal and vertical values supplied.getShrinked
(double left, double top, double right, double bottom) Returns a newAbstractRectangleBasedGeometry
shrinked by the specified insets.final Dimension
getSize()
Returns aDimension
that records the width and height of thisAbstractRectangleBasedGeometry
.getTop()
Returns the top edge of thisRoundedRectangle
.Returns the top leftArc
of thisRoundedRectangle
.Returns the top rightArc
of thisRoundedRectangle
.getTranslated
(double dx, double dy) Translates a copy of this object by the given values in x and y direction.getTranslated
(Point pt) Translates a copy of this object by the givenPoint
.final double
getWidth()
Returns the width of thisAbstractRectangleBasedGeometry
.final double
getX()
Returns the x coordinate thisAbstractRectangleBasedGeometry
.final double
getY()
Returns the y coordinate of thisAbstractRectangleBasedGeometry
.final int
hashCode()
scale
(double factor) Scales the calling object by the given factor relative to its centerPoint
.scale
(double fx, double fy) Scales the calling object by the given factors relative to the given centerPoint
.scale
(double factor, double cx, double cy) Scales the calling object by the given factor relative to the given centerPoint
(cx, cy).scale
(double fx, double fy, double cx, double cy) Scales the calling object by the given factors relative to the given centerPoint
(cx, cy).Scales the calling object by the given factors relative to the given centerPoint
.Scales the calling object by the given factor relative to the given centerPoint
.setArcHeight
(double arcHeight) Sets the arc height of thisRoundedRectangle
, which is the height of the arc used to define its rounded corners.setArcWidth
(double arcWidth) Sets the arc width of thisRoundedRectangle
, which is the width of the arc used to define its rounded corners.final RoundedRectangle
setBounds
(double x, double y, double w, double h) Sets the x, y, width, and height values of thisAbstractRectangleBasedGeometry
to the given values.final RoundedRectangle
final RoundedRectangle
Sets the x and y coordinates and the width and height of thisAbstractRectangleBasedGeometry
to the respective values of the givenRectangle
.final RoundedRectangle
setHeight
(double height) Sets the height of thisAbstractRectangleBasedGeometry
to the given value.final RoundedRectangle
setLocation
(double x, double y) Sets the x and y coordinates of thisAbstractRectangleBasedGeometry
to the specified values.final RoundedRectangle
setLocation
(Point p) Sets the x and y coordinates of thisAbstractRectangleBasedGeometry
to the respective values of the givenPoint
.final RoundedRectangle
setSize
(double w, double h) Sets the width and height of thisAbstractRectangleBasedGeometry
to the given values.final RoundedRectangle
Sets the width and height of thisAbstractRectangleBasedGeometry
to the width and height of the givenDimension
.final RoundedRectangle
setWidth
(double width) Sets the width of thisAbstractRectangleBasedGeometry
to the passed-in value.final RoundedRectangle
setX
(double x) Sets the x-coordinate of thisAbstractRectangleBasedGeometry
to the given value.final RoundedRectangle
setY
(double y) Sets the y-coordinate of thisAbstractRectangleBasedGeometry
to the given value.shrink
(double h, double v) Shrinks the sides of thisAbstractRectangleBasedGeometry
by the horizontal and vertical values provided as input, and returns thisAbstractRectangleBasedGeometry
for convenience.shrink
(double left, double top, double right, double bottom) Shrinks thisAbstractRectangleBasedGeometry
by the specified amounts.toPath()
toString()
boolean
translate
(double dx, double dy) Translates the object by the given values in x and y direction.Translates the object by the givenPoint
.
-
Constructor Details
-
RoundedRectangle
public RoundedRectangle(double x, double y, double width, double height, double arcWidth, double arcHeight) Constructs a newRoundedRectangle
from the given bounds and arc values.- Parameters:
x
- the x-coordinate of the newRoundedRectangle
's boundsy
- the y-coordinate of the newRoundedRectangle
's boundswidth
- the width of the newRoundedRectangle
's boundsheight
- the height of the newRoundedRectangle
's boundsarcWidth
- the arc width of the newRoundedRectangle
rounded cornersarcHeight
- the arc height of the newRoundedRectangle
rounded corners
-
RoundedRectangle
Constructs a newRoundedRectangle
from the bounds of the givenRectangle
and the given arc values.- Parameters:
r
- theRectangle
, whose bounds are used to initialize the x, y, width, and height values of the newRoundedRectangle
arcWidth
- the arc width of the newRoundedRectangle
rounded cornersarcHeight
- the arc height of the newRoundedRectangle
rounded corners
-
-
Method Details
-
contains
Description copied from interface:IShape
-
contains
Description copied from interface:IGeometry
-
equals
-
getArcHeight
public double getArcHeight()Returns the arc height of thisRoundedRectangle
, which is the height of the arc used to define its rounded corners.- Returns:
- the arc height
-
getArcWidth
public double getArcWidth()Returns the arc width of thisRoundedRectangle
, which is the width of the arc used to define its rounded corners.- Returns:
- the arc height
-
getBottom
Returns the bottom edge of thisRoundedRectangle
.- Returns:
- the bottom edge of this
RoundedRectangle
.
-
getBottomLeftArc
Returns the bottom leftArc
of thisRoundedRectangle
.- Returns:
- the bottom left
Arc
of thisRoundedRectangle
.
-
getBottomRightArc
Returns the bottom rightArc
of thisRoundedRectangle
.- Returns:
- the bottom right
Arc
of thisRoundedRectangle
.
-
getCopy
Description copied from interface:IGeometry
Returns a new identical copy of thisIGeometry
. -
getEffectiveArcHeight
protected double getEffectiveArcHeight()Returns the effective arc height, i.e. clamped to the range[0;height]
.- Returns:
- the effective arc height, i.e. clamped to the range
[0;height]
.
-
getEffectiveArcWidth
protected double getEffectiveArcWidth()Returns the effective arc width, i.e. clamped to the range[0;width]
.- Returns:
- the effective arc width, i.e. clamped to the range
[0;width]
.
-
getLeft
Returns the left edge of thisRoundedRectangle
.- Returns:
- the left edge of this
RoundedRectangle
.
-
getOutline
Description copied from interface:IShape
- Specified by:
getOutline
in interfaceIShape
- Returns:
- An
ICurve
representing thisIShape
's outline.
-
getOutlineSegments
Description copied from interface:IShape
- Specified by:
getOutlineSegments
in interfaceIShape
- Returns:
- The
ICurve
segments of thisIShape
's outline. - See Also:
-
getRight
Returns the right edge of thisRoundedRectangle
.- Returns:
- the right edge of this
RoundedRectangle
.
-
getRotatedCCW
Description copied from interface:IRotatable
Rotates the calling object by specifiedAngle
counter-clock-wise (CCW) around its centerPoint
. Does not necessarily return an object of the same type.- Specified by:
getRotatedCCW
in interfaceIRotatable<PolyBezier>
- Parameters:
angle
- rotationAngle
- Returns:
- an
IGeometry
representing the result of the rotation
-
getRotatedCCW
Description copied from interface:IRotatable
Rotates the calling object by the specifiedAngle
counter-clock-wise (CCW) around the specified centerPoint
(cx, cy). Does not necessarily return an object of the same type.- Specified by:
getRotatedCCW
in interfaceIRotatable<PolyBezier>
- Parameters:
angle
- rotationAngle
cx
- x-coordinate of the relativePoint
for the rotationcy
- y-coordinate of the relativePoint
for the rotation- Returns:
- an
IGeometry
representing the result of the rotation
-
getRotatedCCW
Description copied from interface:IRotatable
Rotates the calling object by the specifiedAngle
counter-clock-wise (CCW) around the specified centerPoint
. Does not necessarily return an object of the same type.- Specified by:
getRotatedCCW
in interfaceIRotatable<PolyBezier>
- Parameters:
angle
- rotationAngle
center
- relativePoint
for the rotation- Returns:
- an
IGeometry
representing the result of the rotation
-
getRotatedCW
Description copied from interface:IRotatable
Rotates the calling object by specifiedAngle
clock-wise (CW) around its centerPoint
. Does not necessarily return an object of the same type.- Specified by:
getRotatedCW
in interfaceIRotatable<PolyBezier>
- Parameters:
angle
- rotationAngle
- Returns:
- an
IGeometry
representing the result of the rotation
-
getRotatedCW
Description copied from interface:IRotatable
Rotates the calling object by the specifiedAngle
clock-wise (CW) around the specified centerPoint
(cx, cy). Does not necessarily return an object of the same type.- Specified by:
getRotatedCW
in interfaceIRotatable<PolyBezier>
- Parameters:
angle
- rotationAngle
cx
- x-coordinate of the relativePoint
for the rotationcy
- y-coordinate of the relativePoint
for the rotation- Returns:
- an
IGeometry
representing the result of the rotation
-
getRotatedCW
Description copied from interface:IRotatable
Rotates the calling object by the specifiedAngle
clock-wise (CW) around the specified centerPoint
. Does not necessarily return an object of the same type.- Specified by:
getRotatedCW
in interfaceIRotatable<PolyBezier>
- Parameters:
angle
- rotationAngle
center
- relativePoint
for the rotation- Returns:
- an
IGeometry
representing the result of the rotation
-
getTop
Returns the top edge of thisRoundedRectangle
.- Returns:
- the top edge of this
RoundedRectangle
.
-
getTopLeftArc
Returns the top leftArc
of thisRoundedRectangle
.- Returns:
- the top left
Arc
of thisRoundedRectangle
.
-
getTopRightArc
Returns the top rightArc
of thisRoundedRectangle
.- Returns:
- the top right
Arc
of thisRoundedRectangle
.
-
getTransformed
Default implementation returning a transformedPath
representation of thisIGeometry
. Subclasses may override this method to return a more specific representation.- Specified by:
getTransformed
in interfaceIGeometry
- Specified by:
getTransformed
in interfaceIShape
- Parameters:
t
- TheAffineTransform
to be applied- Returns:
- a transformed
Path
representation of thisIGeometry
- See Also:
-
setArcHeight
Sets the arc height of thisRoundedRectangle
, which is the height of the arc used to define its rounded corners.- Parameters:
arcHeight
- the new arc height- Returns:
this
for convenience
-
setArcWidth
Sets the arc width of thisRoundedRectangle
, which is the width of the arc used to define its rounded corners.- Parameters:
arcWidth
- the new arc width- Returns:
this
for convenience
-
toPath
Description copied from interface:IGeometry
-
toString
-
expand
Expands the horizontal and vertical sides of thisAbstractRectangleBasedGeometry
with the values provided as input, and returnsthis
for convenience. The location of its center is kept constant.- Parameters:
h
- the horizontal incrementv
- the vertical increment- Returns:
this
for convenience
-
expand
Expands thisAbstractRectangleBasedGeometry
by the given amounts, and returns this for convenience.- Parameters:
left
- the amount to expand the left sidetop
- the amount to expand the top sideright
- the amount to expand the right sidebottom
- the amount to expand the bottom side- Returns:
this
for convenience
-
getBounds
Description copied from interface:IGeometry
-
getCenter
Returns the centerPoint
of thisAbstractRectangleBasedGeometry
.- Returns:
- the center
Point
of thisAbstractRectangleBasedGeometry
-
getExpanded
Returns a new expandedAbstractRectangleBasedGeometry
, where the sides are incremented by the horizontal and vertical values provided. The center of theAbstractRectangleBasedGeometry
is maintained constant.- Parameters:
h
- The horizontal incrementv
- The vertical increment- Returns:
- a new expanded
AbstractRectangleBasedGeometry
-
getExpanded
Creates and returns a newAbstractRectangleBasedGeometry
with the bounds of thisAbstractRectangleBasedGeometry
expanded by the given insets.- Parameters:
left
- the amount to expand the left sidetop
- the amount to expand the top sideright
- the amount to expand the right sidebottom
- the amount to expand the bottom side- Returns:
- a new expanded
AbstractRectangleBasedGeometry
-
getHeight
public final double getHeight()Returns the height of thisAbstractRectangleBasedGeometry
.- Returns:
- the height of this
AbstractRectangleBasedGeometry
-
getLocation
Returns aPoint
specifying the x and y coordinates of thisAbstractRectangleBasedGeometry
.- Returns:
- a
Point
representing the x and y coordinates of thisAbstractRectangleBasedGeometry
-
getScaled
Description copied from interface:IScalable
Scales a copy of the calling object by the given factor relative to its centerPoint
. -
getScaled
Description copied from interface:IScalable
Scales a copy of the calling object by the given factors relative to its centerPoint
. -
getScaled
Description copied from interface:IScalable
Scales a copy of the calling object by the given factor relative to the given centerPoint
(cx, cy).- Specified by:
getScaled
in interfaceIScalable<T extends org.eclipse.gef.geometry.planar.AbstractRectangleBasedGeometry<?,
?>> - Parameters:
factor
- scale-factorcenterX
- x-coordinate of the relativePoint
for the scalingcenterY
- y-coordinate of the relativePoint
for the scaling- Returns:
- the new, scaled object
-
getScaled
Description copied from interface:IScalable
Scales a copy of the calling object by the given factors relative to the given centerPoint
(cx, cy).- Specified by:
getScaled
in interfaceIScalable<T extends org.eclipse.gef.geometry.planar.AbstractRectangleBasedGeometry<?,
?>> - Parameters:
factorX
- x-scale-factorfactorY
- y-scale-factorcenterX
- x-coordinate of the relativePoint
for the scalingcenterY
- y-coordinate of the relativePoint
for the scaling- Returns:
- the new, scaled object
-
getScaled
Description copied from interface:IScalable
Scales a copy of the calling object by the given factors relative to the given centerPoint
. -
getScaled
Description copied from interface:IScalable
Scales a copy of the calling object by the given factor relative to the given centerPoint
. -
getShrinked
Returns a newAbstractRectangleBasedGeometry
, where the sides are shrinked by the horizontal and vertical values supplied. The center of thisAbstractRectangleBasedGeometry
is kept constant.- Parameters:
h
- horizontal reduction amountv
- vertical reduction amount- Returns:
- a new, shrinked
AbstractRectangleBasedGeometry
-
getShrinked
Returns a newAbstractRectangleBasedGeometry
shrinked by the specified insets.- Parameters:
left
- the amount to shrink the left sidetop
- the amount to shrink the top sideright
- the amount to shrink the right sidebottom
- the amount to shrink the bottom side- Returns:
- a new, shrinked
AbstractRectangleBasedGeometry
-
getSize
Returns aDimension
that records the width and height of thisAbstractRectangleBasedGeometry
.- Returns:
- a
Dimension
that records the width and height of thisAbstractRectangleBasedGeometry
-
getTranslated
Description copied from interface:ITranslatable
Translates a copy of this object by the given values in x and y direction.- Specified by:
getTranslated
in interfaceITranslatable<T extends org.eclipse.gef.geometry.planar.AbstractRectangleBasedGeometry<?,
?>> - Parameters:
dx
- x-translationdy
- y-translation- Returns:
- a new, translated object
-
getTranslated
Description copied from interface:ITranslatable
Translates a copy of this object by the givenPoint
.- Specified by:
getTranslated
in interfaceITranslatable<T extends org.eclipse.gef.geometry.planar.AbstractRectangleBasedGeometry<?,
?>> - Parameters:
pt
- translationPoint
- Returns:
- a new, translated object
-
getWidth
public final double getWidth()Returns the width of thisAbstractRectangleBasedGeometry
.- Returns:
- the width of this
AbstractRectangleBasedGeometry
-
getX
public final double getX()Returns the x coordinate thisAbstractRectangleBasedGeometry
.- Returns:
- the x coordinate this
AbstractRectangleBasedGeometry
-
getY
public final double getY()Returns the y coordinate of thisAbstractRectangleBasedGeometry
.- Returns:
- the y coordinate of this
AbstractRectangleBasedGeometry
-
scale
Description copied from interface:IScalable
Scales the calling object by the given factor relative to its centerPoint
. -
scale
Description copied from interface:IScalable
Scales the calling object by the given factors relative to the given centerPoint
. -
scale
Description copied from interface:IScalable
Scales the calling object by the given factor relative to the given centerPoint
(cx, cy). -
scale
Description copied from interface:IScalable
Scales the calling object by the given factors relative to the given centerPoint
(cx, cy).- Specified by:
scale
in interfaceIScalable<T extends org.eclipse.gef.geometry.planar.AbstractRectangleBasedGeometry<?,
?>> - Parameters:
fx
- x-scale-factorfy
- y-scale-factorcx
- x-coordinate of the relativePoint
for the scalingcy
- y-coordinate of the relativePoint
for the scaling- Returns:
this
for convenience
-
scale
Description copied from interface:IScalable
Scales the calling object by the given factors relative to the given centerPoint
. -
scale
Description copied from interface:IScalable
Scales the calling object by the given factor relative to the given centerPoint
. -
setBounds
Sets the x, y, width, and height values of thisAbstractRectangleBasedGeometry
to the given values.- Parameters:
x
- the new x-coordinatey
- the new y-coordinatew
- the new widthh
- the new height- Returns:
this
for convenience
-
setBounds
-
setBounds
Sets the x and y coordinates and the width and height of thisAbstractRectangleBasedGeometry
to the respective values of the givenRectangle
.- Parameters:
r
- theRectangle
specifying the new x, y, width, and height values of thisAbstractRectangleBasedGeometry
- Returns:
this
for convenience
-
setHeight
Sets the height of thisAbstractRectangleBasedGeometry
to the given value.- Parameters:
height
- the new height- Returns:
this
for convenience
-
setLocation
Sets the x and y coordinates of thisAbstractRectangleBasedGeometry
to the specified values.- Parameters:
x
- the new x coordinate of thisAbstractRectangleBasedGeometry
y
- the new y coordinate of thisAbstractRectangleBasedGeometry
- Returns:
this
for convenience
-
setLocation
Sets the x and y coordinates of thisAbstractRectangleBasedGeometry
to the respective values of the givenPoint
.- Parameters:
p
- thePoint
specifying the new x and y coordinates of thisAbstractRectangleBasedGeometry
- Returns:
this
for convenience
-
setSize
Sets the width and height of thisAbstractRectangleBasedGeometry
to the width and height of the givenDimension
.- Parameters:
d
- theDimension
specifying the new width and height of thisAbstractRectangleBasedGeometry
- Returns:
this
for convenience
-
setSize
Sets the width and height of thisAbstractRectangleBasedGeometry
to the given values.- Parameters:
w
- the new width of thisAbstractRectangleBasedGeometry
h
- the new height of thisAbstractRectangleBasedGeometry
- Returns:
this
for convenience
-
setWidth
Sets the width of thisAbstractRectangleBasedGeometry
to the passed-in value.- Parameters:
width
- the new width of thisAbstractRectangleBasedGeometry
- Returns:
this
for convenience
-
setX
Sets the x-coordinate of thisAbstractRectangleBasedGeometry
to the given value.- Parameters:
x
- The new x-coordinate.- Returns:
this
for convenience.
-
setY
Sets the y-coordinate of thisAbstractRectangleBasedGeometry
to the given value.- Parameters:
y
- The new y-coordinate.- Returns:
this
for convenience.
-
shrink
Shrinks the sides of thisAbstractRectangleBasedGeometry
by the horizontal and vertical values provided as input, and returns thisAbstractRectangleBasedGeometry
for convenience. The center of thisAbstractRectangleBasedGeometry
is kept constant.- Parameters:
h
- horizontal reduction amountv
- vertical reduction amount- Returns:
this
for convenience
-
shrink
Shrinks thisAbstractRectangleBasedGeometry
by the specified amounts.- Parameters:
left
- the amount to shrink the left sidetop
- the amount to shrink the top sideright
- the amount to shrink the right sidebottom
- the amount to shrink the bottom side- Returns:
this
for convenience
-
translate
Description copied from interface:ITranslatable
Translates the object by the given values in x and y direction.- Specified by:
translate
in interfaceITranslatable<T extends org.eclipse.gef.geometry.planar.AbstractRectangleBasedGeometry<?,
?>> - Parameters:
dx
- x-translationdy
- y-translation- Returns:
this
for convenience
-
translate
Description copied from interface:ITranslatable
Translates the object by the givenPoint
.- Specified by:
translate
in interfaceITranslatable<T extends org.eclipse.gef.geometry.planar.AbstractRectangleBasedGeometry<?,
?>> - Parameters:
p
- translationPoint
- Returns:
this
for convenience
-
clone
Overridden with public visibility as recommended withinCloneable
. -
hashCode
public final int hashCode() -
touches
Description copied from interface:IGeometry
-