public final class Rectangle extends java.lang.Object implements IShape
PrecisionUtils) to compensate for rounding effects.| Constructor and Description |
|---|
Rectangle()
Constructs a
Rectangle with location (0,0) and a size of (0,0). |
Rectangle(double x,
double y,
double width,
double height)
Constructs a Rectangle from the given values for its location (upper-left
corner point) and its size.
|
Rectangle(Point location,
Dimension size)
Constructs a new
Rectangle with the given location and size. |
Rectangle(Point p1,
Point p2)
|
Rectangle(Rectangle r)
|
| Modifier and Type | Method and Description |
|---|---|
java.lang.Object |
clone()
Overridden with public visibility as recommended within
Cloneable
. |
boolean |
contains(double x,
double y)
Returns whether the point given by x and y is within the boundaries of
this Rectangle.
|
boolean |
contains(double x,
double y,
double width,
double height)
Returns true in case the rectangle specified by (x, y, width, height) is
contained within this
Rectangle. |
boolean |
contains(IGeometry g)
|
boolean |
contains(Point p)
Returns whether the given point is within the boundaries of this
Rectangle.
|
boolean |
contains(Rectangle r)
|
boolean |
equals(double x,
double y,
double width,
double height)
Returns
true if this Rectangle's x, y, width, and height
values are identical to the provided ones. |
boolean |
equals(java.lang.Object o)
Returns whether the input object is equal to this Rectangle or not.
|
T |
expand(double h,
double v)
Expands the horizontal and vertical sides of this
AbstractRectangleBasedGeometry with the values provided as input,
and returns this for convenience. |
T |
expand(double left,
double top,
double right,
double bottom)
Expands this
AbstractRectangleBasedGeometry by the given amounts,
and returns this for convenience. |
double |
getArea()
Returns the area of this
Rectangle, i.e. the product of its width
and height. |
Point |
getBottom()
Returns a new Point representing the middle point of the bottom side of
this Rectangle.
|
Point |
getBottomLeft()
Returns a new Point representing the bottom left point of this Rectangle.
|
Point |
getBottomRight()
Returns a new Point representing the bottom right point of this
Rectangle.
|
Rectangle |
getBounds()
|
Point |
getCenter()
Returns the center
Point of this
AbstractRectangleBasedGeometry. |
Rectangle |
getCopy()
Returns a new Rectangle which has the exact same parameters as this
Rectangle.
|
T |
getExpanded(double h,
double v)
Returns a new expanded
AbstractRectangleBasedGeometry, where the
sides are incremented by the horizontal and vertical values provided. |
T |
getExpanded(double left,
double top,
double right,
double bottom)
Creates and returns a new
AbstractRectangleBasedGeometry with the
bounds of this AbstractRectangleBasedGeometry expanded by the
given insets. |
double |
getHeight()
Returns the height of this
AbstractRectangleBasedGeometry. |
Rectangle |
getIntersected(Rectangle rect)
Returns a new Rectangle which has the intersection of this Rectangle and
the rectangle provided as input.
|
Point |
getLeft()
Returns a new Point representing the middle point of the left hand side
of this Rectangle.
|
Point |
getLocation()
Returns a
Point specifying the x and y coordinates of this
AbstractRectangleBasedGeometry. |
Polyline |
getOutline()
|
Line[] |
getOutlineSegments()
|
Point[] |
getPoints()
|
Point |
getRight()
Returns a new Point which represents the middle point of the right hand
side of this Rectangle.
|
Polygon |
getRotatedCCW(Angle alpha)
|
Polygon |
getRotatedCCW(Angle alpha,
double cx,
double cy)
|
Polygon |
getRotatedCCW(Angle alpha,
Point center)
|
Polygon |
getRotatedCW(Angle alpha)
|
Polygon |
getRotatedCW(Angle alpha,
double cx,
double cy)
|
Polygon |
getRotatedCW(Angle alpha,
Point center)
|
T |
getScaled(double factor)
Scales a copy of the calling object by the given factor relative to its
center
Point. |
T |
getScaled(double factorX,
double factorY)
Scales a copy of the calling object by the given factors relative to its
center
Point. |
T |
getScaled(double factor,
double centerX,
double centerY)
Scales a copy of the calling object by the given factor relative to the
given center
Point (cx, cy). |
T |
getScaled(double factorX,
double factorY,
double centerX,
double centerY)
Scales a copy of the calling object by the given factors relative to the
given center
Point (cx, cy). |
T |
getScaled(double factorX,
double factorY,
Point center)
Scales a copy of the calling object by the given factors relative to the
given center
Point. |
T |
getScaled(double factor,
Point center)
Scales a copy of the calling object by the given factor relative to the
given center
Point. |
T |
getShrinked(double h,
double v)
Returns a new
AbstractRectangleBasedGeometry, where the sides are
shrinked by the horizontal and vertical values supplied. |
T |
getShrinked(double left,
double top,
double right,
double bottom)
Returns a new
AbstractRectangleBasedGeometry shrinked by the
specified insets. |
Dimension |
getSize()
Returns a
Dimension that records the width and height of this
AbstractRectangleBasedGeometry. |
Point |
getTop()
Returns a new Point which represents the middle point of the top side of
this Rectangle.
|
Point |
getTopLeft()
Returns a new Point which represents the top left hand corner of this
Rectangle.
|
Point |
getTopRight()
Returns a new Point which represents the top right hand corner of this
Rectangle.
|
Polygon |
getTransformed(AffineTransform t)
|
T |
getTranslated(double dx,
double dy)
Translates a copy of this object by the given values in x and y
direction.
|
T |
getTranslated(Point pt)
Translates a copy of this object by the given
Point. |
Rectangle |
getTransposed()
Returns a new rectangle whose width and height have been interchanged, as
well as its x and y values.
|
Rectangle |
getUnioned(Point p)
Returns a new Rectangle which contains both this Rectangle and the Point
supplied as input.
|
Rectangle |
getUnioned(Rectangle rect)
Returns a new Rectangle which contains both this Rectangle and the
Rectangle supplied as input.
|
double |
getWidth()
Returns the width of this
AbstractRectangleBasedGeometry. |
double |
getX()
Returns the x coordinate this
AbstractRectangleBasedGeometry. |
double |
getY()
Returns the y coordinate of this
AbstractRectangleBasedGeometry. |
int |
hashCode() |
Rectangle |
intersect(Rectangle r)
|
boolean |
isEmpty()
Returns
true if this Rectangle's width or height is less
than or equal to 0. |
T |
scale(double factor)
Scales the calling object by the given factor relative to its center
Point. |
T |
scale(double fx,
double fy)
Scales the calling object by the given factors relative to the given
center
Point. |
T |
scale(double factor,
double cx,
double cy)
Scales the calling object by the given factor relative to the given
center
Point (cx, cy). |
T |
scale(double fx,
double fy,
double cx,
double cy)
Scales the calling object by the given factors relative to the given
center
Point (cx, cy). |
T |
scale(double fx,
double fy,
Point center)
Scales the calling object by the given factors relative to the given
center
Point. |
T |
scale(double factor,
Point center)
Scales the calling object by the given factor relative to the given
center
Point. |
T |
setBounds(double x,
double y,
double w,
double h)
Sets the x, y, width, and height values of this
AbstractRectangleBasedGeometry to the given values. |
T |
setBounds(Point loc,
Dimension size)
|
T |
setBounds(Rectangle r)
Sets the x and y coordinates and the width and height of this
AbstractRectangleBasedGeometry to the respective values of the
given Rectangle. |
T |
setHeight(double height)
Sets the height of this
AbstractRectangleBasedGeometry to the
given value. |
T |
setLocation(double x,
double y)
Sets the x and y coordinates of this
AbstractRectangleBasedGeometry to the specified values. |
T |
setLocation(Point p)
Sets the x and y coordinates of this
AbstractRectangleBasedGeometry to the respective values of the
given Point. |
T |
setSize(Dimension d)
Sets the width and height of this
AbstractRectangleBasedGeometry
to the width and height of the given Dimension. |
T |
setSize(double w,
double h)
Sets the width and height of this
AbstractRectangleBasedGeometry
to the given values. |
T |
setWidth(double width)
Sets the width of this
AbstractRectangleBasedGeometry to the
passed-in value. |
T |
setX(double x)
Sets the x-coordinate of this
AbstractRectangleBasedGeometry to
the given value. |
T |
setY(double y)
Sets the y-coordinate of this
AbstractRectangleBasedGeometry to
the given value. |
T |
shrink(double h,
double v)
Shrinks the sides of this
AbstractRectangleBasedGeometry by the
horizontal and vertical values provided as input, and returns this
AbstractRectangleBasedGeometry for convenience. |
T |
shrink(double left,
double top,
double right,
double bottom)
Shrinks this
AbstractRectangleBasedGeometry by the specified
amounts. |
Path |
toPath()
|
Polygon |
toPolygon()
|
java.lang.String |
toString() |
boolean |
touches(IGeometry g)
|
boolean |
touches(Line l)
|
boolean |
touches(Rectangle r)
|
T |
translate(double dx,
double dy)
Translates the object by the given values in x and y direction.
|
T |
translate(Point p)
Translates the object by the given
Point. |
Rectangle |
transpose()
Switches the x and y values, as well as the width and height of this
Rectangle.
|
Rectangle |
union(double x,
double y)
|
Rectangle |
union(double x,
double y,
double w,
double h)
|
Rectangle |
union(Point p)
|
Rectangle |
union(Rectangle r)
|
public Rectangle()
Rectangle with location (0,0) and a size of (0,0).public Rectangle(double x,
double y,
double width,
double height)
public Rectangle(Point location, Dimension size)
Rectangle with the given location and size.public boolean contains(double x,
double y)
x - the x-coordinate of the point to testy - the y-coordinate of the point to testpublic boolean contains(double x,
double y,
double width,
double height)
Rectangle.x - The x coordinate of the rectangle to be tested for containmenty - The y coordinate of the rectangle to be tested for containmentwidth - The width of the rectangle to be tested for containmentheight - The height of the rectangle to be tested for containmenttrue if the rectangle characterized by (x,y, width,
height) is (imprecisely) fully contained within this
Rectangle, false otherwisepublic boolean contains(Point p)
public boolean contains(Rectangle r)
r - the other Rectangle to test for being contained by
this Rectangletrue if this Rectangle contains the other
Rectangle, otherwise falseIShape.contains(IGeometry)public boolean equals(double x,
double y,
double width,
double height)
true if this Rectangle's x, y, width, and height
values are identical to the provided ones.x - The x value to testy - The y value to testwidth - The width value to testheight - The height value to testtrue if this Rectangle's x, y, width, and height
values are (imprecisely) equal to the provided ones,
false otherwisepublic boolean equals(java.lang.Object o)
equals in class java.lang.Objecto - Object being tested for equalitypublic double getArea()
Rectangle, i.e. the product of its width
and height.Rectanglepublic Point getBottom()
public Point getBottomLeft()
public Point getBottomRight()
public Rectangle getCopy()
public Rectangle getIntersected(Rectangle rect)
rect - Rectangle provided to test for intersectionpublic Point getLeft()
public Polyline getOutline()
IShapegetOutline in interface IShapeICurve representing this IShape's outline.public Line[] getOutlineSegments()
getOutlineSegments in interface IShapeLine representations of this
Rectangle's borders.public Point[] getPoints()
Points representing the top-left, top-right,
bottom-right, and bottom-left border points of this Rectangle.Rectanglepublic Point getRight()
public Polygon getRotatedCCW(Angle alpha)
Rectangle counter-clock-wise by the given
Angle around the center Point of this Rectangle
(see AbstractRectangleBasedGeometry.getCenter()).getRotatedCCW in interface IRotatable<Polygon>alpha - The rotation Angle.PolygonIRotatable.getRotatedCCW(Angle, Point)public Polygon getRotatedCCW(Angle alpha, double cx, double cy)
Rectangle counter-clock-wise by the given
Angle around the given Point.
If the rotation Angle is not an integer multiple of 90 degrees,
the resulting figure cannot be expressed as a Rectangle object.
That's why this method returns a Polygon instead.getRotatedCCW in interface IRotatable<Polygon>alpha - the rotation anglecx - x-component of the center point for the rotationcy - y-component of the center point for the rotationPolygonpublic Polygon getRotatedCCW(Angle alpha, Point center)
Rectangle counter-clock-wise by the given
Angle around the given Point.
If the rotation Angle is not an integer multiple of 90 degrees,
the resulting figure cannot be expressed as a Rectangle object.
That's why this method returns a Polygon instead.getRotatedCCW in interface IRotatable<Polygon>alpha - the rotation anglecenter - the center point for the rotationPolygonpublic Polygon getRotatedCW(Angle alpha)
Rectangle clock-wise by the given Angle
around the center (AbstractRectangleBasedGeometry.getCenter()) of
this Rectangle.getRotatedCW in interface IRotatable<Polygon>alpha - the rotation AnglePolygonIRotatable.getRotatedCW(Angle, Point)public Polygon getRotatedCW(Angle alpha, double cx, double cy)
Rectangle clock-wise by the given Angle
alpha around the given Point (cx, cy).
If the rotation Angle is not an integer multiple of 90 degrees,
the resulting figure cannot be expressed as a Rectangle object.
That's why this method returns a Polygon instead.getRotatedCW in interface IRotatable<Polygon>alpha - the rotation anglecx - x-component of the center point for the rotationcy - y-component of the center point for the rotationPolygonpublic Polygon getRotatedCW(Angle alpha, Point center)
Rectangle clock-wise by the given Angle
alpha around the given Point.
If the rotation Angle is not an integer multiple of 90 degrees,
the resulting figure cannot be expressed as a Rectangle object.
That's why this method returns a Polygon instead.getRotatedCW in interface IRotatable<Polygon>alpha - the rotation anglecenter - the center point for the rotationPolygonpublic Point getTop()
public Point getTopLeft()
public Point getTopRight()
public Polygon getTransformed(AffineTransform t)
getTransformed in interface IGeometrygetTransformed in interface IShapet - The AffineTransform to be appliedPath representation of this
IGeometryIGeometry.getTransformed(AffineTransform)public Rectangle getTransposed()
public Rectangle getUnioned(Point p)
p - Point for calculating unionpublic Rectangle getUnioned(Rectangle rect)
rect - Rectangle for calculating unionpublic boolean isEmpty()
true if this Rectangle's width or height is less
than or equal to 0.true if this Rectangle is (imprecisely) considered
to be emptypublic Path toPath()
IGeometrytoPath in interface IGeometryPath representation for this IGeometry.IGeometry.toPath()public Polygon toPolygon()
Rectangle into a Polygon representation.
The control points used to construct the polygon are the border points
returned by getPoints().public java.lang.String toString()
toString in class java.lang.Objectpublic boolean touches(Line l)
public boolean touches(Rectangle r)
Rectangle and the given other
Rectangle touch, i.e. whether they have at least one point in
common.r - The Rectangle to testtrue if this Rectangle and the given
Rectangle share at least one common point,
false otherwise.IGeometry.touches(IGeometry)public Rectangle transpose()
this for conveniencepublic Rectangle union(double x, double y)
public Rectangle union(double x, double y, double w, double h)
public Rectangle union(Point p)
p - The Point to union withthis for conveniencepublic Rectangle union(Rectangle r)
r - The Rectangle to union withthis for conveniencepublic T expand(double h,
double v)
AbstractRectangleBasedGeometry with the values provided as input,
and returns this for convenience. The location of its center
is kept constant.h - the horizontal incrementv - the vertical incrementthis for conveniencepublic T expand(double left,
double top,
double right,
double bottom)
AbstractRectangleBasedGeometry by the given amounts,
and returns this for convenience.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 sidethis for conveniencepublic Point getCenter()
Point of this
AbstractRectangleBasedGeometry.Point of this
AbstractRectangleBasedGeometrypublic T getExpanded(double h,
double v)
AbstractRectangleBasedGeometry, where the
sides are incremented by the horizontal and vertical values provided. The
center of the AbstractRectangleBasedGeometry is maintained
constant.h - The horizontal incrementv - The vertical incrementAbstractRectangleBasedGeometrypublic T getExpanded(double left,
double top,
double right,
double bottom)
AbstractRectangleBasedGeometry with the
bounds of this AbstractRectangleBasedGeometry expanded by the
given insets.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 sideAbstractRectangleBasedGeometrypublic final double getHeight()
AbstractRectangleBasedGeometry.AbstractRectangleBasedGeometrypublic Point getLocation()
Point specifying the x and y coordinates of this
AbstractRectangleBasedGeometry.Point representing the x and y coordinates of this
AbstractRectangleBasedGeometrypublic T getScaled(double factor)
IScalablePoint.public T getScaled(double factorX,
double factorY)
IScalablePoint.public T getScaled(double factor,
double centerX,
double centerY)
IScalablePoint (cx, cy).getScaled in interface IScalable<T extends org.eclipse.gef.geometry.planar.AbstractRectangleBasedGeometry<?,?>>factor - scale-factorcenterX - x-coordinate of the relative Point for the scalingcenterY - y-coordinate of the relative Point for the scalingpublic T getScaled(double factorX,
double factorY,
double centerX,
double centerY)
IScalablePoint (cx, cy).getScaled in interface IScalable<T extends org.eclipse.gef.geometry.planar.AbstractRectangleBasedGeometry<?,?>>factorX - x-scale-factorfactorY - y-scale-factorcenterX - x-coordinate of the relative Point for the scalingcenterY - y-coordinate of the relative Point for the scalingpublic T getScaled(double factorX,
double factorY,
Point center)
IScalablePoint.public T getScaled(double factor,
Point center)
IScalablePoint.public T getShrinked(double h,
double v)
AbstractRectangleBasedGeometry, where the sides are
shrinked by the horizontal and vertical values supplied. The center of
this AbstractRectangleBasedGeometry is kept constant.h - horizontal reduction amountv - vertical reduction amountAbstractRectangleBasedGeometrypublic T getShrinked(double left,
double top,
double right,
double bottom)
AbstractRectangleBasedGeometry shrinked by the
specified insets.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 sideAbstractRectangleBasedGeometrypublic final Dimension getSize()
Dimension that records the width and height of this
AbstractRectangleBasedGeometry.Dimension that records the width and height of this
AbstractRectangleBasedGeometrypublic T getTranslated(double dx,
double dy)
ITranslatablegetTranslated in interface ITranslatable<T extends org.eclipse.gef.geometry.planar.AbstractRectangleBasedGeometry<?,?>>dx - x-translationdy - y-translationpublic T getTranslated(Point pt)
ITranslatablePoint.getTranslated in interface ITranslatable<T extends org.eclipse.gef.geometry.planar.AbstractRectangleBasedGeometry<?,?>>pt - translation Pointpublic final double getWidth()
AbstractRectangleBasedGeometry.AbstractRectangleBasedGeometrypublic final double getX()
AbstractRectangleBasedGeometry.AbstractRectangleBasedGeometrypublic final double getY()
AbstractRectangleBasedGeometry.AbstractRectangleBasedGeometrypublic T scale(double factor)
IScalablePoint.public T scale(double fx,
double fy)
IScalablePoint.public T scale(double factor,
double cx,
double cy)
IScalablePoint (cx, cy).public T scale(double fx,
double fy,
double cx,
double cy)
IScalablePoint (cx, cy).scale in interface IScalable<T extends org.eclipse.gef.geometry.planar.AbstractRectangleBasedGeometry<?,?>>fx - x-scale-factorfy - y-scale-factorcx - x-coordinate of the relative Point for the scalingcy - y-coordinate of the relative Point for the scalingthis for conveniencepublic T scale(double fx,
double fy,
Point center)
IScalablePoint.public T scale(double factor,
Point center)
IScalablePoint.public final T setBounds(double x,
double y,
double w,
double h)
AbstractRectangleBasedGeometry to the given values.x - the new x-coordinatey - the new y-coordinatew - the new widthh - the new heightthis for conveniencepublic final T setBounds(Rectangle r)
AbstractRectangleBasedGeometry to the respective values of the
given Rectangle.r - the Rectangle specifying the new x, y, width, and
height values of this AbstractRectangleBasedGeometrythis for conveniencepublic final T setHeight(double height)
AbstractRectangleBasedGeometry to the
given value.height - the new heightthis for conveniencepublic final T setLocation(double x,
double y)
AbstractRectangleBasedGeometry to the specified values.x - the new x coordinate of this
AbstractRectangleBasedGeometryy - the new y coordinate of this
AbstractRectangleBasedGeometrythis for conveniencepublic final T setLocation(Point p)
AbstractRectangleBasedGeometry to the respective values of the
given Point.p - the Point specifying the new x and y coordinates of
this AbstractRectangleBasedGeometrythis for conveniencepublic final T setSize(Dimension d)
AbstractRectangleBasedGeometry
to the width and height of the given Dimension.d - the Dimension specifying the new width and height of
this AbstractRectangleBasedGeometrythis for conveniencepublic final T setSize(double w,
double h)
AbstractRectangleBasedGeometry
to the given values.w - the new width of this AbstractRectangleBasedGeometryh - the new height of this AbstractRectangleBasedGeometrythis for conveniencepublic final T setWidth(double width)
AbstractRectangleBasedGeometry to the
passed-in value.width - the new width of this AbstractRectangleBasedGeometrythis for conveniencepublic final T setX(double x)
AbstractRectangleBasedGeometry to
the given value.x - The new x-coordinate.this for convenience.public final T setY(double y)
AbstractRectangleBasedGeometry to
the given value.y - The new y-coordinate.this for convenience.public T shrink(double h,
double v)
AbstractRectangleBasedGeometry by the
horizontal and vertical values provided as input, and returns this
AbstractRectangleBasedGeometry for convenience. The center of
this AbstractRectangleBasedGeometry is kept constant.h - horizontal reduction amountv - vertical reduction amountthis for conveniencepublic T shrink(double left,
double top,
double right,
double bottom)
AbstractRectangleBasedGeometry by the specified
amounts.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 sidethis for conveniencepublic T translate(double dx,
double dy)
ITranslatabletranslate in interface ITranslatable<T extends org.eclipse.gef.geometry.planar.AbstractRectangleBasedGeometry<?,?>>dx - x-translationdy - y-translationthis for conveniencepublic T translate(Point p)
ITranslatablePoint.translate in interface ITranslatable<T extends org.eclipse.gef.geometry.planar.AbstractRectangleBasedGeometry<?,?>>p - translation Pointthis for conveniencepublic java.lang.Object clone()
Cloneable
.clone in class java.lang.Objectpublic final int hashCode()
hashCode in class java.lang.ObjectObject.hashCode()Copyright (c) 2014 itemis AG, and others. All rights reserved.