public class Rectangle extends Object implements Shape, ReadWriteable, Serializable
| Modifier and Type | Field and Description |
|---|---|
float |
height
The height of the rectangle
|
float |
width
The width of the rectangle
|
float |
x
The x-coordinate of the top-left of the rectangle
|
float |
y
The y-coordinate of the top-left of the rectangle
|
| Constructor and Description |
|---|
Rectangle()
Construct a unit rectangle
|
Rectangle(float x,
float y,
float width,
float height)
Construct a Rectangle with the given parameters.
|
Rectangle(Point2d topLeft,
Point2d bottomRight)
Construct a Rectangle with the given parameters.
|
Rectangle(Rectangle r)
Construct a Rectangle by copying from another rectangle.
|
| Modifier and Type | Method and Description |
|---|---|
String |
asciiHeader()
Header for ascii input.
|
Polygon |
asPolygon()
Convert the shape to a polygon representation
|
byte[] |
binaryHeader()
Header for binary input.
|
double |
calculateArea()
Calculate the area of the shape
|
Point2d |
calculateCentroid()
Calculate the centroid of the shape
|
double |
calculatePerimeter()
Calculate the perimeter of the shape
|
Rectangle |
calculateRegularBoundingBox()
Compute the regular (oriented to the axes) bounding box of the shape.
|
Rectangle |
clone() |
boolean |
equals(Object obj) |
Point2d |
getBottomRight() |
double |
getHeight() |
Point2d |
getTopLeft() |
double |
getWidth() |
int |
hashCode() |
double |
intersectionArea(Shape that)
Calls
Polygon.intersectionArea(Shape, int) with 1 step per pixel
dimension. |
double |
intersectionArea(Shape that,
int nStepsPerDimension)
Return an estimate for the area of the intersection of this polygon and
another polygon.
|
boolean |
isConvex()
Test if the shape is convex.
|
boolean |
isInside(Point2d point)
Test whether the point p is inside the shape.
|
boolean |
isInside(Rectangle rect)
Test if the given rectangle is inside this one.
|
boolean |
isOverlapping(Rectangle other)
Test if rectangles overlap.
|
double |
maxX() |
double |
maxY() |
RotatedRectangle |
minimumBoundingRectangle()
Compute the minimum size rotated bounding rectangle that contains this
shape.
|
double |
minX() |
double |
minY() |
Rectangle |
overlapping(Rectangle other)
Get the overlapping rectangle between this rectangle and another.
|
double |
percentageOverlap(Rectangle other)
Compute the percentage by which the given rectangle overlaps this one.
|
void |
readASCII(Scanner in)
Read internal state from in.
|
void |
readBinary(DataInput in)
Read internal state from in.
|
RotatedRectangle |
rotate(Point2d p,
double angle)
Rotate the
Rectangle about the given pivot with the given angle
(in radians) |
void |
scale(float sc)
Scale the shape by the given amount about (0,0).
|
void |
scale(Point2d centre,
float sc)
Scale the shape by the given amount about the given point.
|
void |
scaleCentroid(float sc)
Scale the shape about its centroid.
|
void |
setBounds(float x,
float y,
float width,
float height)
Set the position and size of this rectangle
|
String |
toString() |
Shape |
transform(Jama.Matrix transform)
Apply a 3x3 transform matrix to a copy of the
GeometricObject2d and
return it |
void |
translate(float x,
float y)
Translate the shapes position
|
Rectangle |
union(Rectangle other)
Find the rectangle that just contains this rectangle and another
rectangle.
|
void |
writeASCII(PrintWriter out)
Write the content of this as ascii to out.
|
void |
writeBinary(DataOutput out)
Write the content of this as binary to out.
|
public float x
public float y
public float width
public float height
public Rectangle()
public Rectangle(float x, float y, float width, float height)
x - x-coordinate of top-lefty - y-coordinate of top-leftwidth - widthheight - heightpublic Rectangle(Rectangle r)
r - rectangle to copy frompublic boolean isInside(Point2d point)
Shapepublic Rectangle calculateRegularBoundingBox()
GeometricObject2dcalculateRegularBoundingBox in interface GeometricObject2dpublic void translate(float x, float y)
GeometricObject2dtranslate in interface GeometricObject2dx - x-translationy - y-translationpublic void scale(float sc)
GeometricObject2dscale in interface GeometricObject2dsc - the scale factor.public void scale(Point2d centre, float sc)
GeometricObject2dscale in interface GeometricObject2dcentre - the centre of the scaling operationsc - the scale factorpublic void scaleCentroid(float sc)
GeometricObject2dscaleCentroid in interface GeometricObject2dsc - the scale factorpublic Point2d calculateCentroid()
GeometricObject2dcalculateCentroid in interface GeometricObject2dpublic double calculateArea()
ShapecalculateArea in interface Shapepublic double minX()
minX in interface GeometricObject2dpublic double minY()
minY in interface GeometricObject2dpublic double maxX()
maxX in interface GeometricObject2dpublic double maxY()
maxY in interface GeometricObject2dpublic double getWidth()
getWidth in interface GeometricObject2dpublic double getHeight()
getHeight in interface GeometricObject2dpublic Point2d getTopLeft()
public Point2d getBottomRight()
public Shape transform(Jama.Matrix transform)
GeometricObject2dGeometricObject2d and
return ittransform in interface GeometricObject2dtransform in interface Shapetransform - 3x3 transform matrixpublic Polygon asPolygon()
Shapepublic void setBounds(float x, float y, float width, float height)
x - x-coordinate of top-lefty - y-coordinate of top-leftwidth - widthheight - heightpublic boolean isOverlapping(Rectangle other)
other - the rectangle to test with.public boolean isInside(Rectangle rect)
rect - the rectangle to test with.public Rectangle overlapping(Rectangle other)
other - the rectangle to test with.public double percentageOverlap(Rectangle other)
other - public Rectangle union(Rectangle other)
other - the other rectanglepublic double intersectionArea(Shape that)
ShapePolygon.intersectionArea(Shape, int) with 1 step per pixel
dimension. Subsequently this function returns the shared whole pixels of
this polygon and that.intersectionArea in interface Shapepublic double intersectionArea(Shape that, int nStepsPerDimension)
ShapeintersectionArea in interface Shapepublic void readASCII(Scanner in) throws IOException
ReadableASCIIreadASCII in interface ReadableASCIIin - source to read from.IOException - an error reading inputpublic String asciiHeader()
ReadableASCIIasciiHeader in interface ReadableASCIIasciiHeader in interface WriteableASCIIpublic void readBinary(DataInput in) throws IOException
ReadableBinaryreadBinary in interface ReadableBinaryin - source to read from.IOException - an error reading inputpublic byte[] binaryHeader()
ReadableBinarybinaryHeader in interface ReadableBinarybinaryHeader in interface WriteableBinarypublic void writeASCII(PrintWriter out) throws IOException
WriteableASCIIwriteASCII in interface WriteableASCIIout - sink to write toIOException - an error writing to outpublic void writeBinary(DataOutput out) throws IOException
WriteableBinarywriteBinary in interface WriteableBinaryout - sink to write toIOException - an error writing to outpublic double calculatePerimeter()
ShapecalculatePerimeter in interface Shapepublic RotatedRectangle minimumBoundingRectangle()
ShapeminimumBoundingRectangle in interface Shapepublic RotatedRectangle rotate(Point2d p, double angle)
Rectangle about the given pivot with the given angle
(in radians)p - the pivot of the rotationangle - the angle in radians