TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
G3D::ConvexPolygon2D Class Reference

#include <ConvexPolyhedron.h>

Public Member Functions

 ConvexPolygon2D ()
 
 ConvexPolygon2D (const Array< Vector2 > &pts, bool reverse=false)
 
int numVertices () const
 
const Vector2vertex (int index) const
 
bool contains (const Vector2 &p, bool reverseWinding=false) const
 

Private Attributes

Array< Vector2m_vertex
 

Constructor & Destructor Documentation

G3D::ConvexPolygon2D::ConvexPolygon2D ( )
inline
154 {}
G3D::ConvexPolygon2D::ConvexPolygon2D ( const Array< Vector2 > &  pts,
bool  reverse = false 
)

Points are counter-clockwise in a Y = down, X = right coordinate system.

Parameters
reverseIf true, the points are reversed (i.e. winding direction is changed) before the polygon is created.
420  : m_vertex(pts) {
421  if (reverse) {
422  m_vertex.reverse();
423  }
424 }
Array< Vector2 > m_vertex
Definition: ConvexPolyhedron.h:150

Member Function Documentation

bool G3D::ConvexPolygon2D::contains ( const Vector2 p,
bool  reverseWinding = false 
) const
Parameters
reverseWindingIf true, the winding direction of the polygon is reversed for this test.
427  {
428  // Compute the signed area of each polygon from p to an edge.
429  // If the area is non-negative for all polygons then p is inside
430  // the polygon. (To adapt this algorithm for a concave polygon,
431  // the *sum* of the areas must be non-negative).
432 
433  float r = reverse ? -1.0f : 1.0f;
434 
435  for (int i0 = 0; i0 < m_vertex.size(); ++i0) {
436  int i1 = (i0 + 1) % m_vertex.size();
437  const Vector2& v0 = m_vertex[i0];
438  const Vector2& v1 = m_vertex[i1];
439 
440  Vector2 e0 = v0 - p;
441  Vector2 e1 = v1 - p;
442 
443  // Area = (1/2) cross product, negated to be ccw in
444  // a 2D space; we neglect the 1/2
445  float area = -(e0.x * e1.y - e0.y * e1.x);
446 
447  if (area * r < 0) {
448  return false;
449  }
450  }
451 
452  return true;
453 }
Array< Vector2 > m_vertex
Definition: ConvexPolyhedron.h:150
int G3D::ConvexPolygon2D::numVertices ( ) const
inline
165  {
166  return m_vertex.size();
167  }
Array< Vector2 > m_vertex
Definition: ConvexPolyhedron.h:150

+ Here is the call graph for this function:

const Vector2& G3D::ConvexPolygon2D::vertex ( int  index) const
inline
169  {
170  debugAssert((index >= 0) && (index <= m_vertex.size()));
171  return m_vertex[index];
172  }
Array< Vector2 > m_vertex
Definition: ConvexPolyhedron.h:150
#define debugAssert(exp)
Definition: debugAssert.h:160

+ Here is the call graph for this function:

Member Data Documentation

Array<Vector2> G3D::ConvexPolygon2D::m_vertex
private

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