net.paulhertz.aifile
Class BezRectangle

java.lang.Object
  extended by net.paulhertz.aifile.DisplayComponent
      extended by net.paulhertz.aifile.BezShape
          extended by net.paulhertz.aifile.BezRectangle
All Implemented Interfaces:
ColorableINF, Visitable

public class BezRectangle
extends BezShape

Provides factory methods to create and operate on closed rectangular shapes. In methods that do not include a reference to a PApplet in the signature, the PApplet used for calls to the Processing environment is obtained from IgnoCodeLib, which must be correctly initialized in setup. If IgnoCodeLib does not have a reference to a PApplet, it throws a NullPointerException.


Nested Class Summary
 
Nested classes/interfaces inherited from class net.paulhertz.aifile.BezShape
BezShape.BezType
 
Field Summary
 
Fields inherited from class net.paulhertz.aifile.BezShape
bezType, CURVE_SEGMENT, KAPPA, LINE_SEGMENT
 
Method Summary
 boolean contains(BezRectangle r)
          Determines if this rectangle contains a specified rectangle.
static boolean contains(BezRectangle one, BezRectangle another)
          Determines if one rectangle contains another rectangle
 boolean containsPoint(float x, float y)
           
static boolean containsPoint(float x, float y, BezRectangle r)
           
 float getArea()
           
 float getBottom()
           
 Vertex2DINF getBottomRight()
           
 LineVertex getCenterPoint()
           
 float[] getCoords()
          Returns an array of all vertex coordinates.
 double getDiagonalLength()
           
 float getHeight()
           
 float getLeft()
           
 float getRight()
           
 float getTop()
           
 LineVertex getTopLeft()
           
 float getWidth()
           
 BezRectangle inset(float insetWidth, float insetHeight)
          Returns a rectangle inset by the specified values.
 BezRectangle intersect(BezRectangle r)
          Calculates the intersection of this rectangle with a supplied rectangle, returns the result as a rectangle.
 boolean isAligned()
           
 boolean isNeedsUpdate()
          convenience method to allow you to check the need for an update, which you set earlier
static double lerp(double a, double l, double h)
          Interpolates a value within a range.
static BezRectangle makeCenterWidthHeight(float xctr, float yctr, float width, float height)
           
static BezRectangle makeCenterWidthHeight(PApplet parent, float xctr, float yctr, float width, float height)
           
static BezRectangle makeLeftTopRightBottom(float left, float top, float right, float bottom)
           
static BezRectangle makeLeftTopRightBottom(PApplet parent, float left, float top, float right, float bottom)
           
static BezRectangle makeLeftTopWidthHeight(float left, float top, float width, float height)
           
static BezRectangle makeLeftTopWidthHeight(PApplet parent, float left, float top, float width, float height)
           
static BezRectangle makeRectangle(BezRectangle r)
           
static double map(double v, double vlo, double vhi, double dlo, double dhi)
          Maps a value from one range to another.
 Vertex2DINF map(Vertex2DINF vt1, BezRectangle r2)
           
static Vertex2DINF map(Vertex2DINF vt1, BezRectangle r1, BezRectangle r2)
           
 int overlapOutcode(BezRectangle lim)
           
static int overlapOutcode(BezRectangle targ, BezRectangle lim)
           
 boolean overlaps(BezRectangle r)
          Determines if this rectangle overlaps a specified rectangle
static boolean overlaps(BezRectangle one, BezRectangle another)
          Determines if one rectangle overlaps another rectangle
 BezRectangle pin(BezRectangle r)
          Clip the supplied rectangle to this rectangle; both rectangles should be aligned to x and y axes.
 void rotateShape(float theta)
          Rotates this shape around its center point.
 BezRectangle roundCoordinates()
           
 void scaleShape(float xyScale)
          Uniformly scales this shape around its center point.
 void scaleShape(float xScale, float yScale)
          Scales this shape around its center point.
 void scaleShape(float xyScale, float x0, float y0)
          Uniformly scales this shape around a given point.
 void scaleShape(float xScale, float yScale, float x0, float y0)
          Scales this shape around a given point.
 void setLeftTopRightBottom(float left, float top, float right, float bottom)
          Updates rectangle coordinates, width and height.
 void setLeftTopWidthHeight(float left, float top, float width, float height)
          Updates rectangle coordinates, width and height.
 void setNeedsUpdate(boolean needsUpdate)
          convenience method to allow you to flag the need for an update
 BezRectangle stick(BezRectangle r)
          Stick the nearest edge of this rectangle to limitRect, if it doesn't overlap.
 void transform(Matrix3 matx)
          Performs an affine geometric transformation on this shape using 3x3 matrix multiplication.
 void translateShape(float xTrans, float yTrans)
          Translates this shape.
 void update()
          Updates local tracking of rectangle top, left, bottom, right, width and height.
 BezRectangle wrap(BezRectangle r)
          Wrap supplied rectangle in the smallest rectangle that contains it and this rectangle; Both rectangles should be aligned.
 
Methods inherited from class net.paulhertz.aifile.BezShape
accept, accept, add, add, append, append, append, asPolygon, asPolygon, asPolygon, asPolygon, bezCircle, bezCurve, bezCurveShape, bezEllipse, bezLine, bezMultiCurve, bezMultiLine, bezPoly, bezRectangle, bezRegularPoly, bezTriangle, bezTriangle, bezType, bounds, bounds, boundsRect, calculateCenter, centerVertex, children, clone, containsPoint, curveIterator, curves, curvesCopy, draw, draw, drawQuick, fillColor, fillOpacity, get, getAnchorCenter, getBoundsCenter, getCtm, getGeoCenter, getMatrix, hasFill, hasStroke, isClosed, isTerminal, iterator, moveTo, polySize, polySize, polySteps, remove, rotateShape, setBezType, setCenter, setCenter, setCenter, setColors, setCtm, setCtm, setCtm, setCurves, setFillColor, setFillOpacity, setHasFill, setHasStroke, setIsClosed, setNoFill, setNoStroke, setPolySteps, setStartPoint, setStartPoint, setStartPoint, setStrokeColor, setStrokeOpacity, setUseTransparency, setWeight, setX, setY, startVertex, startVertexArray, strokeColor, strokeOpacity, transform, transformShape, useTransparency, weight, write, write, x, xcoords, xcoords, xctr, y, ycoords, ycoords, yctr
 
Methods inherited from class net.paulhertz.aifile.DisplayComponent
hide, id, isLocked, isVisible, parentComponent, setLocked, setParentComponent, setVisible, show
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

makeLeftTopWidthHeight

public static BezRectangle makeLeftTopWidthHeight(PApplet parent,
                                                  float left,
                                                  float top,
                                                  float width,
                                                  float height)

makeLeftTopWidthHeight

public static BezRectangle makeLeftTopWidthHeight(float left,
                                                  float top,
                                                  float width,
                                                  float height)

makeCenterWidthHeight

public static BezRectangle makeCenterWidthHeight(PApplet parent,
                                                 float xctr,
                                                 float yctr,
                                                 float width,
                                                 float height)

makeCenterWidthHeight

public static BezRectangle makeCenterWidthHeight(float xctr,
                                                 float yctr,
                                                 float width,
                                                 float height)

makeLeftTopRightBottom

public static BezRectangle makeLeftTopRightBottom(PApplet parent,
                                                  float left,
                                                  float top,
                                                  float right,
                                                  float bottom)

makeLeftTopRightBottom

public static BezRectangle makeLeftTopRightBottom(float left,
                                                  float top,
                                                  float right,
                                                  float bottom)

makeRectangle

public static BezRectangle makeRectangle(BezRectangle r)

setLeftTopWidthHeight

public void setLeftTopWidthHeight(float left,
                                  float top,
                                  float width,
                                  float height)
Updates rectangle coordinates, width and height.

Parameters:
left -
top -
width -
height -

setLeftTopRightBottom

public void setLeftTopRightBottom(float left,
                                  float top,
                                  float right,
                                  float bottom)
Updates rectangle coordinates, width and height.

Parameters:
left -
top -
right -
bottom -

getCoords

public float[] getCoords()
Description copied from class: BezShape
Returns an array of all vertex coordinates. A LineVertex adds two values to the array and a BezVertex adds six values (two control points and an anchor point). There is no inherent way to distinguish which values represent control points and which represent anchor points.

Overrides:
getCoords in class BezShape
Returns:
an array of float generated from the vertices of this shape.
See Also:
BezShape.asPolygon(PApplet, int).

getLeft

public float getLeft()

getTop

public float getTop()

getRight

public float getRight()

getBottom

public float getBottom()

getWidth

public float getWidth()

getHeight

public float getHeight()

getTopLeft

public LineVertex getTopLeft()

getBottomRight

public Vertex2DINF getBottomRight()

getCenterPoint

public LineVertex getCenterPoint()

getArea

public float getArea()

getDiagonalLength

public double getDiagonalLength()

contains

public static boolean contains(BezRectangle one,
                               BezRectangle another)
Determines if one rectangle contains another rectangle

Parameters:
one - the possibly containing rectangle
another - the rectangle to check for containment
Returns:
true if one rectangle contains another, false otherwise

contains

public boolean contains(BezRectangle r)
Determines if this rectangle contains a specified rectangle.

Parameters:
r - the rectangle to check
Returns:
true if this rectangle contains r, false otherwise

overlaps

public static boolean overlaps(BezRectangle one,
                               BezRectangle another)
Determines if one rectangle overlaps another rectangle

Parameters:
one - one rectangle to check for overlap
another - another rectangle to check for overlap
Returns:
true if one rectangle overlaps another, false otherwise

overlaps

public boolean overlaps(BezRectangle r)
Determines if this rectangle overlaps a specified rectangle

Parameters:
r - the rectangle to check against this one
Returns:
true if this rectangle overlaps r, false otherwise

overlapOutcode

public int overlapOutcode(BezRectangle lim)
Parameters:
lim - the limiting rectangle
Returns:
outcode indicating relation of this rectangle to lim as follows: | | 1 | 4 | 7 ___|___|___ | | 2 | 5 | 8 ___|___|___ | | 3 | 6 | 9 | | where 5 indicates the two rectangles overlap, all other outcodes indicate no overlap with this rectangle located in one of 8 sectors, as shown.

overlapOutcode

public static int overlapOutcode(BezRectangle targ,
                                 BezRectangle lim)
Parameters:
targ - rectangle to test against a limiting rectangle
lim - the limiting rectangle
Returns:
outcode indicating relation of two rectangles as follows: | | 1 | 4 | 7 ___|___|___ | | 2 | 5 | 8 ___|___|___ | | 3 | 6 | 9 | | where 5 indicates the two rectangles overlap, all other outcodes indicate no overlap with targ located in one of 8 sectors, as shown.

containsPoint

public static boolean containsPoint(float x,
                                    float y,
                                    BezRectangle r)
Parameters:
x - x-coordinate of point to test
y - y-coordinate of point to test
r - rectangle to test
Returns:
true if r contains the specified point

containsPoint

public boolean containsPoint(float x,
                             float y)
Overrides:
containsPoint in class BezShape

update

public void update()
Updates local tracking of rectangle top, left, bottom, right, width and height. Sets needsUpdate to false. If the BezShape.bounds(PApplet) of this BezRectangle no longer corresponds to the top, left, bottom and right, isAligned will be set to false to flag that the rectangle has been transformed out of alignment with the x and y axes of the world system. Call after any geometric transformation of the points of this rectangle by your code. Methods in this class that change geometry will call update for you.


isNeedsUpdate

public boolean isNeedsUpdate()
convenience method to allow you to check the need for an update, which you set earlier

Returns:
the needsUpdate

setNeedsUpdate

public void setNeedsUpdate(boolean needsUpdate)
convenience method to allow you to flag the need for an update

Parameters:
needsUpdate - the needsUpdate to set

isAligned

public boolean isAligned()
Returns:
the isAligned

rotateShape

public void rotateShape(float theta)
Description copied from class: BezShape
Rotates this shape around its center point. You can change the center point by calling setCenter or calculateCenter. Sets xcoords and ycoords arrays to null: they will have to be recalculated after a transform, which will be done through lazy initialization when xcoords() or ycoords() are called.

Overrides:
rotateShape in class BezShape
Parameters:
theta - degrees to rotate (in radians) TODO for theta very near PI, 0, or TWO_PI, insure correct rotation.

scaleShape

public void scaleShape(float xScale,
                       float yScale)
Description copied from class: BezShape
Scales this shape around its center point. You can change the center point by calling setCenter or calculateCenter. Sets xcoords and ycoords arrays to null: they will have to be recalculated after a transform, which will be done through lazy initialization when xcoords() or ycoords() are called.

Overrides:
scaleShape in class BezShape
Parameters:
xScale - scaling on x-axis
yScale - scaling on y-axis

scaleShape

public void scaleShape(float xyScale)
Description copied from class: BezShape
Uniformly scales this shape around its center point. You can change the center point by calling setCenter or calculateCenter. Sets xcoords and ycoords arrays to null: they will have to be recalculated after a transform, which will be done through lazy initialization when xcoords() or ycoords() are called.

Overrides:
scaleShape in class BezShape
Parameters:
xyScale - uniform scaling on x-axis and y-axis

scaleShape

public void scaleShape(float xScale,
                       float yScale,
                       float x0,
                       float y0)
Description copied from class: BezShape
Scales this shape around a given point. Sets xcoords and ycoords arrays to null: they will have to be recalculated after a transform, which will be done through lazy initialization when xcoords() or ycoords() are called.

Overrides:
scaleShape in class BezShape
Parameters:
xScale - scaling on x-axis
yScale - scaling on y-axis

scaleShape

public void scaleShape(float xyScale,
                       float x0,
                       float y0)
Description copied from class: BezShape
Uniformly scales this shape around a given point.

Overrides:
scaleShape in class BezShape
Parameters:
xyScale - uniform scaling on x-axis and y-axis

transform

public void transform(Matrix3 matx)
Description copied from class: BezShape
Performs an affine geometric transformation on this shape using 3x3 matrix multiplication. Sets xcoords and ycoords arrays to null: they will have to be recalculated after a transform, which will be done through lazy initialization when xcoords() or ycoords() are called.

Overrides:
transform in class BezShape
Parameters:
matx - a 3x3 matrix see Matrix3 class for methods of loading transforms

translateShape

public void translateShape(float xTrans,
                           float yTrans)
Description copied from class: BezShape
Translates this shape. Moves center point, calculating it if necessary. Sets xcoords and ycoords arrays to null: they will have to be recalculated after a transform, which will be done through lazy initialization when xcoords() or ycoords() are called.

Overrides:
translateShape in class BezShape
Parameters:
xTrans - translation on x-axis
yTrans - translation on y-axis

roundCoordinates

public BezRectangle roundCoordinates()
Returns:
a BezRectangle with coordinates rounded to the nearest integer value

inset

public BezRectangle inset(float insetWidth,
                          float insetHeight)
Returns a rectangle inset by the specified values. Negative values will outset the new rectangle with respect to this rectangle. Works with aligned rectangles.

Parameters:
insetWidth -
insetHeight -
Returns:
a new BezRectangle inset (or outset) from the original.

intersect

public BezRectangle intersect(BezRectangle r)
Calculates the intersection of this rectangle with a supplied rectangle, returns the result as a rectangle. Results will not be accurate unless both rectangles are aligned with x and y axes, i.e., isAligned == true.

Parameters:
r -
Returns:
a new rectangle created by intersection of this rectangle with the supplied rectangle.

pin

public BezRectangle pin(BezRectangle r)
Clip the supplied rectangle to this rectangle; both rectangles should be aligned to x and y axes.

Parameters:
r - rectangle to clip
Returns:
a new rectangle clipped to the bounds of this rectangle.

stick

public BezRectangle stick(BezRectangle r)
Stick the nearest edge of this rectangle to limitRect, if it doesn't overlap.

Parameters:
r - the "sticky" rectangle
Returns:
a rectangle with the same dimensions as this, stuck to limitRect.

wrap

public BezRectangle wrap(BezRectangle r)
Wrap supplied rectangle in the smallest rectangle that contains it and this rectangle; Both rectangles should be aligned.

Parameters:
r -
Returns:
a new rectangle that contains both this and the supplied rectangle.

lerp

public static double lerp(double a,
                          double l,
                          double h)
Interpolates a value within a range. linear interpolation from l (when a=0) to h (when a=1) (equal to (a * h) + (1 - a) * l)


map

public static double map(double v,
                         double vlo,
                         double vhi,
                         double dlo,
                         double dhi)
Maps a value from one range to another.

Parameters:
v - value to interpolage
vlo - low value of source range
vhi - high value of source range
dlo - low value of destination range
dhi - high value of destination range
Returns:
value linearly interpolated from source range to destination range

map

public Vertex2DINF map(Vertex2DINF vt1,
                       BezRectangle r2)
Parameters:
vt1 - a LineVertex for mapping from this rectangle to another
r2 - the destination rectangle
Returns:
a LineVertex mapped to the destination rectangle

map

public static Vertex2DINF map(Vertex2DINF vt1,
                              BezRectangle r1,
                              BezRectangle r2)
Parameters:
vt1 - a LineVertex for interpolation
r1 - a source rectangle for mapping
r2 - a destination rectangle for mapping
Returns:
a LineVertex mapped to the destination rectangle


Processing library IgnoCodeLib by Paul Hertz. (C) 2013