Package breadboards
Class GRectangle
- java.lang.Object
-
- breadboards.GRectangle
-
public class GRectangle extends java.lang.Object
Class whose objects are rectangle whose width, height, and location coordinates are all stored as doubles- Author:
- paul oser
-
-
Field Summary
Fields Modifier and Type Field Description double
EMPTY_THRESHOLD
-
Constructor Summary
Constructors Constructor Description GRectangle()
constructs an empty rectangle (dimensions and coordinates are zero)GRectangle(double width, double height)
GRectangle(double x, double y, double width, double height)
constructs a rectangle with the specified dimensions at the specified location
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
contains(double x, double y)
returns true when point specified (i.e., (x,y)) is on or inside the GRectangleboolean
contains(GPoint p)
returns true when point specified is on or inside the GRectangledouble
getHeight()
returns the height of the GRectangleGPoint
getLocation()
returns the location of this GRectangleGDimension
getSize()
returns the dimensions of this GRectangledouble
getWidth()
returns the width of the GRectangledouble
getX()
returns the x-coordinate of the upper left corner of this rectangledouble
getY()
returns the y-coordinate of the upper left corner of this rectanglevoid
grow(double dx, double dy)
grows the dimensions of the rectangle (width by dx, height by dy)boolean
intersects(GRectangle otherRectangle)
boolean
isEmpty()
returns whether or not the width and height are essentially zero (i.e., sufficiently small)void
setLocation(double x, double y)
sets the location of the upper left corner of the rectangle to the specified coordinatesvoid
setSize(double width, double height)
sets the dimensions of the rectangle to those specifiedvoid
setSize(GDimension size)
sets the dimensions of the rectangle to the specified dimensionsjava.lang.String
toString()
void
translate(double dx, double dy)
translates the rectangle, adding dx to the x-coordinate and dy to the y-coordinate of its upper left cornerGRectangle
union(GRectangle r2)
returns the GRectangle that bounds both this GRectangle and another specified GRectangle
-
-
-
Field Detail
-
EMPTY_THRESHOLD
public final double EMPTY_THRESHOLD
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
GRectangle
public GRectangle()
constructs an empty rectangle (dimensions and coordinates are zero)
-
GRectangle
public GRectangle(double width, double height)
-
GRectangle
public GRectangle(double x, double y, double width, double height)
constructs a rectangle with the specified dimensions at the specified location- Parameters:
x
- x-coordinate of specified locationy
- y-coordinate of specified locationwidth
- specified widthheight
- specified height
-
-
Method Detail
-
contains
public boolean contains(double x, double y)
returns true when point specified (i.e., (x,y)) is on or inside the GRectangle- Parameters:
x
- x-coordinate of the point specifiedy
- y-coordinate of the point specified- Returns:
- true when (x,y) is on or inside the GRectangle, false otherwise
-
contains
public boolean contains(GPoint p)
returns true when point specified is on or inside the GRectangle- Parameters:
p
- the point specified- Returns:
- true when point specified is on or inside the GRectangle, false otherwise
-
intersects
public boolean intersects(GRectangle otherRectangle)
-
getWidth
public double getWidth()
returns the width of the GRectangle- Returns:
- the width of the GRectangle
-
getHeight
public double getHeight()
returns the height of the GRectangle- Returns:
- the height of the GRectangle
-
getLocation
public GPoint getLocation()
returns the location of this GRectangle- Returns:
- the location of this GRectangle
-
getSize
public GDimension getSize()
returns the dimensions of this GRectangle- Returns:
- the dimensions of this GRectangle
-
getX
public double getX()
returns the x-coordinate of the upper left corner of this rectangle- Returns:
- the x-coordinate of the upper left corner of this rectangle
-
getY
public double getY()
returns the y-coordinate of the upper left corner of this rectangle- Returns:
- the y-coordinate of the upper left corner of this rectangle
-
isEmpty
public boolean isEmpty()
returns whether or not the width and height are essentially zero (i.e., sufficiently small)- Returns:
- true if both width and height are less than GRectangle.EMPTY_THRESHOLD, false otherwise
-
setLocation
public void setLocation(double x, double y)
sets the location of the upper left corner of the rectangle to the specified coordinates- Parameters:
x
- x-coordinate specifiedy
- y-coordinate specified
-
setSize
public void setSize(double width, double height)
sets the dimensions of the rectangle to those specified- Parameters:
width
- the specified widthheight
- the specified height
-
setSize
public void setSize(GDimension size)
sets the dimensions of the rectangle to the specified dimensions- Parameters:
size
- the specified dimensions
-
grow
public void grow(double dx, double dy)
grows the dimensions of the rectangle (width by dx, height by dy)- Parameters:
dx
- amount to add to the width of the rectangledy
- amount to add to the height of the rectangle
-
translate
public void translate(double dx, double dy)
translates the rectangle, adding dx to the x-coordinate and dy to the y-coordinate of its upper left corner- Parameters:
dx
- amount to add to the x-coordinate of its upper left cornerdy
- amount to add to the y-coordinate of its upper left corner
-
union
public GRectangle union(GRectangle r2)
returns the GRectangle that bounds both this GRectangle and another specified GRectangle- Parameters:
r2
- the GRectangle specified- Returns:
- the GRectangle that bounds both this GRectangle and r2
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-