public class Rectangle extends Shape
geometry, positionChangeListeners, sizeChangeListeners
Constructor and Description |
---|
Rectangle()
Default constructor.
|
Rectangle(float x,
float y,
float width,
float height)
Constructor
|
Rectangle(Geometry geometry)
|
Rectangle(Rectangle rectangle)
Constructs a new
Rectangle as a copy of another |
Modifier and Type | Method and Description |
---|---|
boolean |
contains(Circle circle) |
boolean |
contains(float x,
float y)
Returns if a set of coordinates are contained inside this shape
|
boolean |
contains(Rectangle rectangle) |
boolean |
contains(Sizeable shape)
Returns if this shape contains the specified shape
|
boolean |
contains(org.mini2Dx.gdx.math.Vector2 point)
Returns if a
Vector2 is contained inside this shape |
Shape |
copy()
Returns an exact copy of this
Shape |
void |
dispose()
|
void |
draw(Graphics g)
Draws this shape using a
Graphics instance |
EdgeIterator |
edgeIterator()
Returns an
EdgeIterator for looping over the edges of this
Shape |
boolean |
equals(java.lang.Object obj) |
void |
fill(Graphics g)
Fills this shape using a
Graphics instance |
float |
getCenterX()
Returns the x coordinate of the center of this
Rectangle |
float |
getCenterY()
Returns the y coordinate of the center of this
Rectangle |
float |
getDistanceTo(float x,
float y)
Returns this distance between this object's x,y coordinates and the
provided xy coordinates
|
float |
getHeight()
Returns the height of this object
|
float |
getMaxX()
Returns the greatest x coordinate this
Rectangle |
float |
getMaxY()
Returns the greatest y coordinate this
Rectangle |
float |
getMinX()
Returns the least x coordinate this
Rectangle |
float |
getMinY()
Returns the least y coordinate this
Rectangle |
int |
getNumberOfSides()
Returns the number of edges of this object
|
Polygon |
getPolygon()
|
float |
getRotation()
Returns the rotation of this
Shape |
float[] |
getVertices()
Returns the vertices that make up this
Rectangle |
float |
getWidth()
Returns the width of this object
|
float |
getX()
Returns the x coordinate of this object
|
float |
getY()
Returns the y coordinate of this object
|
int |
hashCode() |
Rectangle |
intersection(Rectangle rect) |
boolean |
intersects(Circle circle)
|
boolean |
intersects(float x,
float y,
float width,
float height) |
boolean |
intersects(Polygon polygon)
|
boolean |
intersects(Rectangle rectangle)
Returns if the specified
Rectangle intersects this one |
boolean |
intersects(Sizeable shape)
Returns if this shape intersects a shape
|
boolean |
intersects(Triangle triangle)
|
boolean |
intersectsLineSegment(float x1,
float y1,
float x2,
float y2)
Returns if this shape intersects a line segment
|
boolean |
intersectsLineSegment(org.mini2Dx.gdx.math.Vector2 pointA,
org.mini2Dx.gdx.math.Vector2 pointB)
Returns if this shape intersects a line segment
|
boolean |
isCircle()
|
Rectangle |
lerp(Rectangle target,
float alpha) |
void |
rotate(float degrees)
Rotates this
Shape by a specified amount of degrees with its
first point as the origin |
void |
rotateAround(float centerX,
float centerY,
float degrees)
Rotates this
Shape by a specified amount of degrees around a
specified point |
void |
scale(float scale)
Scales the radius of this shape.
|
Rectangle |
set(float x,
float y,
float width,
float height) |
void |
set(Rectangle rectangle) |
void |
setCenter(float x,
float y)
Sets the center x,y coordinate of this object
|
void |
setCenterX(float x)
Sets the center x coordinate
|
void |
setCenterY(float y)
Sets the center y coordianate
|
Rectangle |
setHeight(float height) |
void |
setRadius(float radius)
Sets the radius of this shape.
|
void |
setRotation(float degrees)
Sets the rotation of this
Shape with its first point as the
origin |
void |
setRotationAround(float centerX,
float centerY,
float degrees)
Sets the rotation of this
Shape with a specified point as the
origin |
Rectangle |
setSize(float sizeXY) |
Rectangle |
setSize(float width,
float height) |
Rectangle |
setWidth(float width) |
void |
setX(float x)
Sets the x coordinate of this object
|
void |
setXY(float x,
float y)
Sets the x and y coordinate of this object
|
void |
setXY(org.mini2Dx.gdx.math.Vector2 position) |
void |
setY(float y)
Sets the y coordinate of this object
|
java.lang.String |
toString() |
void |
translate(float translateX,
float translateY)
Translates the x and y coordinate of this object
|
add, addPostionChangeListener, addSizeChangeListener, clearPositionChangeListeners, clearPositionListeners, clearPositionListeners, clearSizeChangeListeners, clearSizeListeners, clearSizeListeners, getDistanceTo, intersects, moveTowards, moveTowards, notifyPositionChangeListeners, notifyPositionListeners, notifyPositionListeners, notifySizeChangeListeners, notifySizeListeners, notifySizeListeners, removePositionChangeListener, removePositionListener, removePositionListener, removeSizeChangeListener, removeSizeListener, removeSizeListener, setRotationAround, subtract
public Rectangle()
Rectangle
at 0,0 with a width and
height of 1public Rectangle(float x, float y, float width, float height)
public void dispose()
Shape
public boolean contains(float x, float y)
Sizeable
x
- The x coordinate to checky
- The y coordinate to checkpublic boolean contains(org.mini2Dx.gdx.math.Vector2 point)
Sizeable
Vector2
is contained inside this shapepoint
- The Vector2
to checkVector2
public boolean contains(Sizeable shape)
Sizeable
public boolean contains(Rectangle rectangle)
public boolean contains(Circle circle)
public boolean intersects(Sizeable shape)
Sizeable
public boolean intersects(Circle circle)
public boolean intersects(Rectangle rectangle)
Rectangle
intersects this onepublic boolean intersects(float x, float y, float width, float height)
public boolean intersects(Triangle triangle)
public boolean intersects(Polygon polygon)
public boolean intersectsLineSegment(org.mini2Dx.gdx.math.Vector2 pointA, org.mini2Dx.gdx.math.Vector2 pointB)
Sizeable
pointA
- The first point in the line segmentpointB
- The second point in the line segmentpublic boolean intersectsLineSegment(float x1, float y1, float x2, float y2)
Sizeable
x1
- The x coordinate of the first pointy1
- The y coordinate of the first pointx2
- The x coordinate of the second pointy2
- The y coordinate of the second pointpublic int getNumberOfSides()
Shape
getNumberOfSides
in interface Sizeable
getNumberOfSides
in class Shape
Shape.getNumberOfSides()
public void draw(Graphics g)
Shape
Graphics
instancedraw
in class Shape
g
- The Graphics
context to render withShape.draw(Graphics)
public void fill(Graphics g)
Shape
Graphics
instancepublic float getDistanceTo(float x, float y)
Positionable
x
- The x coordinate to measure distance toy
- The y coordinate to measure distance topublic float getRotation()
Shape
Shape
getRotation
in class Shape
public void setRotation(float degrees)
Shape
Shape
with its first point as the
originsetRotation
in class Shape
degrees
- The rotation in degreespublic void rotate(float degrees)
Shape
Shape
by a specified amount of degrees with its
first point as the originpublic void rotateAround(float centerX, float centerY, float degrees)
Shape
Shape
by a specified amount of degrees around a
specified pointrotateAround
in class Shape
centerX
- The origin/center x coordinatecenterY
- The origin/center y coordinatedegrees
- The rotation in degreespublic void setRotationAround(float centerX, float centerY, float degrees)
Shape
Shape
with a specified point as the
originsetRotationAround
in class Shape
centerX
- The origin/center x coordinatecenterY
- The origin/center y coordinatedegrees
- The rotation in degreespublic Rectangle set(float x, float y, float width, float height)
public void set(Rectangle rectangle)
public void setXY(float x, float y)
Positionable
x
- The x coordinatey
- The y coordinatepublic void setXY(org.mini2Dx.gdx.math.Vector2 position)
public float getX()
Positionable
public void setX(float x)
Positionable
x
- The x coordinatepublic float getY()
Positionable
public void setY(float y)
Positionable
y
- The y coordinatepublic float getWidth()
Sizeable
public Rectangle setWidth(float width)
public float getHeight()
Sizeable
public Rectangle setHeight(float height)
public Rectangle setSize(float width, float height)
public Rectangle setSize(float sizeXY)
public void setRadius(float radius)
Sizeable
Polygon
shapes, this will
stretch in/out the shape from its center. Note that Polygon
s must
be equilateral.radius
- The radius in pixelspublic void scale(float scale)
Sizeable
Polygon
shapes, this will
stretch in/out the shape from its center. Note that Polygon
s must
be equilateral.scale
- The amount to scale by (e.g. 2.0 = double the size)public void translate(float translateX, float translateY)
Shape
public EdgeIterator edgeIterator()
Shape
EdgeIterator
for looping over the edges of this
Shape
edgeIterator
in class Shape
EdgeIterator
public float getCenterX()
Rectangle
public float getCenterY()
Rectangle
public void setCenter(float x, float y)
Sizeable
x
- The x coordinate of the shape's centery
- The y coordinate of the shape's centerpublic void setCenterX(float x)
Sizeable
x
- The x coordinate of the shape's centerpublic void setCenterY(float y)
Sizeable
y
- The y coordinate of the shape's centerpublic float getMinX()
Rectangle
public float getMinY()
Rectangle
public float getMaxX()
Rectangle
public float getMaxY()
Rectangle
public float[] getVertices()
Rectangle
public java.lang.String toString()
toString
in class java.lang.Object
public boolean isCircle()
Shape
public Polygon getPolygon()
Shape
getPolygon
in interface Sizeable
getPolygon
in class Shape
Shape
is a Circle