## Public API Reference

- Main Page
- Modules
- Namespaces
- Classes
- Files
- Related Pages

- Alphabetical List
- Class List
- Class Hierarchy
- Class Members

# csPoly2D Class Reference
[Geometry utilities]

The following class represents a general 2D polygon. More...

`#include <csgeom/poly2d.h>`

List of all members.

## Public Member Functions

size_t | AddVertex (float x, float y)
| Add a vertex (2D) to the polygon.
size_t | AddVertex (const csVector2 &v)
| Add a vertex (2D) to the polygon.
bool | ClipAgainst (iClipper2D *view)
| Clipping routines.
void | ClipPlane (const csPlane2 &plane, csPoly2D &right) const
| This routine is similar to Intersect but it only returns the polygon on the 'right' (positive) side of the plane.
| csPoly2D (const csPoly2D &copy)
| Copy constructor.
| csPoly2D (size_t start_size=10)
| Make a new empty polygon.
void | ExtendConvex (const csPoly2D &other, size_t 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.
csVector2 * | GetFirst ()
| Get the first vertex.
csVector2 * | GetLast ()
| Get the last vertex.
float | GetSignedArea ()
| Calculate the signed area of this polygon.
csVector2 * | GetVertex (size_t i)
| Get the specified vertex.
size_t | GetVertexCount () const
| Get the number of vertices.
const csVector2 * | GetVertices () const
| Get the array with all vertices.
csVector2 * | GetVertices ()
| Get the array with all vertices.
bool | In (const csVector2 &v)
| Test if this vector is inside the polygon.
void | Intersect (const csPlane2 &plane, csPoly2D &left, csPoly2D &right) const
| Intersect this polygon with a given plane and return the two resulting polygons in left and right.
void | MakeEmpty ()
| Initialize the polygon to empty.
void | MakeRoom (size_t new_max)
| Make room for at least the specified number of vertices.
csPoly2D & | operator= (const csPoly2D &other)
| Assignment operator.
const csVector2 & | operator[] (size_t i) const
| Get the specified vertex.
csVector2 & | operator[] (size_t i)
| Get the specified vertex.
void | Random (size_t num, const csBox2 &max_bbox)
| Generate a random convex polygon with the specified number of vertices.
void | SetVertexCount (size_t n)
| Set the number of vertices.
void | SetVertices (csVector2 const *v, size_t num)
| Set all polygon vertices at once.
| ~csPoly2D ()
| Destructor.

## Static Public Member Functions

static bool | In (csVector2 *poly, size_t num_poly, const csVector2 &v)
| Test if a vector is inside the given polygon.

## Protected Attributes

size_t | max_vertices
size_t | num_vertices
csVector2 * | vertices
| The 2D vertices.

## Detailed Description

The following class represents a general 2D polygon.

Definition at line 40 of file poly2d.h.

## Constructor & Destructor Documentation

csPoly2D::csPoly2D | ( | size_t | start_size = `10` | ) |

| Make a new empty polygon.

csPoly2D::csPoly2D | ( | const csPoly2D & | copy | ) |

| Copy constructor.

csPoly2D::~csPoly2D | ( |  | ) |

| Destructor.

## Member Function Documentation

size_t csPoly2D::AddVertex | ( | float | x,
|  | float | y
| ) |

| Add a vertex (2D) to the polygon. Return index of added vertex.

size_t csPoly2D::AddVertex | ( | const csVector2 & | v | ) | `[inline]`

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

bool csPoly2D::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.

void csPoly2D::ClipPlane | ( | const csPlane2 & | plane,
|  | csPoly2D & | right
| ) | const

| This routine is similar to Intersect but it only returns the polygon on the 'right' (positive) side of the plane.

void csPoly2D::ExtendConvex | ( | const csPoly2D & | other,
|  | size_t | 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.

csVector2* csPoly2D::GetFirst | ( |  | ) | `[inline]`

| Get the first vertex. Definition at line 114 of file poly2d.h.

csVector2* csPoly2D::GetLast | ( |  | ) | `[inline]`

| Get the last vertex. Definition at line 120 of file poly2d.h.

float csPoly2D::GetSignedArea | ( |  | ) |

| Calculate the signed area of this polygon.

csVector2* csPoly2D::GetVertex | ( | size_t | i | ) | `[inline]`

| Get the specified vertex. Definition at line 87 of file poly2d.h.

size_t csPoly2D::GetVertexCount | ( |  | ) | const`[inline]`

| Get the number of vertices. Definition at line 72 of file poly2d.h.

const csVector2* csPoly2D::GetVertices | ( |  | ) | const`[inline]`

| Get the array with all vertices. Definition at line 82 of file poly2d.h.

csVector2* csPoly2D::GetVertices | ( |  | ) | `[inline]`

| Get the array with all vertices. Definition at line 77 of file poly2d.h.

static bool csPoly2D::In | ( | csVector2 * | poly,
|  | size_t | num_poly,
|  | const csVector2 & | v
| ) | `[static]`

| Test if a vector is inside the given polygon.

bool csPoly2D::In | ( | const csVector2 & | v | ) |

| Test if this vector is inside the polygon.

void csPoly2D::Intersect | ( | const csPlane2 & | plane,
|  | csPoly2D & | left,
|  | csPoly2D & | right
| ) | const

| 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.

void csPoly2D::MakeEmpty | ( |  | ) |

| Initialize the polygon to empty.

void csPoly2D::MakeRoom | ( | size_t | new_max | ) |

| Make room for at least the specified number of vertices.

csPoly2D& csPoly2D::operator= | ( | const csPoly2D & | other | ) |

| Assignment operator.

const csVector2& csPoly2D::operator[] | ( | size_t | i | ) | const`[inline]`

| Get the specified vertex. Definition at line 105 of file poly2d.h. References CS_ASSERT.

csVector2& csPoly2D::operator[] | ( | size_t | i | ) | `[inline]`

| Get the specified vertex. Definition at line 96 of file poly2d.h. References CS_ASSERT.

void csPoly2D::Random | ( | size_t | num,
|  | const 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.

void csPoly2D::SetVertexCount | ( | size_t | n | ) | `[inline]`

| Set the number of vertices. Definition at line 141 of file poly2d.h.

void csPoly2D::SetVertices | ( | csVector2 const * | v,
|  | size_t | num
| ) | `[inline]`

| Set all polygon vertices at once. Copies the array. Note! This doesn't update the bounding box! Definition at line 163 of file poly2d.h.

## Member Data Documentation

csVector2* csPoly2D::vertices `[protected]`

| The 2D vertices. Definition at line 44 of file poly2d.h.

The documentation for this class was generated from the following file:

- csgeom/poly2d.h