Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## toxi.geom
Class Rect

    java.lang.Object
      toxi.geom.Rect

All Implemented Interfaces:
  Shape2D

Direct Known Subclasses:
  PointQuadtree

    public class Rect

extends java.lang.Object
implements Shape2D

Field Summary
`float` | `height`
`float` | `width`
`float` | `x`
`float` | `y`

Constructor Summary
`Rect()` Constructs an empty rectangle at point 0,0 with no dimensions.
`Rect(float x, float y, float width, float height)` Constructs a new rectangle using a point and dimensions
`Rect(ReadonlyVec2D topLeft, ReadonlyVec2D bottomRight)` Constructs a new rectangle defined by its top left and bottom right points.

Method Summary
`boolean` | `containsPoint(ReadonlyVec2D p)` Checks if the given point is within the rectangle's bounds.
`Rect` | `copy()` Creates a copy of this rectangle
`static Rect` | `fromCenterExtent(ReadonlyVec2D center, Vec2D extent)` Factory method, constructs a new rectangle from a center point and extent vector.
`float` | `getArea()` Computes the area of the shape.
`float` | `getAspect()` Computes the aspect ratio of the rect as width over height.
`float` | `getBottom()`
`Vec2D` | `getBottomRight()`
`Vec2D` | `getCentroid()` Returns the centroid of the rectangle.
`float` | `getCircumference()` Computes the shape's circumference.
`Vec2D` | `getDimensions()` Returns a vector containing the width and height of the rectangle.
`Line2D` | `getEdge(int id)` Returns one of the rectangles edges as `Line2D`.
`float` | `getLeft()`
`float` | `getRight()`
`float` | `getTop()`
`Vec2D` | `getTopLeft()`
`ReadonlyVec2D` | `intersectsRay(Ray2D ray, float minDist, float maxDist)` Checks if the rectangle intersects with the given ray and if so computes the first intersection point.
`boolean` | `intersectsRect(Rect r)` Checks if this rectangle intersects/overlaps the given one.
`Rect` | `scale(float s)`
`Rect` | `set(float x, float y, float w, float h)` Sets new bounds for this rectangle.
`Rect` | `set(Rect r)`
`Rect` | `setDimension(Vec2D dim)`
`Rect` | `setPosition(Vec2D pos)`
`Polygon2D` | `toPolygon2D()` Creates a `Polygon2D` instance of the rect.
`java.lang.String` | `toString()`
`Rect` | `union(Rect r)` Updates the bounds of this rectangle by forming an union with the given rect.

Methods inherited from class java.lang.Object
`equals, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Field Detail

### x

    public float x

### y

    public float y

### width

    public float width

### height

    public float height

Constructor Detail

### Rect

    public Rect()

  Constructs an empty rectangle at point 0,0 with no dimensions.

### Rect

    public Rect(float x,
                float y,
                float width,
                float height)

  Constructs a new rectangle using a point and dimensions

  Parameters:
    `x` - x of top left
    `y` - y of top left
    `width` -
    `height` -

### Rect

    public Rect(ReadonlyVec2D topLeft,
                ReadonlyVec2D bottomRight)

  Constructs a new rectangle defined by its top left and bottom right points.

  Parameters:
    `topLeft` -
    `bottomRight` -

Method Detail

### fromCenterExtent

    public static final Rect fromCenterExtent(ReadonlyVec2D center,
                                              Vec2D extent)

  Factory method, constructs a new rectangle from a center point and extent vector.

  Parameters:
    `center` -
    `extent` -
  Returns:
    new rect

### containsPoint

    public boolean containsPoint(ReadonlyVec2D p)

  Checks if the given point is within the rectangle's bounds.

  Specified by:
    `containsPoint` in interface `Shape2D`
  Parameters:
    `p` - point to check
  Returns:
    true, if point is contained

### copy

    public Rect copy()

  Creates a copy of this rectangle

  Returns:
    new instance

### getArea

    public final float getArea()

  Description copied from interface: `Shape2D`
  Computes the area of the shape.

  Specified by:
    `getArea` in interface `Shape2D`
  Returns:
    area

### getAspect

    public final float getAspect()

  Computes the aspect ratio of the rect as width over height.

  Returns:
    aspect ratio

### getBottom

    public float getBottom()

### getBottomRight

    public final Vec2D getBottomRight()

### getCentroid

    public final Vec2D getCentroid()

  Returns the centroid of the rectangle.

  Returns:
    centroid vector

### getCircumference

    public final float getCircumference()

  Description copied from interface: `Shape2D`
  Computes the shape's circumference.

  Specified by:
    `getCircumference` in interface `Shape2D`
  Returns:
    circumference

### getDimensions

    public final Vec2D getDimensions()

  Returns a vector containing the width and height of the rectangle.

  Returns:
    dimension vector

### getEdge

    public Line2D getEdge(int id)

  Returns one of the rectangles edges as `Line2D`. The edge IDs are:
  - 0 - top
  - 1 - right
  - 2 - bottom
  - 3 - left

  Parameters:
    `id` - edge ID
  Returns:
    edge as Line2D

### getLeft

    public float getLeft()

### getRight

    public float getRight()

### getTop

    public float getTop()

### getTopLeft

    public final Vec2D getTopLeft()

### intersectsRay

    public ReadonlyVec2D intersectsRay(Ray2D ray,
                                       float minDist,
                                       float maxDist)

  Checks if the rectangle intersects with the given ray and if so computes the first intersection point. The method takes a min/max distance interval along the ray in which the intersection must occur.

  Parameters:
    `ray` - intersection ray
    `minDist` - minimum distance
    `maxDist` - max distance
  Returns:
    intersection point or null if no intersection in the given interval

### intersectsRect

    public boolean intersectsRect(Rect r)

  Checks if this rectangle intersects/overlaps the given one.

  Parameters:
    `r` - another rect
  Returns:
    true, if intersecting

### scale

    public Rect scale(float s)

### set

    public final Rect set(float x,
                          float y,
                          float w,
                          float h)

  Sets new bounds for this rectangle.

  Parameters:
    `x` - x of top left
    `y` - y of top right
    `w` - width
    `h` - height
  Returns:
    itself

### set

    public final Rect set(Rect r)

### setDimension

    public final Rect setDimension(Vec2D dim)

### setPosition

    public final Rect setPosition(Vec2D pos)

### toPolygon2D

    public Polygon2D toPolygon2D()

  Creates a `Polygon2D` instance of the rect.

  Returns:
    rect as polygon

### toString

    public java.lang.String toString()

  Overrides:
    `toString` in class `java.lang.Object`

### union

    public final Rect union(Rect r)

  Updates the bounds of this rectangle by forming an union with the given rect. If the rects are not overlapping, the resulting bounds will be inclusive of both.

  Parameters:
    `r` -
  Returns:
    itself

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD