net.returnvoid.graphics.shape

## Class Rect

- java.lang.Object
- - net.returnvoid.graphics.shape.Rect

- All Implemented Interfaces:
    RShape

      public class Rect
      extends java.lang.Object
      implements RShape

  A class for building and transforming rectangles.
  Author:
    Diana Lange

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected processing.core.PApplet` | `parent` The PApplet object for drawing thinks.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `Rect(processing.core.PApplet parent, float x, float y, float width, float height)` Builds a new rectangle with the given parameters.
    `Rect(processing.core.PApplet parent, processing.core.PVector p, processing.core.PVector dimension)` Builds a new rectangle with the given parameters.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `computeMinMax()` Forces to calculate the bounds of this shape and store them.
    `Rect` | `copy()` Builds and returns a true copy of this shape.
    `Rect` | `draw()` Draws the shape-
    `processing.core.PVector` | `get(int i)` Returns the coordinate with index i.
    `float` | `getArea()` Returns the area (width * height).
    `Rect` | `getBoundingBox()` Returns the bounding box of this shape (will mark the bounds of the shape).
    `processing.core.PVector` | `getCenter()` Returns the center coordinate of this shape.
    `processing.core.PVector[]` | `getCoordinates()` Returns all coordinates that defines this shape.
    `float` | `getHeight()` Returns the height of the rectangle.
    `Line[]` | `getLines()` Converts the rectangle to four lines.
    `LineSegments` | `getLineSegments()` Converts the rectangle to LineSegments.
    `java.lang.Float` | `getRotation()` Returns the angle of shape.
    `processing.core.PVector` | `getStart()` Returns the start coordinate for this shape.
    `float` | `getWidth()` Returns the width of the rectangle.
    `java.lang.Float` | `getX()` Returns the x-position of the start coordinate for this shape.
    `java.lang.Float` | `getY()` Returns the y-position of the start coordinate for this shape.
    `Rect` | `rotate(float angle)` Turns the shape through the given angle.
    `Rect` | `rotate(processing.core.PVector rotationCenter, float angle)` Turns the shape through the given angle.
    `Rect` | `scale(float scale)` Scale the shape by the given scaling factor.
    `Rect` | `scale(processing.core.PVector scaleCenter, float scale)` Scale the shape by the given scaling factor.
    `Rect` | `scale(processing.core.PVector scaleCenter, float scaleX, float scaleY)` Scales the shape by the given scaling factors.
    `Rect` | `setDimension(float width, float height)` Sets the width and height of the rectangle.
    `Rect` | `setDimension(processing.core.PVector center, float width, float height)` Sets the width and height of the rectangle.
    `Rect` | `setHeight(float height)` Sets the height of the rectangle.
    `Rect` | `setHeight(processing.core.PVector center, float height)` Sets the height of the rectangle.
    `Rect` | `setLocation(float x, float y)` Translates the shape to the given location.
    `Rect` | `setRotation(float angle)` Rotates the shape to the given angle (past rotations will be overridden).
    `Rect` | `setRotation(processing.core.PVector rotationCenter, float angle)` Rotates the shape to the given angle (past rotations will be overridden).
    `Rect` | `setWidth(float width)` Sets the width of the rectangle.
    `Rect` | `setWidth(processing.core.PVector center, float width)` Sets the width of the rectangle.
    `Rect` | `setX(float x)` Translates the shape to the given x-location.
    `Rect` | `setY(float y)` Translates the shape to the given y-location.
    `int` | `size()` Returns the number of coordinates for this shape.
    `Line[]` | `toLines()` Converts the rectangle to four lines.
    `LineSegments` | `toLineSegments()` Converts the rectangle to LineSegments.
    `Rect` | `translate(float x, float y)` Translates the coordinates by the given parameters x, y ( "moves the shape by x, y").

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### parent

          protected processing.core.PApplet parent

      The PApplet object for drawing thinks.

  - ### Constructor Detail

    - #### Rect

          public Rect(processing.core.PApplet parent,
                      float x,
                      float y,
                      float width,
                      float height)

      Builds a new rectangle with the given parameters. The rotation for any newly built shape will be 0.
      Parameters:
        `parent` - The PApplet object.
        `x` - The x-location of the rectangle (top-left corner).
        `y` - The y-location of the rectangle (top-left corner).
        `width` - The width the rectangle.
        `height` - The height the rectangle.

    - #### Rect

          public Rect(processing.core.PApplet parent,
                      processing.core.PVector p,
                      processing.core.PVector dimension)

      Builds a new rectangle with the given parameters. The rotation for any newly built shape will be 0.
      Parameters:
        `parent` - The PApplet object.
        `p` - The location of the rectangle (top-left corner).
        `dimension` - The width and height of the rectangle.

  - ### Method Detail

    - #### size

          public int size()

      Description copied from interface: `RShape`
      Returns the number of coordinates for this shape. Can be used to iterate over all coordinates for this shape (e.g. for drawing the shape). Example:

           for (int i = 0; i < myShape.size(); i++) {
                  PVector p = myShape.get(i);
           }

      Specified by:
        `size` in interface `RShape`
      Returns:
        The number of coordinates for this shape.

    - #### get

          public processing.core.PVector get(int i)

      Description copied from interface: `RShape`
      Returns the coordinate with index i. Please make sure i is within bounds, e.g. using the size() method. Example:

           for (int i = 0; i < myShape.size(); i++) {
                  PVector p = myShape.get(i);
           }

      Specified by:
        `get` in interface `RShape`
      Parameters:
        `i` - The index of a coordinates of this shape.
      Returns:
        The coordinate of the shape with the given index.

    - #### getStart

          public processing.core.PVector getStart()

      Description copied from interface: `RShape`
      Returns the start coordinate for this shape. The start is defined differently for each shape. For a Line it is one of the ends, for a Rect it is the top left corner (when no rotation is applied) and so on.
      Specified by:
        `getStart` in interface `RShape`
      Returns:
        The start coordinate for the shape.

    - #### getBoundingBox

          public Rect getBoundingBox()

      Description copied from interface: `RShape`
      Returns the bounding box of this shape (will mark the bounds of the shape).
      Specified by:
        `getBoundingBox` in interface `RShape`
      Returns:
        The bounding box.

    - #### getCenter

          public processing.core.PVector getCenter()

      Description copied from interface: `RShape`
      Returns the center coordinate of this shape.
      Specified by:
        `getCenter` in interface `RShape`
      Returns:
        The center coordinate of this shape.

    - #### getX

          public java.lang.Float getX()

      Description copied from interface: `RShape`
      Returns the x-position of the start coordinate for this shape. The start is defined differently for each shape. For a Line it is one of the ends, for a Rect it is the top left corner (when no rotation is applied) and so on.
      Specified by:
        `getX` in interface `RShape`
      Returns:
        The x-position start coordinate for the shape.

    - #### getY

          public java.lang.Float getY()

      Description copied from interface: `RShape`
      Returns the y-position of the start coordinate for this shape. The start is defined differently for each shape. For a Line it is one of the ends, for a Rect it is the top left corner (when no rotation is applied) and so on.
      Specified by:
        `getY` in interface `RShape`
      Returns:
        The y-position start coordinate for the shape.

    - #### getWidth

          public float getWidth()

      Returns the width of the rectangle.
      Returns:
        The width.

    - #### getHeight

          public float getHeight()

      Returns the height of the rectangle.
      Returns:
        The height.

    - #### getArea

          public float getArea()

      Returns the area (width * height).
      Returns:
        The area.

    - #### getCoordinates

          public processing.core.PVector[] getCoordinates()

      Description copied from interface: `RShape`
      Returns all coordinates that defines this shape.
      Specified by:
        `getCoordinates` in interface `RShape`
      Returns:
        The coordinates of this shape.

    - #### getRotation

          public java.lang.Float getRotation()

      Description copied from interface: `RShape`
      Returns the angle of shape.
      Specified by:
        `getRotation` in interface `RShape`
      Returns:
        The angle of the shape.

    - #### copy

          public Rect copy()

      Description copied from interface: `RShape`
      Builds and returns a true copy of this shape.
      Specified by:
        `copy` in interface `RShape`
      Returns:
        The copy of this shape.

    - #### setRotation

          public Rect setRotation(float angle)

      Description copied from interface: `RShape`
      Rotates the shape to the given angle (past rotations will be overridden). The rotation center will be the getStart() of this shape.
      Specified by:
        `setRotation` in interface `RShape`
      Parameters:
        `angle` - The target rotation angle.
      Returns:
        The current shape.

    - #### setRotation

          public Rect setRotation(processing.core.PVector rotationCenter,
                                  float angle)

      Description copied from interface: `RShape`
      Rotates the shape to the given angle (past rotations will be overridden). The rotation center will be the given location c.
      Specified by:
        `setRotation` in interface `RShape`
      Parameters:
        `rotationCenter` - The rotation center.
        `angle` - The target rotation angle.
      Returns:
        The current shape.

    - #### setDimension

          public Rect setDimension(float width,
                                   float height)

      Sets the width and height of the rectangle. The rectangle will be scaled around getStart().
      Parameters:
        `width` - The new width of the rectangle (> 0).
        `height` - The new height of the rectangle (> 0).
      Returns:
        The current shape.

    - #### setDimension

          public Rect setDimension(processing.core.PVector center,
                                   float width,
                                   float height)

      Sets the width and height of the rectangle. The rectangle will be scaled around center.
      Parameters:
        `center` - The control point for the scaling.
        `width` - The new width of the rectangle (> 0).
        `height` - The new height of the rectangle (> 0).
      Returns:
        The current shape.

    - #### setWidth

          public Rect setWidth(float width)

      Sets the width of the rectangle. The rectangle will be scaled around getStart().
      Parameters:
        `width` - The new width of the rectangle (> 0).
      Returns:
        The current shape.

    - #### setWidth

          public Rect setWidth(processing.core.PVector center,
                               float width)

      Sets the width of the rectangle. The rectangle will be scaled around center.
      Parameters:
        `center` - The control point for the scaling.
        `width` - The new width of the rectangle (> 0).
      Returns:
        The current shape.

    - #### setHeight

          public Rect setHeight(float height)

      Sets the height of the rectangle. The rectangle will be scaled around getStart().
      Parameters:
        `height` - The new height of the rectangle (> 0).
      Returns:
        The current shape.

    - #### setHeight

          public Rect setHeight(processing.core.PVector center,
                                float height)

      Sets the height of the rectangle. The rectangle will be scaled around center.
      Parameters:
        `center` - The control point for the scaling.
        `height` - The new height of the rectangle (> 0).
      Returns:
        The current shape.

    - #### setX

          public Rect setX(float x)

      Description copied from interface: `RShape`
      Translates the shape to the given x-location. After the translation getStart().x will be equal to the given x.
      Specified by:
        `setX` in interface `RShape`
      Parameters:
        `x` - The new x-position of this shape.
      Returns:
        The current shape.

    - #### setY

          public Rect setY(float y)

      Description copied from interface: `RShape`
      Translates the shape to the given y-location. After the translation getStart().y will be equal to the given y.
      Specified by:
        `setY` in interface `RShape`
      Parameters:
        `y` - The new y-position of this shape.
      Returns:
        The current shape.

    - #### setLocation

          public Rect setLocation(float x,
                                  float y)

      Description copied from interface: `RShape`
      Translates the shape to the given location. After the translation getStart() will be equal to the given x, y.
      Specified by:
        `setLocation` in interface `RShape`
      Parameters:
        `x` - The new x-position of this shape.
        `y` - The new y-position of this shape.
      Returns:
        The current shape.

    - #### translate

          public Rect translate(float x,
                                float y)

      Description copied from interface: `RShape`
      Translates the coordinates by the given parameters x, y ( "moves the shape by x, y").
      Specified by:
        `translate` in interface `RShape`
      Parameters:
        `x` - The horizontal translation.
        `y` - The vertical translation.
      Returns:
        The current shape.

    - #### rotate

          public Rect rotate(float angle)

      Description copied from interface: `RShape`
      Turns the shape through the given angle. The rotation center will be the getStart() of this shape.
      Specified by:
        `rotate` in interface `RShape`
      Parameters:
        `angle` - The rotation angle.
      Returns:
        The current shape.

    - #### rotate

          public Rect rotate(processing.core.PVector rotationCenter,
                             float angle)

      Description copied from interface: `RShape`
      Turns the shape through the given angle. The rotation center will be the given location c.
      Specified by:
        `rotate` in interface `RShape`
      Parameters:
        `rotationCenter` - The rotation center.
        `angle` - The rotation angle.
      Returns:
        The current shape.

    - #### scale

          public Rect scale(float scale)

      Description copied from interface: `RShape`
      Scale the shape by the given scaling factor. For scaling factor s <1 the shape will shrink. For scaling factor s>1 the shape will expand. The scaling center will be the getStart() of this shape.
      Specified by:
        `scale` in interface `RShape`
      Parameters:
        `scale` - The scaling factor (> 0).
      Returns:
        The current shape.

    - #### scale

          public Rect scale(processing.core.PVector scaleCenter,
                            float scale)

      Description copied from interface: `RShape`
      Scale the shape by the given scaling factor. For scaling factor s <1 the shape will shrink. For scaling factor s>1 the shape will expand. The scaling center will be the given location c.
      Specified by:
        `scale` in interface `RShape`
      Parameters:
        `scaleCenter` - The scaling center.
        `scale` - The scaling factor (> 0).
      Returns:
        The current shape.

    - #### scale

          public Rect scale(processing.core.PVector scaleCenter,
                            float scaleX,
                            float scaleY)

      Scales the shape by the given scaling factors. For scaling factor < 1 the shape will shrink. For scaling factors > 1 the shape will expand. The scaling center will be the given location scaleCenter.
      Parameters:
        `scaleCenter` - The scaling center.
        `scaleX` - The horizontal scaling.
        `scaleY` - The vertical scaling.
      Returns:
        The current shape.

    - #### computeMinMax

          public void computeMinMax()

      Forces to calculate the bounds of this shape and store them. The bounds can be accessed by getBoundingBox().

    - #### draw

          public Rect draw()

      Description copied from interface: `RShape`
      Draws the shape-
      Specified by:
        `draw` in interface `RShape`
      Returns:
        The current shape.

    - #### toLines

          public Line[] toLines()

      Converts the rectangle to four lines. Does a real copy of the coordinates of this shape.
      Returns:
        The four lines.

    - #### getLines

          public Line[] getLines()

      Converts the rectangle to four lines. Does a shallow copy of the coordinates of this shape.
      Returns:
        The four lines.

    - #### toLineSegments

          public LineSegments toLineSegments()

      Converts the rectangle to LineSegments. Does a real copy of the coordinates of this shape.
      Returns:
        The LineSegments shape.

    - #### getLineSegments

          public LineSegments getLineSegments()

      Converts the rectangle to LineSegments. Does a shallow copy of the coordinates of this shape.
      Returns:
        The four lines.