Package lejos.robotics.geometry
Class Rectangle2D
- java.lang.Object
-
- lejos.robotics.geometry.RectangularShape
-
- lejos.robotics.geometry.Rectangle2D
-
- All Implemented Interfaces:
java.lang.Cloneable,Shape
- Direct Known Subclasses:
Rectangle2D.Double,Rectangle2D.Float,RectangleInt32
public abstract class Rectangle2D extends RectangularShape
An abstract class for a Rectangle. Subclasses use float, double or integer coordinates.- Author:
- Lawrie Griffiths
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classRectangle2D.DoubleA Rectangle2D with double coordinatesstatic classRectangle2D.FloatA Rectangle2D with float coordinates.
-
Field Summary
Fields Modifier and Type Field Description static intOUT_BOTTOMThe bitmask that indicates that a point lies below this rectangle.static intOUT_LEFTThe bitmask that indicates that a point lies to the left of this rectangle.static intOUT_RIGHTThe bitmask that indicates that a point lies to the right of this rectangle.static intOUT_TOPThe bitmask that indicates that a point lies above this rectangle.
-
Constructor Summary
Constructors Modifier Constructor Description protectedRectangle2D()This is an abstract class which cannot be instantiated: use Rectangle2D.Float, Rectangle2D.Double, or Rectangle.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description booleancontains(double x, double y)Test if this Rectangle2D contains a rectangle defined by double coordinatesbooleancontains(double x, double y, double w, double h)Test if the shape contains the rectangle with top left at (x,y), width w and height h.booleanequals(java.lang.Object obj)Test if the rectangle is equal to a given objectbooleanintersects(double x, double y, double w, double h)Test if this Rectangle2D intersects a rectangle defined by double coordinatesbooleanintersectsLine(double x1, double y1, double x2, double y2)Test if this rectangle intersects a given lineabstract intoutcode(double x, double y)Returns a mask value that specifies where a point lies with respect to this rectangle.intoutcode(Point2D p)Returns a mask value that specifies where a given point lies with respect to this rectangle.voidsetFrame(double x, double y, double w, double h)Set the frame for the rectangular shapeabstract voidsetRect(double x, double y, double w, double h)Set this rectangle to a rectangle defined by double coordinatesvoidsetRect(Rectangle2D r)Set this Rectangle2D to be the same as a given Rectangle2D-
Methods inherited from class lejos.robotics.geometry.RectangularShape
clone, contains, contains, getBounds, getCenterX, getCenterY, getFrame, getHeight, getMaxX, getMaxY, getMinX, getMinY, getWidth, getX, getY, intersects, isEmpty, setFrame
-
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface lejos.robotics.geometry.Shape
getBounds2D
-
-
-
-
Field Detail
-
OUT_LEFT
public static final int OUT_LEFT
The bitmask that indicates that a point lies to the left of this rectangle.- See Also:
- Constant Field Values
-
OUT_TOP
public static final int OUT_TOP
The bitmask that indicates that a point lies above this rectangle.- See Also:
- Constant Field Values
-
OUT_RIGHT
public static final int OUT_RIGHT
The bitmask that indicates that a point lies to the right of this rectangle.- See Also:
- Constant Field Values
-
OUT_BOTTOM
public static final int OUT_BOTTOM
The bitmask that indicates that a point lies below this rectangle.- See Also:
- Constant Field Values
-
-
Method Detail
-
contains
public boolean contains(double x, double y, double w, double h)Description copied from interface:ShapeTest if the shape contains the rectangle with top left at (x,y), width w and height h.- Parameters:
x- the x-coordinate of the top left point of the rectangley- the y-coordinate of the top left point of the rectanglew- the width of the rectangleh- the height of the rectangle- Returns:
- true iff the shape contains the rectangle
-
setRect
public abstract void setRect(double x, double y, double w, double h)Set this rectangle to a rectangle defined by double coordinates- Parameters:
x- the x coordinate of the top left cornery- the y coordinate of the top right cornerw- the width of the rectangleh- the height of the rectangle
-
setRect
public void setRect(Rectangle2D r)
Set this Rectangle2D to be the same as a given Rectangle2D- Parameters:
r- the Rectangle2D
-
setFrame
public void setFrame(double x, double y, double w, double h)Description copied from class:RectangularShapeSet the frame for the rectangular shape- Specified by:
setFramein classRectangularShape- Parameters:
x- the x coordinate of the top left cornery- the y coordinate iof the top left cornerw- the widthh- the height
-
contains
public boolean contains(double x, double y)Test if this Rectangle2D contains a rectangle defined by double coordinates- Parameters:
x- the x co-ordinate of the pointy- the y co-ordinate of the point- Returns:
- true iff the shape contains the point
-
intersects
public boolean intersects(double x, double y, double w, double h)Test if this Rectangle2D intersects a rectangle defined by double coordinates- Parameters:
x- the x-coordinate of the top left point of the rectangley- the y-coordinate of the top left point of the rectanglew- the width of the rectangleh- the height of the rectangle- Returns:
- true iff the shape intersects the rectangle
-
intersectsLine
public boolean intersectsLine(double x1, double y1, double x2, double y2)Test if this rectangle intersects a given line- Parameters:
x1- the x coordinate of the start of the given liney1- the y coordinate of the start of the given linex2- the x coordinate of the end of the given liney2- the y coordinate of the end of the given line- Returns:
- true iff the rectangle intersects the line
-
outcode
public int outcode(Point2D p)
Returns a mask value that specifies where a given point lies with respect to this rectangle.- Parameters:
p- the given point- Returns:
- the mask value
-
outcode
public abstract int outcode(double x, double y)Returns a mask value that specifies where a point lies with respect to this rectangle.- Parameters:
x- the x coordinate of the given pointy- the y coordinate of the given point- Returns:
- the mask value
-
equals
public boolean equals(java.lang.Object obj)
Test if the rectangle is equal to a given object- Overrides:
equalsin classjava.lang.Object
-
-