- Object
-
- AbstractShape
-
- Polygon
-
- Rectangle
-
- All Implemented Interfaces:
DataContainer
,Convex
,Rotatable
,Shape
,Transformable
,Translatable
,Wound
public class Rectangle extends Polygon implements Convex, Wound, Shape, Transformable, DataContainer
Implementation of a RectangleConvex
Shape
.This class represents both axis-aligned and oriented rectangles and squares.
A
Rectangle
must have a width and height greater than zero.- Since:
- 1.0.0
- Version:
- 3.4.0
- Author:
- William Bittle
-
-
Constructor Summary
Constructors Constructor Description Rectangle(double width, double height)
Full constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
computeAABB(Transform transform, AABB aabb)
boolean
contains(Vector2 point, Transform transform)
Returns true if the given point is inside thisShape
.Mass
createMass(double density)
Vector2[]
getAxes(Vector2[] foci, Transform transform)
Returns an array of separating axes to test for thisShape
.double
getHeight()
Returns the height.Rotation
getRotation()
double
getRotationAngle()
Returns the rotation about the local center in radians in the range [-π, π].double
getWidth()
Returns the width.Interval
project(Vector2 vector, Transform transform)
String
toString()
-
Methods inherited from class Polygon
getFarthestFeature, getFarthestPoint, getFoci, getNormalIterator, getNormals, getRadius, getVertexIterator, getVertices, rotate, translate
-
Methods inherited from class AbstractShape
computeAABB, contains, createAABB, createAABB, getCenter, getRadius, getUserData, project, rotate, rotate, rotate, rotate, rotate, rotateAboutCenter, setUserData, translate
-
Methods inherited from interface Convex
getFarthestFeature, getFarthestPoint, getFoci
-
Methods inherited from interface DataContainer
getUserData, setUserData
-
Methods inherited from interface Shape
computeAABB, contains, createAABB, createAABB, getCenter, getRadius, getRadius, project, rotateAboutCenter
-
Methods inherited from interface Translatable
translate, translate
-
Methods inherited from interface Wound
getNormalIterator, getNormals, getVertexIterator, getVertices
-
-
-
-
Constructor Detail
-
Rectangle
public Rectangle(double width, double height)
Full constructor.The center of the rectangle will be the origin.
A rectangle must have a width and height greater than zero.
- Parameters:
width
- the widthheight
- the height- Throws:
IllegalArgumentException
- if width or height is less than or equal to zero
-
-
Method Detail
-
getHeight
public double getHeight()
Returns the height.- Returns:
- double
-
getWidth
public double getWidth()
Returns the width.- Returns:
- double
-
getRotationAngle
public double getRotationAngle()
Returns the rotation about the local center in radians in the range [-π, π].- Returns:
- double the rotation in radians
- Since:
- 3.0.1
-
getRotation
public Rotation getRotation()
- Returns:
- the
Rotation
object that represents the local rotation
-
getAxes
public Vector2[] getAxes(Vector2[] foci, Transform transform)
Description copied from interface:Convex
Returns an array of separating axes to test for thisShape
.The
foci
parameter is an array of circular focal points of the otherShape
.If foci points are given, this method will return the separating axes for this
Shape
's voronoi regions also. The points in the foci array are assumed to be in world space.The returned axes are normalized and in world space.
-
contains
public boolean contains(Vector2 point, Transform transform)
Description copied from interface:Shape
-
project
public Interval project(Vector2 vector, Transform transform)
Description copied from interface:Shape
-
createMass
public Mass createMass(double density)
Creates aMass
object using the geometric properties of thisRectangle
and the given density.m = d * h * w I = m * (h2 + w2) / 12
- Specified by:
createMass
in interfaceShape
- Overrides:
createMass
in classPolygon
- Parameters:
density
- the density in kg/m2- Returns:
Mass
theMass
of thisRectangle
-
computeAABB
public void computeAABB(Transform transform, AABB aabb)
Description copied from interface:Shape
Computes theAABB
from thisShape
after applying the given transformation and places the result in the givenAABB
.- Specified by:
computeAABB
in interfaceShape
- Overrides:
computeAABB
in classPolygon
- Parameters:
transform
- theTransform
for thisShape
aabb
- the destinationAABB
-
-