hermes.hshape
Class HRectangle

java.lang.Object
  extended by hermes.hshape.HShape
      extended by hermes.hshape.HRectangle

public class HRectangle
extends HShape

Represents an axis-aligned bounding rectangle.


Field Summary
static int mode
           
 
Fields inherited from class hermes.hshape.HShape
_position
 
Constructor Summary
HRectangle(float a, float b, float c, float d)
          Creates a new Rectangle based on current rectMode.
HRectangle(PVector ab, float c, float d)
          Creates a new Rectangle based on current rectMode.
HRectangle(PVector ab, PVector cd)
          Creates a new Rectangle based on current rectMode.
HRectangle(PVector position, PVector min, PVector max)
          Creates a new Rectangle.
 
Method Summary
 boolean contains(float x, float y)
           
 boolean contains(HRectangle other)
          Whether this rectangle completely encloses another (no part of other protrudes from this).
 boolean contains(PVector point)
          Whether the Shape contains the given point coordinates (boundary is inclusive).
 void draw()
          Shortcut method for drawing the shape on screen
 PVector getAbsMax()
           
 PVector getAbsMin()
           
 HRectangle getBoundingBox()
          Finds the smallest Rectangle that encloses the shape.
 PVector getCenter()
           
 float getHeight()
           
 PVector getMax()
           
 PVector getMin()
           
 float getWidth()
           
 PVector projectionVector(HCircle other)
           
 PVector projectionVector(HPolygon other)
           
 PVector projectionVector(HRectangle other)
           
 PVector projectionVector(HShape other)
          Finds the projection vector for a collision with another shape.
 void scale(float xScale, float yScale)
          Scales the rectangle's width and height about its position.
 java.lang.String toString()
           
 
Methods inherited from class hermes.hshape.HShape
collide, getPosition
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

mode

public static int mode
Constructor Detail

HRectangle

public HRectangle(float a,
                  float b,
                  float c,
                  float d)
Creates a new Rectangle based on current rectMode.

Default - a and b define the upper left corner, and c and d are width and height, see Processing reference on rectMode() for details on other modes.

Parameters:
a -
b -
c -
d -

HRectangle

public HRectangle(PVector ab,
                  float c,
                  float d)
Creates a new Rectangle based on current rectMode.

Default - ab.x and ab.y define the upper left corner, and c and d are width and height, see Processing reference on rectMode() for details on other modes.

Parameters:
ab -
c -
d -

HRectangle

public HRectangle(PVector ab,
                  PVector cd)
Creates a new Rectangle based on current rectMode.

Default - ab.x and ab.y define the upper left corner, and cd.x and cd.y are width and height see Processing reference on rectMode() for details on other modes

Parameters:
ab -
cd -

HRectangle

public HRectangle(PVector position,
                  PVector min,
                  PVector max)
Creates a new Rectangle.

Directly assigns fields, does not link with rectMode.

Parameters:
position - - position of rectangle
min - - location of top left corner in relation to position
max - - location of bottom right corner in relation to position
Method Detail

getMin

public PVector getMin()
Returns:
Position of corner with lowest x,y values in Rectangle coordinates (shape's position is (0,0)).

getMax

public PVector getMax()
Returns:
Position of corner with highest x,y values in Rectangle coordinates (shape's position is (0,0)).

getAbsMin

public PVector getAbsMin()
Returns:
Position of corner with lowest x,y values in world coordinates.

getAbsMax

public PVector getAbsMax()
Returns:
Position of corner with highest x,y values in world coordinates.

getWidth

public float getWidth()

getHeight

public float getHeight()

getCenter

public PVector getCenter()
Returns:
The absolute position of the rectangle's geometric center.

scale

public void scale(float xScale,
                  float yScale)
Scales the rectangle's width and height about its position.

Parameters:
xScale - the x-axis scale factor
yScale - the y-axis scale factor

projectionVector

public PVector projectionVector(HShape other)
Description copied from class: HShape
Finds the projection vector for a collision with another shape.

The projection vector is the vector by which one body could be displaced such that it no longer intersects the other body, by the shortest possible distance.

Each shape must contain methods for collision with all other types of HShapes. If you create your own type of shape, you will have to modify HShape (as well as its subclasses) to contain methods colliding it with the new type.

Specified by:
projectionVector in class HShape
Parameters:
other - the shape to collide with
Returns:
the projection vector from this body to other, or null if they aren't colliding

projectionVector

public PVector projectionVector(HCircle other)
Specified by:
projectionVector in class HShape

projectionVector

public PVector projectionVector(HPolygon other)
Specified by:
projectionVector in class HShape

projectionVector

public PVector projectionVector(HRectangle other)
Specified by:
projectionVector in class HShape

getBoundingBox

public HRectangle getBoundingBox()
Description copied from class: HShape
Finds the smallest Rectangle that encloses the shape.

Specified by:
getBoundingBox in class HShape
Returns:
the bounding box

contains

public boolean contains(HRectangle other)
Whether this rectangle completely encloses another (no part of other protrudes from this).

Specified by:
contains in class HShape
Parameters:
other - the other rectangle
Returns:
whether it is completely contained

contains

public boolean contains(float x,
                        float y)
Specified by:
contains in class HShape
Parameters:
x - the x coordinate
y - the y coordinate
Returns:
true if (x,y) lies within the Shape

contains

public boolean contains(PVector point)
Description copied from class: HShape
Whether the Shape contains the given point coordinates (boundary is inclusive).

Specified by:
contains in class HShape
Parameters:
point - the point vector
Returns:
true if (x,y) lies within the Shape

draw

public void draw()
Description copied from class: HShape
Shortcut method for drawing the shape on screen

Specified by:
draw in class HShape

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object