crystalspace.jbind.impl.csgeom.poly2d
Class csPoly2D

java.lang.Object
  extended bycrystalspace.jbind.impl.csNativeObject
      extended bycrystalspace.jbind.impl.csgeom.poly2d.csPoly2D
All Implemented Interfaces:
iPointer

public class csPoly2D
extends csNativeObject

The following class represents a general 2D polygon with a bounding box.

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

Field Summary
 
Fields inherited from class crystalspace.jbind.impl.csNativeObject
ImplFactory, nPointer
 
Constructor Summary
csPoly2D()
          Make a new empty polygon.
csPoly2D(csPoly2D copy)
          Copy constructor.
csPoly2D(int start_size)
          Make a new empty polygon.
csPoly2D(iPointer nPointer)
           
 
Method Summary
 int addVertex(csVector2 v)
          Add a vertex (2D) to the polygon.
 int addVertex(float x, float y)
          Add a vertex (2D) to the polygon.
 boolean clipAgainst(iClipper2D view)
          Clipping routines.
 void clipPlane(csPlane2 plane, csPoly2D right)
          This routine is similar to Intersect but it only returns the polygon on the 'right' (positive) side of the plane.
 void extendConvex(csPoly2D other, int this_edge)
          Extend this polygon with another polygon so that the resulting polygon is: (a) still convex, (b) fully contains this polygon, and (c) contains as much as possible of the other polgon.
 csBox2 getBoundingBox()
          Get the bounding box (in 2D space) for this polygon.
 csVector2 getFirst()
          Get the first vertex.
 csVector2 getLast()
          Get the last vertex.
 float getSignedArea()
          Calculate the signed area of this polygon.
 csVector2 getVertex(int i)
          Get the specified vertex.
 int getVertexCount()
          Get the number of vertices.
 csVector2Array getVertices()
          Get the array with all vertices.
 boolean in(csVector2 v)
          Test if this vector is inside the polygon.
static boolean in(csVector2Array poly, csVector2 v)
          Test if a vector is inside the given polygon.
 void intersect(csPlane2 plane, csPoly2D left, csPoly2D right)
          Intersect this polygon with a given plane and return the two resulting polygons in left and right.
protected  boolean isNativePointerValidSafe(long nPointer)
           
 csVector2 item(int i)
          Get the specified vertex.
 void makeEmpty()
          Initialize the polygon to empty.
 void makeRoom(int new_max)
          Make room for at least the specified number of vertices.
protected  void nDelete(long pointer)
           
 void random(int num, csBox2 max_bbox)
          Generate a random convex polygon with the specified number of vertices.
 csPoly2D set(csPoly2D other)
          Assignment operator.
 void setVertexCount(int n)
          Set the number of vertices.
 void setVertices(csVector2Array v)
          Set all polygon vertices at once.
 void updateBoundingBox()
          Update the bounding box (useful after SetVertices).
 
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

csPoly2D

public csPoly2D(iPointer nPointer)
Parameters:
nPointer -

csPoly2D

public csPoly2D()
Make a new empty polygon.


csPoly2D

public csPoly2D(int start_size)
Make a new empty polygon.

Parameters:
start_size -

csPoly2D

public csPoly2D(csPoly2D copy)
Copy constructor.

Parameters:
copy -
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()

addVertex

public int addVertex(float x,
                     float y)
Add a vertex (2D) to the polygon. Return index of added vertex.

Parameters:
x -
y -
Returns:

addVertex

public int addVertex(csVector2 v)
Add a vertex (2D) to the polygon. Return index of added vertex. Definition at line 157 of file poly2d.h. References csVector2::x, and csVector2::y.

Parameters:
v -
Returns:

clipAgainst

public boolean clipAgainst(iClipper2D view)
Clipping routines. They return false if the resulting polygon is not visible for some reason. Note that these routines must not be called if the polygon is not visible. These routines will not check that. Note that these routines will put the resulting clipped 2D polygon in place of the original 2D polygon.

Parameters:
view -
Returns:

clipPlane

public void clipPlane(csPlane2 plane,
                      csPoly2D right)
This routine is similar to Intersect but it only returns the polygon on the 'right' (positive) side of the plane.

Parameters:
plane -
right -

extendConvex

public void extendConvex(csPoly2D other,
                         int this_edge)
Extend this polygon with another polygon so that the resulting polygon is: (a) still convex, (b) fully contains this polygon, and (c) contains as much as possible of the other polgon. 'this_edge' is the index of the common edge for this polygon. Edges are indexed with 0 being the edge from 0 to 1 and n-1 being the edge from n-1 to 0.

Parameters:
other -
this_edge -

getBoundingBox

public csBox2 getBoundingBox()
Get the bounding box (in 2D space) for this polygon. Definition at line 176 of file poly2d.h.

Returns:

getFirst

public csVector2 getFirst()
Get the first vertex. Definition at line 120 of file poly2d.h.

Returns:

getLast

public csVector2 getLast()
Get the last vertex. Definition at line 126 of file poly2d.h.

Returns:

getSignedArea

public float getSignedArea()
Calculate the signed area of this polygon.

Returns:

getVertex

public csVector2 getVertex(int i)
Get the specified vertex. Definition at line 93 of file poly2d.h.

Parameters:
i -
Returns:

getVertexCount

public int getVertexCount()
Get the number of vertices. Definition at line 78 of file poly2d.h.

Returns:

getVertices

public csVector2Array getVertices()
Get the array with all vertices. Definition at line 88 of file poly2d.h.

Returns:

in

public static boolean in(csVector2Array poly,
                         csVector2 v)
Test if a vector is inside the given polygon.

Parameters:
poly -
v -
Returns:

in

public boolean in(csVector2 v)
Test if this vector is inside the polygon.

Parameters:
v -
Returns:

intersect

public void intersect(csPlane2 plane,
                      csPoly2D left,
                      csPoly2D right)
Intersect this polygon with a given plane and return the two resulting polygons in left and right. This version is robust. If one of the edges of this polygon happens to be on the same plane as 'plane' then the edge will go to the polygon which already has most edges. i.e. you will not get degenerate polygons.

Parameters:
plane -
left -
right -

makeEmpty

public void makeEmpty()
Initialize the polygon to empty.


makeRoom

public void makeRoom(int new_max)
Make room for at least the specified number of vertices. Referenced by SetVertexCount(), and SetVertices().

Parameters:
new_max -

set

public csPoly2D set(csPoly2D other)
Assignment operator.

Parameters:
other -
Returns:

item

public csVector2 item(int i)
Get the specified vertex. Definition at line 111 of file poly2d.h.

Parameters:
i -
Returns:

random

public void random(int num,
                   csBox2 max_bbox)
Generate a random convex polygon with the specified number of vertices. The polygon will be inside the given bounding box. @@ Currently only triangles are supported.

Parameters:
num -
max_bbox -

setVertexCount

public void setVertexCount(int n)
Set the number of vertices. Definition at line 147 of file poly2d.h. References MakeRoom().

Parameters:
n -

setVertices

public void setVertices(csVector2Array v)
Set all polygon vertices at once. Copies the array. Note! This doesn't update the bounding box! Definition at line 169 of file poly2d.h. References MakeRoom().

Parameters:
v -

updateBoundingBox

public void updateBoundingBox()
Update the bounding box (useful after SetVertices).