Package lejos.robotics.geometry
Class RectangleInt32
- java.lang.Object
-
- lejos.robotics.geometry.RectangularShape
-
- lejos.robotics.geometry.Rectangle2D
-
- lejos.robotics.geometry.RectangleInt32
-
- All Implemented Interfaces:
java.lang.Cloneable,Shape
public class RectangleInt32 extends Rectangle2D
A rectangle with integer coordinates.- Author:
- Lawrie Griffiths
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class lejos.robotics.geometry.Rectangle2D
Rectangle2D.Double, Rectangle2D.Float
-
-
Field Summary
Fields Modifier and Type Field Description intheightThe height of the rectangleintwidthThe width of the rectangleintxThe x coordinate of the top left of the rectangleintyThe y coordinate of the top right of the rectangle-
Fields inherited from class lejos.robotics.geometry.Rectangle2D
OUT_BOTTOM, OUT_LEFT, OUT_RIGHT, OUT_TOP
-
-
Constructor Summary
Constructors Constructor Description RectangleInt32()Creates an empty rectangle at (0,0).RectangleInt32(int width, int height)Creates a rectangle with top left corner at (0,0) and with specified width and height.RectangleInt32(int x, int y, int width, int height)Creates a rectangle with top left corner at (x,y) and with specified width and height.RectangleInt32(Point p)Create an empty rectangle at the given point
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description booleancontains(int x, int y)Test if a point given by (x,y) coordinates is within the rectanglebooleancontains(Point p)Test if a point is within the rectanglebooleancontains(RectangleInt32 r)Test if this rectangle contains a specified rectanglebooleanequals(java.lang.Object obj)Test if the Rectangle is equal to a given objectRectangleInt32getBounds()Get the bounds of this rectangular shape as a RectangleRectangle2DgetBounds2D()Get the bounding Rectangle2D for the shapedoublegetHeight()Get the height as a doublePointgetLocation()Get the location of the rectangledoublegetWidth()Get the width as a doubledoublegetX()Get the x coordinate as a doubledoublegetY()Get the y coordinate as a doublebooleaninside(int x, int y)Deprecated.booleanintersects(RectangleInt32 r)Test if this rectangle intersects a specified rectanglebooleanisEmpty()Test if the rectangle is emptyintoutcode(double x, double y)Returns a mask value that specifies where a point lies with respect to this rectangle.voidreshape(int x, int y, int width, int height)Deprecated.voidresize(int width, int height)Deprecated.voidsetBounds(int x, int y, int width, int height)Set the bounds of this rectanglevoidsetBounds(RectangleInt32 r)Set the bounds of this rectangle to the given rectanglevoidsetLocation(int x, int y)Move the rectangle to (x,y)voidsetLocation(Point p)Set the location of this point to the location of a given pointvoidsetRect(double x, double y, double width, double height)Set this rectangle to a rectangle defined by double coordinatesvoidsetSize(int width, int height)Set the size of the rectanglejava.lang.StringtoString()Returns a String representing this rectangle.-
Methods inherited from class lejos.robotics.geometry.Rectangle2D
contains, contains, intersects, intersectsLine, outcode, setFrame, setRect
-
Methods inherited from class lejos.robotics.geometry.RectangularShape
clone, contains, contains, getCenterX, getCenterY, getFrame, getMaxX, getMaxY, getMinX, getMinY, intersects, setFrame
-
-
-
-
Constructor Detail
-
RectangleInt32
public RectangleInt32(int x, int y, int width, int height)Creates a rectangle with top left corner at (x,y) and with specified width and height.- Parameters:
x- the x coordinate of the top left cornery- the y coordinate of the top left cornerwidth- the width of the rectangleheight- the height of the rectangle
-
RectangleInt32
public RectangleInt32(int width, int height)Creates a rectangle with top left corner at (0,0) and with specified width and height.- Parameters:
width- the width of the rectangleheight- the height of the rectangle
-
RectangleInt32
public RectangleInt32()
Creates an empty rectangle at (0,0).
-
RectangleInt32
public RectangleInt32(Point p)
Create an empty rectangle at the given point- Parameters:
p- trhe point
-
-
Method Detail
-
getX
public double getX()
Get the x coordinate as a double- Specified by:
getXin classRectangularShape- Returns:
- the x coordinate
-
getY
public double getY()
Get the y coordinate as a double- Specified by:
getYin classRectangularShape- Returns:
- the y coordinate
-
getWidth
public double getWidth()
Get the width as a double- Specified by:
getWidthin classRectangularShape- Returns:
- the width
-
getHeight
public double getHeight()
Get the height as a double- Specified by:
getHeightin classRectangularShape- Returns:
- the height
-
setLocation
public void setLocation(int x, int y)Move the rectangle to (x,y)- Parameters:
x- the new x coordinatey- the new y coordinate
-
setLocation
public void setLocation(Point p)
Set the location of this point to the location of a given point- Parameters:
p- the given point
-
isEmpty
public boolean isEmpty()
Test if the rectangle is empty- Specified by:
isEmptyin classRectangularShape- Returns:
- true iff the rectangle is empty
-
contains
public boolean contains(int x, int y)Test if a point given by (x,y) coordinates is within the rectangle- Parameters:
x- the x coordinatey- the y coordinate- Returns:
- true iff the point is within the rectangle
-
contains
public boolean contains(Point p)
Test if a point is within the rectangle- Parameters:
p- the point- Returns:
- true iff the point is within the rectangle
-
contains
public boolean contains(RectangleInt32 r)
Test if this rectangle contains a specified rectangle- Parameters:
r- the specified rectangle- Returns:
- true iff the specified rectangle is contained within this rectangle
-
intersects
public boolean intersects(RectangleInt32 r)
Test if this rectangle intersects a specified rectangle- Parameters:
r- the given rectangle- Returns:
- true iff this rectangle intersects the given rectangle
-
getBounds
public RectangleInt32 getBounds()
Description copied from class:RectangularShapeGet the bounds of this rectangular shape as a Rectangle- Specified by:
getBoundsin interfaceShape- Overrides:
getBoundsin classRectangularShape- Returns:
- the bounds as a Rectangle
-
getBounds2D
public Rectangle2D getBounds2D()
Description copied from interface:ShapeGet the bounding Rectangle2D for the shape- Returns:
- the bounding Rectangle2D
-
setBounds
public void setBounds(int x, int y, int width, int height)Set the bounds of this rectangle- Parameters:
x- the new x coordinatey- the new y coordinatewidth- the new widthheight- the new height
-
setBounds
public void setBounds(RectangleInt32 r)
Set the bounds of this rectangle to the given rectangle- Parameters:
r- the new rectangle
-
setRect
public void setRect(double x, double y, double width, double height)Description copied from class:Rectangle2DSet this rectangle to a rectangle defined by double coordinates- Specified by:
setRectin classRectangle2D- Parameters:
x- the x coordinate of the top left cornery- the y coordinate of the top right cornerwidth- the width of the rectangleheight- the height of the rectangle
-
reshape
@Deprecated public void reshape(int x, int y, int width, int height)Deprecated.Use setBounds.
-
equals
public boolean equals(java.lang.Object obj)
Test if the Rectangle is equal to a given object- Overrides:
equalsin classRectangle2D- Parameters:
obj- the object
-
getLocation
public Point getLocation()
Get the location of the rectangle- Returns:
- the (x,y) coordinate of the top left corner
-
setSize
public void setSize(int width, int height)Set the size of the rectangle- Parameters:
width- the new widthheight- the new height
-
resize
@Deprecated public void resize(int width, int height)Deprecated.Use setSize
-
toString
public java.lang.String toString()
Returns a String representing this rectangle.- Overrides:
toStringin classjava.lang.Object
-
outcode
public int outcode(double x, double y)Description copied from class:Rectangle2DReturns a mask value that specifies where a point lies with respect to this rectangle.- Specified by:
outcodein classRectangle2D- Parameters:
x- the x coordinate of the given pointy- the y coordinate of the given point- Returns:
- the mask value
-
inside
@Deprecated public boolean inside(int x, int y)Deprecated.
-
-