crystalspace.jbind.impl.csgeom.box
Class csBox2

java.lang.Object
  extended bycrystalspace.jbind.impl.csNativeObject
      extended bycrystalspace.jbind.impl.csgeom.box.csBox2
All Implemented Interfaces:
iPointer

public class csBox2
extends csNativeObject

A bounding box in 2D space. In order to operate correctly, this bounding box assumes that all values entered or compared against lie within the range (-CS_BOUNDINGBOX_MAXVALUE, CS_BOUNDINGBOX_MAXVALUE). It is not recommended to use points outside of this range.

Author:
Java wrapper - Quentin Anciaux, c++ version - http://crystal.sourceforge.net/docs/online/pubapi/classcsBox2.php

Field Summary
 
Fields inherited from class crystalspace.jbind.impl.csNativeObject
ImplFactory, nPointer
 
Constructor Summary
csBox2()
          Initialize this box to empty.
csBox2(csVector2 v)
          Initialize this box with one point.
csBox2(float x1, float y1, float x2, float y2)
          Initialize this box with the given values.
csBox2(iPointer nPointer)
           
 
Method Summary
 csBox2 add(csBox2 box)
          Compute the union of two bounding boxes.
static csBox2 add(csBox2 box1, csBox2 box2)
          Compute the union of two bounding boxes.
static csBox2 add(csBox2 box, csVector2 point)
          Compute the union of a bounding box and a point.
 csBox2 add(csVector2 point)
          Compute the union of a point with this bounding box.
 void addBoundingVertex(csVector2 v)
          Add a new vertex and recalculate the bounding box.
 void addBoundingVertex(float x, float y)
          Add a new vertex and recalculate the bounding box.
 void addBoundingVertexSmart(csVector2 v)
          Add a new vertex and recalculate the bounding box.
 void addBoundingVertexSmart(float x, float y)
          Add a new vertex and recalculate the bounding box.
 boolean contains(csBox2 box)
          Test if this box contains the other box.
 boolean empty()
          Test if this box is empty.
static boolean equals(csBox2 box1, csBox2 box2)
          Tests if two bounding boxes are equal.
 csVector2 getCenter()
          Get the center of this box.
 csVector2 getCorner(int corner)
          Return every corner of this bounding box from 0 to 3.
 csSegment2 getEdge(int edge)
          Return every edge (segment); of this bounding box from 0 to 7 (CS_BOX_EDGE_xy_Xy etc.);.
 void getEdge(int edge, csSegment2 e)
          Return every edge (segment); of this bounding box from 0 to 7 (CS_BOX_EDGE_xy_Xy etc.);.
 int[] getEdgeInfo(int edge)
          Given an edge index (CS_BOX_EDGE_xy_Xy etc.); return the two vertices (index CS_BOX_CORNER_xy etc.);.
static boolean greater(csBox2 box1, csBox2 box2)
          Tests if box1 is a superset of box2.
 boolean in(csVector2 v)
          Test if the given coordinate is in this box.
 boolean in(float x, float y)
          Test if the given coordinate is in this box.
 boolean intersect(csVector2Array poly)
          Test if a polygon if visible in the box.
 boolean intersect(csVector2 minbox, csVector2 maxbox, csVector2Array poly)
          Test if a polygon if visible in the box.
 boolean intersect(float minx, float miny, float maxx, float maxy, csVector2Array poly)
          Test if a polygon if visible in the box.
protected  boolean isNativePointerValidSafe(long nPointer)
           
static boolean less(csBox2 box1, csBox2 box2)
          Tests if box1 is a subset of box2.
static boolean less(csVector2 point, csBox2 box)
          Tests if a point is contained in a box.
 csVector2 max()
          Get the 2d vector of maximum (x, y); values.
 float max(int idx)
          Get Max component for 0 (x); or 1 (y);.
 float maxX()
          Get the maximum X value of the box.
 float maxY()
          Get the maximum Y value of the box.
 csVector2 min()
          Get the 2d vector of minimum (x, y); values.
 float min(int idx)
          Get Min component for 0 (x); or 1 (y);.
 float minX()
          Get the minimum X value of the box.
 float minY()
          Get the minimum Y value of the box.
 csBox2 mul(csBox2 box)
          Compute the intersection of two bounding boxes.
static csBox2 mul(csBox2 box1, csBox2 box2)
          Compute the intersection of two bounding boxes.
protected  void nDelete(long pointer)
           
static boolean nEquals(csBox2 box1, csBox2 box2)
          Tests if two bounding boxes are unequal.
 boolean overlap(csBox2 box)
          Test if this box overlaps with the given box.
 void set(csVector2 bmin, csVector2 bmax)
          Sets the bounds of the box with the given values.
 void set(float x1, float y1, float x2, float y2)
          Sets the bounds of the box with the given values.
 void setCenter(csVector2 c)
          Set the center of this box.
 void setMax(int idx, float val)
          Set Max component for 0 (x); or 1 (y);.
 void setMin(int idx, float val)
          Set Min component for 0 (x); or 1 (y);.
 void setSize(csVector2 s)
          Set the size of the box but keep the center intact.
 float squaredOriginDist()
          Calculate the squared distance between (0,0); and the box This routine is extremely efficient.
 float squaredOriginMaxDist()
          Calculate the squared distance between (0,0); and the point on the box which is furthest away from (0,0);.
 void startBoundingBox()
          Initialize this box to empty.
 void startBoundingBox(csVector2 v)
          Initialize this box to one vertex.
 void startBoundingBox(float x, float y)
          Same but given some coordinates.
 boolean testIntersect(csBox2 box)
          Test if the two boxes have an intersection.
 
Methods inherited from class crystalspace.jbind.impl.csNativeObject
changePointer, equals, finalize, getPointer, getPointer, getPointerArray, hashCode, isMemoryOwner, isNativePointerValid, newNativeObject, setMemoryOwner, toString
 
Methods inherited from class java.lang.Object
clone, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

csBox2

public csBox2(iPointer nPointer)
Parameters:
nPointer -

csBox2

public csBox2()
Initialize this box to empty. Definition at line 331 of file box.h. References CS_BOUNDINGBOX_MAXVALUE.


csBox2

public csBox2(csVector2 v)
Initialize this box with one point. Definition at line 335 of file box.h.

Parameters:
v -

csBox2

public csBox2(float x1,
              float y1,
              float x2,
              float y2)
Initialize this box with the given values. Definition at line 338 of file box.h. References Empty();, and StartBoundingBox();. Member Function Documentation

Parameters:
x1 -
y1 -
x2 -
y2 -
Method Detail

nDelete

protected void nDelete(long pointer)
Specified by:
nDelete in class csNativeObject
See Also:
csNativeObject.nDelete(long)

isNativePointerValidSafe

protected boolean isNativePointerValidSafe(long nPointer)
Specified by:
isNativePointerValidSafe in class csNativeObject
See Also:
crystalspace.jbind.impl.csNativeObject#isNativePointerValidSafe()

addBoundingVertex

public final void addBoundingVertex(csVector2 v)
Add a new vertex and recalculate the bounding box. Definition at line 290 of file box.h. References AddBoundingVertex();, csVector2::x, and csVector2::y.

Parameters:
v -

addBoundingVertex

public final void addBoundingVertex(float x,
                                    float y)
Add a new vertex and recalculate the bounding box. Definition at line 283 of file box.h. References csVector2::x, and csVector2::y. Referenced by AddBoundingVertex();.

Parameters:
x -
y -

addBoundingVertexSmart

public final void addBoundingVertexSmart(csVector2 v)
Add a new vertex and recalculate the bounding box. This version is a little more optimal. It assumes however that at least one point has been added to the bounding box. Definition at line 311 of file box.h. References AddBoundingVertexSmart();, csVector2::x, and csVector2::y.

Parameters:
v -

addBoundingVertexSmart

public final void addBoundingVertexSmart(float x,
                                         float y)
Add a new vertex and recalculate the bounding box. This version is a little more optimal. It assumes however that at least one point has been added to the bounding box. Definition at line 300 of file box.h. References csVector2::x, and csVector2::y. Referenced by AddBoundingVertexSmart();.

Parameters:
x -
y -

contains

public final boolean contains(csBox2 box)
Test if this box contains the other box. Definition at line 234 of file box.h. References maxbox, minbox, csVector2::x, and csVector2::y.

Parameters:
box -
Returns:

empty

public final boolean empty()
Test if this box is empty. Definition at line 241 of file box.h. References csVector2::x, and csVector2::y. Referenced by csBox2();.

Returns:

getCenter

public final csVector2 getCenter()
Get the center of this box. Definition at line 137 of file box.h.

Returns:

getCorner

public final csVector2 getCorner(int corner)
Return every corner of this bounding box from 0 to 3. This contrasts with Min(); and Max(); because those are only the min and max corners. Corner 0 = xy, 1 = xY, 2 = Xy, 3 = XY. Use CS_BOX_CORNER_xy etc. defines. CS_BOX_CENTER2 also works.

Parameters:
corner -
Returns:

getEdge

public final void getEdge(int edge,
                          csSegment2 e)
Return every edge (segment); of this bounding box from 0 to 7 (CS_BOX_EDGE_xy_Xy etc.);. Definition at line 173 of file box.h. References csSegment2::SetEnd();, and csSegment2::SetStart();.

Parameters:
edge -
e -

getEdge

public final csSegment2 getEdge(int edge)
Return every edge (segment); of this bounding box from 0 to 7 (CS_BOX_EDGE_xy_Xy etc.);. Definition at line 164 of file box.h.

Parameters:
edge -
Returns:

getEdgeInfo

public final int[] getEdgeInfo(int edge)
Given an edge index (CS_BOX_EDGE_xy_Xy etc.); return the two vertices (index CS_BOX_CORNER_xy etc.);. Definition at line 154 of file box.h.

Parameters:
edge -
Returns:

in

public final boolean in(csVector2 v)
Test if the given coordinate is in this box. Definition at line 220 of file box.h. References In();, csVector2::x, and csVector2::y.

Parameters:
v -
Returns:

in

public final boolean in(float x,
                        float y)
Test if the given coordinate is in this box. Definition at line 212 of file box.h. References csVector2::x, and csVector2::y. Referenced by In();, and csBoxClipper::IsInside();.

Parameters:
x -
y -
Returns:

intersect

public final boolean intersect(csVector2Array poly)
Test if a polygon if visible in the box. This function does not test the case where the box is fully contained in the polygon. But all other cases are tested. Definition at line 206 of file box.h. References Intersect();.

Parameters:
poly -
Returns:

intersect

public final boolean intersect(csVector2 minbox,
                               csVector2 maxbox,
                               csVector2Array poly)
Test if a polygon if visible in the box. This function does not test the case where the box is fully contained in the polygon. But all other cases are tested. Definition at line 194 of file box.h. References Intersect();, csVector2::x, and csVector2::y.

Parameters:
minbox -
maxbox -
poly -
Returns:

intersect

public final boolean intersect(float minx,
                               float miny,
                               float maxx,
                               float maxy,
                               csVector2Array poly)
Test if a polygon if visible in the box. This function does not test the case where the box is fully contained in the polygon. But all other cases are tested. Referenced by Intersect();.

Parameters:
minx -
miny -
maxx -
maxy -
poly -
Returns:

max

public final csVector2 max()
Get the 2d vector of maximum (x, y); values. Definition at line 122 of file box.h.

Returns:

max

public final float max(int idx)
Get Max component for 0 (x); or 1 (y);. Definition at line 118 of file box.h. References csVector2::x, and csVector2::y.

Parameters:
idx -
Returns:

maxX

public final float maxX()
Get the maximum X value of the box. Definition at line 112 of file box.h. References csVector2::x.

Returns:

maxY

public final float maxY()
Get the maximum Y value of the box. Definition at line 114 of file box.h. References csVector2::y.

Returns:

min

public final csVector2 min()
Get the 2d vector of minimum (x, y); values. Definition at line 120 of file box.h.

Returns:

min

public final float min(int idx)
Get Min component for 0 (x); or 1 (y);. Definition at line 116 of file box.h. References csVector2::x, and csVector2::y.

Parameters:
idx -
Returns:

minX

public final float minX()
Get the minimum X value of the box. Definition at line 108 of file box.h. References csVector2::x.

Returns:

minY

public final float minY()
Get the minimum Y value of the box. Definition at line 110 of file box.h. References csVector2::y.

Returns:

mul

public final csBox2 mul(csBox2 box)
Compute the intersection of two bounding boxes.

Parameters:
box -
Returns:

add

public final csBox2 add(csVector2 point)
Compute the union of a point with this bounding box.

Parameters:
point -
Returns:

add

public final csBox2 add(csBox2 box)
Compute the union of two bounding boxes.

Parameters:
box -
Returns:

overlap

public final boolean overlap(csBox2 box)
Test if this box overlaps with the given box. Definition at line 226 of file box.h. References maxbox, minbox, csVector2::x, and csVector2::y.

Parameters:
box -
Returns:

set

public final void set(float x1,
                      float y1,
                      float x2,
                      float y2)
Sets the bounds of the box with the given values. Definition at line 350 of file box.h. References StartBoundingBox();, csVector2::x, and csVector2::y.

Parameters:
x1 -
y1 -
x2 -
y2 -

set

public final void set(csVector2 bmin,
                      csVector2 bmax)
Sets the bounds of the box with the given values. Definition at line 343 of file box.h.

Parameters:
bmin -
bmax -

setCenter

public final void setCenter(csVector2 c)
Set the center of this box. This will not change the size of the box but just relocate the center.

Parameters:
c -

setMax

public final void setMax(int idx,
                         float val)
Set Max component for 0 (x); or 1 (y);. Definition at line 364 of file box.h. References csVector2::x, and csVector2::y.

Parameters:
idx -
val -

setMin

public final void setMin(int idx,
                         float val)
Set Min component for 0 (x); or 1 (y);. Definition at line 357 of file box.h. References csVector2::x, and csVector2::y.

Parameters:
idx -
val -

setSize

public final void setSize(csVector2 s)
Set the size of the box but keep the center intact.

Parameters:
s -

squaredOriginDist

public final float squaredOriginDist()
Calculate the squared distance between (0,0); and the box This routine is extremely efficient.

Returns:

squaredOriginMaxDist

public final float squaredOriginMaxDist()
Calculate the squared distance between (0,0); and the point on the box which is furthest away from (0,0);. This routine is extremely efficient.

Returns:

startBoundingBox

public final void startBoundingBox(float x,
                                   float y)
Same but given some coordinates. Definition at line 276 of file box.h. References csVector2::x, and csVector2::y.

Parameters:
x -
y -

startBoundingBox

public final void startBoundingBox(csVector2 v)
Initialize this box to one vertex. Definition at line 269 of file box.h.

Parameters:
v -

startBoundingBox

public final void startBoundingBox()
Initialize this box to empty. Definition at line 262 of file box.h. References CS_BOUNDINGBOX_MAXVALUE, csVector2::x, and csVector2::y. Referenced by csBox2();, and Set();.


testIntersect

public final boolean testIntersect(csBox2 box)
Test if the two boxes have an intersection.

Parameters:
box -
Returns:

mul

public static final csBox2 mul(csBox2 box1,
                               csBox2 box2)
Compute the intersection of two bounding boxes.

Parameters:
box1 -
box2 -
Returns:

nEquals

public static final boolean nEquals(csBox2 box1,
                                    csBox2 box2)
Tests if two bounding boxes are unequal.

Parameters:
box1 -
box2 -
Returns:

add

public static final csBox2 add(csBox2 box,
                               csVector2 point)
Compute the union of a bounding box and a point.

Parameters:
box -
point -
Returns:

add

public static final csBox2 add(csBox2 box1,
                               csBox2 box2)
Compute the union of two bounding boxes.

Parameters:
box1 -
box2 -
Returns:

less

public static final boolean less(csVector2 point,
                                 csBox2 box)
Tests if a point is contained in a box.

Parameters:
point -
box -
Returns:

less

public static final boolean less(csBox2 box1,
                                 csBox2 box2)
Tests if box1 is a subset of box2.

Parameters:
box1 -
box2 -
Returns:

equals

public static final boolean equals(csBox2 box1,
                                   csBox2 box2)
Tests if two bounding boxes are equal.

Parameters:
box1 -
box2 -
Returns:

greater

public static final boolean greater(csBox2 box1,
                                    csBox2 box2)
Tests if box1 is a superset of box2.

Parameters:
box1 -
box2 -
Returns: