CUGL 2.1
Cornell University Game Library
Public Member Functions | Public Attributes | Friends | List of all members
cugl::Poly2 Class Reference

#include <CUPoly2.h>

Public Member Functions

 Poly2 ()
 
 Poly2 (const std::vector< Vec2 > &vertices)
 
 Poly2 (const Vec2 *vertices, size_t vertsize)
 
 Poly2 (const std::vector< Vec2 > &vertices, const std::vector< Uint32 > &indices)
 
 Poly2 (const Poly2 &poly)
 
 Poly2 (Poly2 &&poly)
 
 Poly2 (const Rect rect)
 
 Poly2 (const std::shared_ptr< JsonValue > &data)
 
 ~Poly2 ()
 
Poly2operator= (const Poly2 &other)
 
Poly2operator= (Poly2 &&other)
 
Poly2operator= (const Rect rect)
 
Poly2operator= (const std::shared_ptr< JsonValue > &data)
 
Poly2set (const std::vector< Vec2 > &vertices)
 
Poly2set (const Vec2 *vertices, size_t vertsize)
 
Poly2set (const Poly2 &poly)
 
Poly2set (const Rect rect)
 
Poly2set (const std::shared_ptr< JsonValue > &data)
 
Poly2setIndices (const std::vector< Uint32 > &indices)
 
Poly2setIndices (const Uint32 *indices, size_t indxsize)
 
Poly2clear ()
 
size_t size () const
 
size_t indexSize () const
 
Vec2at (int index)
 
const Vec2at (int index) const
 
const std::vector< Vec2 > & getVertices () const
 
const std::vector< Uint32 > & getIndices () const
 
const Rect getBounds () const
 
Poly2operator*= (float scale)
 
Poly2operator*= (const Vec2 scale)
 
Poly2operator*= (const Affine2 &transform)
 
Poly2operator*= (const Mat4 &transform)
 
Poly2operator/= (float scale)
 
Poly2operator/= (const Vec2 scale)
 
Poly2operator+= (float offset)
 
Poly2operator+= (const Vec2 offset)
 
Poly2operator-= (float offset)
 
Poly2operator-= (const Vec2 offset)
 
Poly2 operator* (float scale) const
 
Poly2 operator* (const Vec2 scale) const
 
Poly2 operator* (const Affine2 &transform) const
 
Poly2 operator* (const Mat4 &transform) const
 
Poly2 operator/ (float scale) const
 
Poly2 operator/ (const Vec2 scale) const
 
Poly2 operator+ (float offset) const
 
Poly2 operator+ (const Vec2 offset) const
 
Poly2 operator- (float offset)
 
Poly2 operator- (const Vec2 offset)
 
std::vector< Uint32 > convexHull () const
 
bool contains (Vec2 point) const
 
bool contains (float x, float y) const
 
bool incident (Vec2 point, float err=CU_MATH_EPSILON) const
 
bool incident (float x, float y, float err=CU_MATH_EPSILON) const
 
std::unordered_set< Uint32 > exterior () const
 
size_t exterior (std::unordered_set< Uint32 > &buffer) const
 
std::vector< std::vector< Uint32 > > boundaries () const
 
size_t boundaries (std::vector< std::vector< Uint32 >> &buffer) const
 
std::string toString (bool verbose=false) const
 
 operator std::string () const
 
 operator Rect () const
 

Public Attributes

std::vector< Vec2vertices
 
std::vector< Uint32 > indices
 

Friends

Poly2 operator* (float scale, const Poly2 &poly)
 
Poly2 operator* (const Vec2 scale, const Poly2 &poly)
 

Detailed Description

Class to represent a simple polygon.

This class is intended to represent any polygon (including non-convex polygons). that does not have self-interections (as these can cause serious problems with the mathematics). Most polygons are simple, meaning that they have no holes. However, this class does support complex polygons with holes, provided that the polygon is not implicit and has an corresponding mesh.

To define a mesh, the user should provide a set of indices which will be used in rendering. These indices should represent a triangulation of the polygon. However, this class performs no verification. It will not check that a mesh is in proper form, nor will it search for holes or self-intersections. These are the responsibility of the programmer.

Generating indices for a Poly2 can be nontrivial. While this class has standard constructors for custom meshes, most Poly2 objects are created through alternate means. In particular, there are several Poly2 factories available. These factories allow for delegating index computation to a separate thread, if it takes too long. These factories are as follows:

EarclipTriangulator: This is a simple earclipping-triangulator for tesselating paths into polygons. It supports holes, but does not support self-intersections. While it produces better (e.g. less thin) triangles than MonotoneTriangulator, this comes at a cost. This triangulator has worst case O(n^2). With that said, it has low overhead and so is very efficient on small polygons.

DelaunayTriangulator: This is a Delaunay Triangular that gives a more uniform triangulation in accordance to the Vornoi diagram. This triangulator uses an advancing-front algorithm that is the fastest in practice (though worst case O(n log n) is not guaranteed). However, it has a lot of overhead that is unnecessary for small polygons. As with EarclipTriangulator, it supports holes, but does not support self-intersections.

PolyFactory: This is a tool is used to generate several basic path shapes, such as rounded rectangles or arcs. It also allows you construct wireframe traversals of existing polygons.

SimpleExtruder: This is a tool can take a path and convert it into a solid polygon. This solid polygon is the same as the path, except that the path now has a width and a mitre at the joints. This algorithm is quite fast, but the resulting polygon may overlap itself. This is ideal for strokes that only need to be drawn and do not need accurate geometric information.

ComplexExtruder: Like SimpleExtruder, this is a tool can take a path polygon and convert it into a solid polygon. However it is much more powerful and guarantees that the resulting polygon has no overlaps. Unforunately, it is extremely slow (in the 10s of milliseconds) and is unsuitable for calcuations at framerate.

Constructor & Destructor Documentation

◆ Poly2() [1/8]

cugl::Poly2::Poly2 ( )
inline

Creates an empty polygon.

The created polygon has no vertices and no triangulation. The bounding box is trivial.

◆ Poly2() [2/8]

cugl::Poly2::Poly2 ( const std::vector< Vec2 > &  vertices)
inline

Creates a polygon with the given vertices

The new polygon has no indices triangulating the vertices.

Parameters
verticesThe vector of vertices (as Vec2) in this polygon

◆ Poly2() [3/8]

cugl::Poly2::Poly2 ( const Vec2 vertices,
size_t  vertsize 
)
inline

Creates a polygon with the given vertices

The new polygon has no indices triangulating the vertices.

Parameters
verticesThe vector of vertices (as Vec2) in this polygon
vertsizeThe number of elements to use from vertices

◆ Poly2() [4/8]

cugl::Poly2::Poly2 ( const std::vector< Vec2 > &  vertices,
const std::vector< Uint32 > &  indices 
)
inline

Creates a polygon with the given vertices and indices.

A valid list of indices must only refer to vertices in the vertex array. That is, the indices should all be non-negative, and each value should be less than the number of vertices. In addition, the number of indices should be a multiple of three, each group representing a counterclockwise triangle of vertices.

Parameters
verticesThe vector of vertices (as Vec2) in this polygon
indicesThe vector of indices for the rendering

◆ Poly2() [5/8]

cugl::Poly2::Poly2 ( const Poly2 poly)
inline

Creates a copy of the given polygon.

Both the vertices and the indices are of the source are copied. No references to the original polygon are kept.

Parameters
polyThe polygon to copy

◆ Poly2() [6/8]

cugl::Poly2::Poly2 ( Poly2 &&  poly)
inline

Creates a copy with the resource of the given polygon.

Parameters
polyThe polygon to take from

◆ Poly2() [7/8]

cugl::Poly2::Poly2 ( const Rect  rect)
inline

Creates a polygon for the given rectangle.

The polygon will have four vertices, one for each corner of the rectangle. The indices will define two triangles on these vertices. This method is faster than using one of the more heavy-weight triangulators.

Parameters
rectThe rectangle to copy

◆ Poly2() [8/8]

cugl::Poly2::Poly2 ( const std::shared_ptr< JsonValue > &  data)
inline

Creates a polygon from the given JsonValue

The JsonValue should either be an array of floats or an JSON object. If it is an array of floats, then it interprets those floats as the vertices. The polygon indices will be generated using an EarclipTriangulator.

On the other hand, if it is a JSON object, it supports the following attributes:

"vertices":      An (even) list of floats, representing the vertices
"indices":       An intenger list of triangle indices (in multiples of 3)
"triangulator":  One of 'monotone', 'earclip' or 'delaunay'

All attributes are optional. If "vertices" are missing, the polygon will be empty. If both "indices" and "triangulator" are missing, the polygon will have no indices. The "triangulator" choice will only be applied if the "indices" are missing.

Parameters
dataThe JSON object specifying the polygon

◆ ~Poly2()

cugl::Poly2::~Poly2 ( )
inline

Deletes the given polygon, freeing all resources.

Member Function Documentation

◆ at() [1/2]

Vec2& cugl::Poly2::at ( int  index)
inline

Returns a reference to the attribute at the given index.

This accessor will allow you to change the (singular) vertex. It is intended to allow minor distortions to the polygon without changing the underlying mesh.

Parameters
indexThe attribute index
Returns
a reference to the attribute at the given index.

◆ at() [2/2]

const Vec2& cugl::Poly2::at ( int  index) const
inline

Returns a reference to the attribute at the given index.

This accessor will allow you to change the (singular) vertex. It is intended to allow minor distortions to the polygon without changing the underlying mesh.

Parameters
indexThe attribute index
Returns
a reference to the attribute at the given index.

◆ boundaries() [1/2]

std::vector<std::vector<Uint32> > cugl::Poly2::boundaries ( ) const

Returns the connected boundary components for this polygon.

This method allows us to reconstruct the exterior boundary of a solid shape, or to compose a pathwise connected curve into components.

This method detriangulates the polygon mesh, returning the outer hull, discarding any interior points. This hull need not be convex. If the mesh represents a simple polygon, only one boundary will be returned. If the mesh is not continuous, the outer array will contain the boundary of each disjoint polygon. If the mesh has holes, each hole will be returned as a separate boundary. There is no guarantee on the order of boundaries returned.

Returns
the connected boundary components for this polygon.

◆ boundaries() [2/2]

size_t cugl::Poly2::boundaries ( std::vector< std::vector< Uint32 >> &  buffer) const

Stores the connected boundary components for this polygon.

This method allows us to reconstruct the exterior boundary of a solid shape, or to compose a pathwise connected curve into components.

This method detriangulates the polygon mesh, returning the outer hull, discarding any interior points. This hull need not be convex. If the mesh represents a simple polygon, only one boundary will be returned. If the mesh is not continuous, the outer array will contain the boundary of each disjoint polygon. If the mesh has holes, each hole will be returned as a separate boundary. There is no guarantee on the order of boundaries returned.

Parameters
bufferA buffer to connected boundary components
Returns
the number of elements added to the buffer

◆ clear()

Poly2& cugl::Poly2::clear ( )

Clears the contents of this polygon (both vertices and indices)

Returns
This polygon, returned for chaining

◆ contains() [1/2]

bool cugl::Poly2::contains ( float  x,
float  y 
) const

Returns true if this polygon contains the given point.

Unlike Path2, this method does not use an even-odd rule. Instead, it checks for containment within the associated triangle mesh.

Containment is not strict. Points on the boundary are contained within this polygon.

Parameters
xThe x-coordinate to test
yThe y-coordinate to test
Returns
true if this polygon contains the given point.

◆ contains() [2/2]

bool cugl::Poly2::contains ( Vec2  point) const
inline

Returns true if this polygon contains the given point.

Unlike Path2, this method does not use an even-odd rule. Instead, it checks for containment within the associated triangle mesh.

Containment is not strict. Points on the boundary are contained within this polygon.

Parameters
pointThe point to test
Returns
true if this polygon contains the given point.

◆ convexHull()

std::vector<Uint32> cugl::Poly2::convexHull ( ) const

Returns the vertex indices forming the convex hull of this polygon.

The returned set of indices is guaranteed to be a counter-clockwise traversal of the hull.

The points on the convex hull define the "border" of the shape. In addition to minimizing the number of vertices, this is useful for determining whether or not a point lies on the boundary.

This implementation is adapted from the example at

http://www.geeksforgeeks.org/convex-hull-set-2-graham-scan/

Returns
the vertex indices forming the convex hull of this polygon.

◆ exterior() [1/2]

std::unordered_set<Uint32> cugl::Poly2::exterior ( ) const

Returns the set of indices that are on a boundary of this polygon

This method can identify the outer hull using the graph properties of the triangle mesh. An internal node if the number of neighbors is the same as the number of attached triangles. An index that is not internal is external.

Unlike boundaries, this method does not order the boundary indices or decompose them into connected components.

Returns
the set of indices that are on a boundary of this polygon

◆ exterior() [2/2]

size_t cugl::Poly2::exterior ( std::unordered_set< Uint32 > &  buffer) const

Stores the set of indices that are on a boundary of this polygon

This method can identify the outer hull using the graph properties of the triangle mesh. An internal node if the number of neighbors is the same as the number of attached triangles. An index that is not internal is external.

Unlike boundaries, this method does not order the boundary indices or decompose them into connected components.

Parameters
bufferA buffer to store the indices on the boundary
Returns
the number of elements added to the buffer

◆ getBounds()

const Rect cugl::Poly2::getBounds ( ) const

Returns the bounding box for the polygon

The bounding box is the minimal rectangle that contains all of the vertices in this polygon. It is recomputed whenever the vertices are set.

Returns
the bounding box for the polygon

◆ getIndices()

const std::vector<Uint32>& cugl::Poly2::getIndices ( ) const
inline

Returns a reference to list of indices.

This accessor will not permit any changes to the index array. To change the array, you must change the polygon via a set() method.

Returns
a reference to the vertex array

◆ getVertices()

const std::vector<Vec2>& cugl::Poly2::getVertices ( ) const
inline

Returns the list of vertices

This accessor will not permit any changes to the vertex array. To change the array, you must change the polygon via a set() method.

Returns
a reference to the vertex array

◆ incident() [1/2]

bool cugl::Poly2::incident ( float  x,
float  y,
float  err = CU_MATH_EPSILON 
) const

Returns true if the given point is on the boundary of this polygon.

This method generates uses boundaries to determine the boundaries. It returns true if the point is within margin of error of a line segment on one of the boundaries.

Parameters
xThe x-coordinate to test
yThe y-coordinate to test
errThe distance tolerance
Returns
true if the given point is on the boundary of this polygon.

◆ incident() [2/2]

bool cugl::Poly2::incident ( Vec2  point,
float  err = CU_MATH_EPSILON 
) const
inline

Returns true if the given point is on the boundary of this polygon.

This method generates uses boundaries to determine the boundaries. It returns true if the point is within margin of error of a line segment on one of the boundaries.

Parameters
pointThe point to check
errThe distance tolerance
Returns
true if the given point is on the boundary of this polygon.

◆ indexSize()

size_t cugl::Poly2::indexSize ( ) const
inline

Returns the number of indices in the polygon.

Returns
the number of indices in the polygon.

◆ operator Rect()

cugl::Poly2::operator Rect ( ) const

Cast from Poly2 to a Rect.

◆ operator std::string()

cugl::Poly2::operator std::string ( ) const
inline

Cast from Poly to a string.

◆ operator*() [1/4]

Poly2 cugl::Poly2::operator* ( const Affine2 transform) const
inline

Returns a new polygon by transforming all of the vertices of this polygon.

Note: This method does not modify the polygon.

Parameters
transformThe affine transform
Returns
The transformed polygon

◆ operator*() [2/4]

Poly2 cugl::Poly2::operator* ( const Mat4 transform) const
inline

Returns a new polygon by transforming all of the vertices of this polygon.

The vertices are transformed as points. The z-value is 0.

Note: This method does not modify the polygon.

Parameters
transformThe transform matrix
Returns
The transformed polygon

◆ operator*() [3/4]

Poly2 cugl::Poly2::operator* ( const Vec2  scale) const
inline

Returns a new polygon by scaling the vertices non-uniformly.

The vertices are scaled from the origin of the coordinate space. This means that if the origin is not in the interior of this polygon, the polygon will be effectively translated by the scaling.

Note: This method does not modify the polygon.

Parameters
scaleThe non-uniform scaling factor
Returns
The scaled polygon

◆ operator*() [4/4]

Poly2 cugl::Poly2::operator* ( float  scale) const
inline

Returns a new polygon by scaling the vertices uniformly.

The vertices are scaled from the origin of the coordinate space. This means that if the origin is not in the interior of this polygon, the polygon will be effectively translated by the scaling.

Note: This method does not modify the polygon.

Parameters
scaleThe uniform scaling factor
Returns
The scaled polygon

◆ operator*=() [1/4]

Poly2& cugl::Poly2::operator*= ( const Affine2 transform)

Transforms all of the vertices of this polygon.

Parameters
transformThe affine transform
Returns
This polygon with the vertices transformed

◆ operator*=() [2/4]

Poly2& cugl::Poly2::operator*= ( const Mat4 transform)

Transforms all of the vertices of this polygon.

The vertices are transformed as points. The z-value is 0.

Parameters
transformThe transform matrix
Returns
This polygon with the vertices transformed

◆ operator*=() [3/4]

Poly2& cugl::Poly2::operator*= ( const Vec2  scale)

Nonuniformly scales all of the vertices of this polygon.

The vertices are scaled from the origin of the coordinate space. This means that if the origin is not in the interior of this polygon, the polygon will be effectively translated by the scaling.

Parameters
scaleThe non-uniform scaling factor
Returns
This polygon, scaled non-uniformly.

◆ operator*=() [4/4]

Poly2& cugl::Poly2::operator*= ( float  scale)

Uniformly scales all of the vertices of this polygon.

The vertices are scaled from the origin of the coordinate space. This means that if the origin is not in the interior of this polygon, the polygon will be effectively translated by the scaling.

Parameters
scaleThe uniform scaling factor
Returns
This polygon, scaled uniformly.

◆ operator+() [1/2]

Poly2 cugl::Poly2::operator+ ( const Vec2  offset) const
inline

Returns a new polygon by translating the vertices non-uniformly.

Note: This method does not modify the polygon.

Parameters
offsetThe non-uniform translation amount
Returns
The translated polygon

◆ operator+() [2/2]

Poly2 cugl::Poly2::operator+ ( float  offset) const
inline

Returns a new polygon by translating the vertices uniformly.

Note: This method does not modify the polygon.

Parameters
offsetThe uniform translation amount
Returns
The translated polygon

◆ operator+=() [1/2]

Poly2& cugl::Poly2::operator+= ( const Vec2  offset)

Non-uniformly translates all of the vertices of this polygon.

Parameters
offsetThe non-uniform translation amount
Returns
This polygon, translated non-uniformly.

◆ operator+=() [2/2]

Poly2& cugl::Poly2::operator+= ( float  offset)

Uniformly translates all of the vertices of this polygon.

Parameters
offsetThe uniform translation amount
Returns
This polygon, translated uniformly.

◆ operator-() [1/2]

Poly2 cugl::Poly2::operator- ( const Vec2  offset)
inline

Returns a new polygon by translating the vertices non-uniformly.

Note: This method does not modify the polygon.

Parameters
offsetThe inverse of the non-uniform translation amount
Returns
The translated polygon

◆ operator-() [2/2]

Poly2 cugl::Poly2::operator- ( float  offset)
inline

Returns a new polygon by translating the vertices uniformly.

Note: This method does not modify the polygon.

Parameters
offsetThe inverse of the uniform translation amount
Returns
The translated polygon

◆ operator-=() [1/2]

Poly2& cugl::Poly2::operator-= ( const Vec2  offset)

Non-uniformly translates all of the vertices of this polygon.

Parameters
offsetThe inverse of the non-uniform translation amount
Returns
This polygon, translated non-uniformly.

◆ operator-=() [2/2]

Poly2& cugl::Poly2::operator-= ( float  offset)

Uniformly translates all of the vertices of this polygon.

Parameters
offsetThe inverse of the uniform translation amount
Returns
This polygon, translated uniformly.

◆ operator/() [1/2]

Poly2 cugl::Poly2::operator/ ( const Vec2  scale) const
inline

Returns a new polygon by scaling the vertices non-uniformly.

The vertices are scaled from the origin of the coordinate space. This means that if the origin is not in the interior of this polygon, the polygon will be effectively translated by the scaling.

Note: This method does not modify the polygon.

Parameters
scaleThe inverse of the non-uniform scaling factor
Returns
The scaled polygon

◆ operator/() [2/2]

Poly2 cugl::Poly2::operator/ ( float  scale) const
inline

Returns a new polygon by scaling the vertices uniformly.

The vertices are scaled from the origin of the coordinate space. This means that if the origin is not in the interior of this polygon, the polygon will be effectively translated by the scaling.

Note: This method does not modify the polygon.

Parameters
scaleThe inverse of the uniform scaling factor
Returns
The scaled polygon

◆ operator/=() [1/2]

Poly2& cugl::Poly2::operator/= ( const Vec2  scale)

Nonuniformly scales all of the vertices of this polygon.

The vertices are scaled from the origin of the coordinate space. This means that if the origin is not in the interior of this polygon, the polygon will be effectively translated by the scaling.

Parameters
scaleThe inverse of the non-uniform scaling factor
Returns
This polygon, scaled non-uniformly.

◆ operator/=() [2/2]

Poly2& cugl::Poly2::operator/= ( float  scale)

Uniformly scales all of the vertices of this polygon.

The vertices are scaled from the origin of the coordinate space. This means that if the origin is not in the interior of this polygon, the polygon will be effectively translated by the scaling.

Parameters
scaleThe inverse of the uniform scaling factor
Returns
This polygon, scaled uniformly.

◆ operator=() [1/4]

Poly2& cugl::Poly2::operator= ( const Poly2 other)
inline

Sets this polygon to be a copy of the given one.

All of the contents are copied, so that this polygon does not hold any references to elements of the other polygon. This method returns a reference to this polygon for chaining.

Parameters
otherThe polygon to copy
Returns
This polygon, returned for chaining

◆ operator=() [2/4]

Poly2& cugl::Poly2::operator= ( const Rect  rect)
inline

Sets this polygon to be a copy of the given rectangle.

The polygon will have four vertices, one for each corner of the rectangle. The indices will define two triangles on these vertices. This method is faster than using one of the more heavy-weight triangulators.

Parameters
rectThe rectangle to copy
Returns
This polygon, returned for chaining

◆ operator=() [3/4]

Poly2& cugl::Poly2::operator= ( const std::shared_ptr< JsonValue > &  data)
inline

Sets this polygon from the data in the given JsonValue

The JsonValue should either be an array of floats or an JSON object. If it is an array of floats, then it interprets those floats as the vertices. The polygon indices will be generated using an EarclipTriangulator.

On the other hand, if it is a JSON object, it supports the following attributes:

"vertices":      An (even) list of floats, representing the vertices
"indices":       An intenger list of triangle indices (in multiples of 3)
"triangulator":  One of 'monotone', 'earclip' or 'delaunay'

All attributes are optional. If "vertices" are missing, the polygon will be empty. If both "indices" and "triangulator" are missing, the polygon will have no indices. The "triangulator" choice will only be applied if the "indices" are missing.

Parameters
dataThe JSON object specifying the polygon
Returns
This polygon, returned for chaining

◆ operator=() [4/4]

Poly2& cugl::Poly2::operator= ( Poly2 &&  other)
inline

Sets this polygon to be have the resources of the given one.

Parameters
otherThe polygon to take from
Returns
This polygon, returned for chaining

◆ set() [1/5]

Poly2& cugl::Poly2::set ( const Poly2 poly)

Sets this polygon to be a copy of the given one.

All of the contents are copied, so that this polygon does not hold any references to elements of the other polygon.

This method returns a reference to this polygon for chaining.

Parameters
polyThe polygon to copy
Returns
This polygon, returned for chaining

◆ set() [2/5]

Poly2& cugl::Poly2::set ( const Rect  rect)

Sets the polygon to represent the given rectangle.

The polygon will have four vertices, one for each corner of the rectangle. The indices will define two triangles on these vertices. This method is faster than using one of the more heavy-weight triangulators.

Parameters
rectThe rectangle to copy
Returns
This polygon, returned for chaining

◆ set() [3/5]

Poly2& cugl::Poly2::set ( const std::shared_ptr< JsonValue > &  data)

Sets this polygon from the data in the given JsonValue

The JsonValue should either be an array of floats or an JSON object. If it is an array of floats, then it interprets those floats as the vertices. The polygon indices will be generated using an EarclipTriangulator.

On the other hand, if it is a JSON object, it supports the following attributes:

"vertices":      An (even) list of floats, representing the vertices
"indices":       An intenger list of triangle indices (in multiples of 3)
"triangulator":  One of 'monotone', 'earclip' or 'delaunay'

All attributes are optional. If "vertices" are missing, the polygon will be empty. If both "indices" and "triangulator" are missing, the polygon will have no indices. The "triangulator" choice will only be applied if the "indices" are missing.

Parameters
dataThe JSON object specifying the polygon
Returns
This polygon, returned for chaining

◆ set() [4/5]

Poly2& cugl::Poly2::set ( const std::vector< Vec2 > &  vertices)

Sets the polygon to have the given vertices

The resulting polygon has no indices triangulating the vertices.

This method returns a reference to this polygon for chaining.

Parameters
verticesThe vector of vertices (as Vec2) in this polygon
Returns
This polygon, returned for chaining

◆ set() [5/5]

Poly2& cugl::Poly2::set ( const Vec2 vertices,
size_t  vertsize 
)

Sets the polygon to have the given vertices.

The resulting polygon has no indices triangulating the vertices.

This method returns a reference to this polygon for chaining.

Parameters
verticesThe array of vertices (as Vec2) in this polygon
vertsizeThe number of elements to use from vertices
Returns
This polygon, returned for chaining

◆ setIndices() [1/2]

Poly2& cugl::Poly2::setIndices ( const std::vector< Uint32 > &  indices)

Sets the indices for this polygon to the ones given.

A valid list of indices must only refer to vertices in the vertex array. That is, the indices should all be non-negative, and each value should be less than the number of vertices. In addition, the number of indices should be a multiple of three, each group representing a counterclockwise triangle of vertices.

The provided indices are copied. The polygon does not retain a reference.

Parameters
indicesThe vector of indices for the shape
Returns
This polygon, returned for chaining

◆ setIndices() [2/2]

Poly2& cugl::Poly2::setIndices ( const Uint32 *  indices,
size_t  indxsize 
)

Sets the indices for this polygon to the ones given.

A valid list of indices must only refer to vertices in the vertex array. That is, the indices should all be non-negative, and each value should be less than the number of vertices. In addition, the number of indices should be a multiple of three, each group representing a counterclockwise triangle of vertices.

The provided indices are copied. The polygon does not retain a reference.

Parameters
indicesThe array of indices for the rendering
indxsizeThe number of elements to use for the indices
Returns
This polygon, returned for chaining

◆ size()

size_t cugl::Poly2::size ( ) const
inline

Returns the number of vertices in the polygon.

Returns
the number of vertices in the polygon.

◆ toString()

std::string cugl::Poly2::toString ( bool  verbose = false) const

Returns a string representation of this polygon for debugging purposes.

If verbose is true, the string will include class information. This allows us to unambiguously identify the class.

Parameters
verboseWhether to include class information
Returns
a string representation of this polygon for debuggging purposes.

Friends And Related Function Documentation

◆ operator* [1/2]

Poly2 operator* ( const Vec2  scale,
const Poly2 poly 
)
friend

Returns a new polygon by scaling the vertices non-uniformly.

The vertices are scaled from the origin of the coordinate space. This means that if the origin is not in the interior of this polygon, the polygon will be effectively translated by the scaling.

Parameters
scaleThe non-uniform scaling factor
polyThe polygon to scale
Returns
The scaled polygon

◆ operator* [2/2]

Poly2 operator* ( float  scale,
const Poly2 poly 
)
friend

Returns a new polygon by scaling the vertices uniformly.

The vertices are scaled from the origin of the coordinate space. This means that if the origin is not in the interior of this polygon, the polygon will be effectively translated by the scaling.

Parameters
scaleThe uniform scaling factor
polyThe polygon to scale
Returns
The scaled polygon

Member Data Documentation

◆ indices

std::vector<Uint32> cugl::Poly2::indices

The vector of indices in the triangulation

◆ vertices

std::vector<Vec2> cugl::Poly2::vertices

The vector of vertices in this polygon


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