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

#include <CUPath2.h>

Public Member Functions

 Path2 ()
 
 Path2 (const std::vector< Vec2 > &vertices)
 
 Path2 (const Vec2 *vertices, size_t vertsize)
 
 Path2 (const Path2 &path)
 
 Path2 (Path2 &&path)
 
 Path2 (const Rect rect)
 
 Path2 (const std::shared_ptr< JsonValue > &data)
 
 ~Path2 ()
 
Path2operator= (const Path2 &other)
 
Path2operator= (Path2 &&other)
 
Path2operator= (const Rect rect)
 
Path2operator= (const std::shared_ptr< JsonValue > &data)
 
Path2set (const std::vector< Vec2 > &vertices)
 
Path2set (const Vec2 *vertices, size_t vertsize)
 
Path2set (const Path2 &path)
 
Path2set (const Rect rect)
 
Path2set (const std::shared_ptr< JsonValue > &data)
 
Path2clear ()
 
bool empty () const
 
size_t size () const
 
bool isClosed () const
 
Vec2at (size_t index)
 
const Vec2at (size_t index) const
 
bool isCorner (size_t index) const
 
const std::vector< Vec2 > & getVertices () const
 
const Rect getBounds () const
 
std::vector< Uint32 > getIndices () const
 
size_t getIndices (std::vector< Uint32 > &buffer) const
 
Vec2 pop ()
 
void push (Vec2 point, bool corner=false)
 
void push (float x, float y, bool corner=false)
 
Vec2 remove (size_t index)
 
void add (size_t index, Vec2 point, bool corner=false)
 
void add (size_t index, float x, float y, bool corner=false)
 
void reserve (size_t size)
 
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
 
Uint32 leftTurns () const
 
bool isConvex () const
 
float area () const
 
int orientation () const
 
Path2reverse ()
 
Path2 reversed () const
 
Path2operator*= (float scale)
 
Path2operator*= (const Vec2 scale)
 
Path2operator*= (const Affine2 &transform)
 
Path2operator*= (const Mat4 &transform)
 
Path2operator/= (float scale)
 
Path2operator/= (const Vec2 scale)
 
Path2operator+= (const Vec2 offset)
 
Path2operator-= (const Vec2 offset)
 
Path2 operator* (float scale) const
 
Path2 operator* (const Vec2 scale) const
 
Path2 operator* (const Affine2 &transform) const
 
Path2 operator* (const Mat4 &transform) const
 
Path2 operator/ (float scale) const
 
Path2 operator/ (const Vec2 scale) const
 
Path2 operator+ (const Vec2 offset) const
 
Path2 operator- (const Vec2 offset)
 
Path2operator+= (const Path2 &extra)
 
Path2 operator+ (const Path2 &extra) const
 
Path2 slice (size_t start, size_t end) const
 
Path2 sliceFrom (size_t start) const
 
Path2 sliceTo (size_t end) const
 
std::string toString (bool verbose=false) const
 
 operator std::string () const
 
 operator Rect () const
 

Static Public Member Functions

static std::vector< Uint32 > convexHull (const std::vector< Vec2 > &vertices)
 
static int orientation (const Vec2 &a, const Vec2 &b, const Vec2 &c)
 
static int orientation (const std::vector< Vec2 > &path)
 
static int orientation (const Vec2 *path, size_t size)
 

Public Attributes

std::vector< Vec2vertices
 
std::unordered_set< size_t > corners
 
bool closed
 

Friends

class PathSmoother
 
class PathFactory
 
class SplinePather
 
class SimpleExtruder
 
class ComplexExtruder
 
class EarclipTriangulator
 
class DelaunayTriangulator
 
Path2 operator* (float scale, const Path2 &path)
 
Path2 operator* (const Vec2 scale, const Path2 &path)
 

Detailed Description

Class to represent a flattened polyline.

This class is intended to represent any continuous polyline. While it may be either open or closed, it should not have any gaps between vertices. If you need a path with gaps, that should be represented by multiple Path2 objects.

It is possible to draw a path object directly to a SpriteBatch. However, in most applications you will want to convert a path object to a Poly2 for width and texturing. In particular, you will often want to either extrude (give stroke width) or triangulate (fill) a path.

We have provided several factories for converting a path to a Poly2. 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.

PathFactory: 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 polygon meshes.

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

◆ Path2() [1/7]

cugl::Path2::Path2 ( )
inline

Creates an empty path.

The created path has no vertices. The bounding box is trivial.

◆ Path2() [2/7]

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

Creates a path with the given vertices

No vertices are marked are as corner vertices. The path will be open.

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

◆ Path2() [3/7]

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

Creates a path with the given vertices

No vertices are marked are as corner vertices. The path will be open.

Parameters
verticesThe array of vertices in this path
vertsizeThe number of elements to use from vertices

◆ Path2() [4/7]

cugl::Path2::Path2 ( const Path2 path)
inline

Creates a copy of the given path.

Both the vertices and the annotations are copied. No references to the original path are kept.

Parameters
pathThe path to copy

◆ Path2() [5/7]

cugl::Path2::Path2 ( Path2 &&  path)
inline

Creates a copy with the resource of the given path.

As a move constructor, this will invalidate the original path

Parameters
pathThe path to take from

◆ Path2() [6/7]

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

Creates a path for the given rectangle.

The path will have four vertices, one for each corner of the rectangle. It will be closed.

Parameters
rectThe rectangle to copy

◆ Path2() [7/7]

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

Creates a path 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. All points are corners and the path is closed.

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

"vertices":  An (even) list of floats, representing the vertices
"corners":   A list of integers representing corner positions
"closed":    A boolean value, representing if the path is closed

All attributes are optional. If "vertices" are missing, then the path will be empty. If "corners" is missing, then all vertices are corners. If "closed" is missing, then the path is closed by default.

Parameters
dataThe JSON object specifying the path

◆ ~Path2()

cugl::Path2::~Path2 ( )
inline

Deletes the given path, freeing all resources.

Member Function Documentation

◆ add() [1/2]

void cugl::Path2::add ( size_t  index,
float  x,
float  y,
bool  corner = false 
)

Adds a point at the given index

Parameters
indexThe index to add the point
xThe x-coordinate to add
yThe y-coordinate to add
cornerWhether this point is a corner

◆ add() [2/2]

void cugl::Path2::add ( size_t  index,
Vec2  point,
bool  corner = false 
)

Adds a point at the given index

Parameters
indexThe index to add the point
pointThe point to add
cornerWhether this point is a corner

◆ area()

float cugl::Path2::area ( ) const

Returns the area enclosed by this path.

The area is defined as the sum of oriented triangles in a triangle fan from a point on the convex hull. Counter-clockwise triangles have positive area, while clockwise triangles have negative area. The result agrees with the traditional concept of area for counter clockwise paths.

The area can be used to determine the orientation. It the area is negative, that means this path essentially represents a hole (e.g. is clockwise instead of counter-clockwise).

Returns
the area enclosed by this path.

◆ at() [1/2]

Vec2& cugl::Path2::at ( size_t  index)
inline

Returns a reference to the point at the given index.

This accessor will allow you to change the (singular) point. It is intended to allow minor distortions to the path without changing the underlying geometry.

Parameters
indexThe path index
Returns
a reference to the point at the given index.

◆ at() [2/2]

const Vec2& cugl::Path2::at ( size_t  index) const
inline

Returns a reference to the point at the given index.

This accessor will allow you to change the (singular) point. It is intended to allow minor distortions to the path without changing the underlying geometry.

Parameters
indexThe path index
Returns
a reference to the point at the given index.

◆ clear()

Path2& cugl::Path2::clear ( )

Clears the contents of this path

Returns
This path, returned for chaining

◆ contains() [1/2]

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

Returns true if the interior of this path contains the given point.

This mehtod returns false if the path is open. Otherwise, it uses an even-odd crossing rule to determine containment. 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 path contains the given point.

◆ contains() [2/2]

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

Returns true if the interior of this path contains the given point.

This mehtod returns false if the path is open. Otherwise, it uses an even-odd crossing rule to determine containment. Containment is not strict. Points on the boundary are contained within this polygon.

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

◆ convexHull() [1/2]

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

Returns the set of points forming the convex hull of this path.

The returned set of points 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 set of points forming the convex hull of this polygon.

◆ convexHull() [2/2]

static std::vector<Uint32> cugl::Path2::convexHull ( const std::vector< Vec2 > &  vertices)
static

Returns the set of points forming the convex hull of the given points.

The returned set of points 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/

Parameters
verticesThe points for the computation
Returns
the set of points forming the convex hull of the given points.

◆ empty()

bool cugl::Path2::empty ( ) const
inline

Returns true if the path is empty.

Returns
true if the path is empty.

◆ getBounds()

const Rect cugl::Path2::getBounds ( ) const

Returns the bounding box for the path

The bounding box is the minimal rectangle that contains all of the vertices in this path. This method will recompute the bounds and is hence O(n).

Returns
the bounding box for the path

◆ getIndices() [1/2]

std::vector<Uint32> cugl::Path2::getIndices ( ) const

Returns a list of vertex indices representing this path.

The indices are intended to be used in a drawing mesh to display this path. The number of indices will be a multiple of two.

Returns
a list of vertex indices for using in a path mesh.

◆ getIndices() [2/2]

size_t cugl::Path2::getIndices ( std::vector< Uint32 > &  buffer) const

Stores a list of vertex indices in the given buffer.

The indices are intended to be used in a drawing mesh to display this path. The number of indices will be a multiple of two.

The indices will be appended to the provided vector. You should clear the vector first if you do not want to preserve the original data. If the calculation is not yet performed, this method will do nothing.

Parameters
buffera buffer to store the list of indices.
Returns
the number of elements added to the buffer

◆ getVertices()

const std::vector<Vec2>& cugl::Path2::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 path via a set() method.

Returns
a reference to the vertex array

◆ incident() [1/2]

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

Returns true if the given point is on the path.

This method returns true if the point is within margin of error of a line segment.

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

◆ incident() [2/2]

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

Returns true if the given point is on the path.

This method returns true if the point is within margin of error of a line segment.

Parameters
pointThe point to check
errThe distance tolerance
Returns
true if the given point is on the path.

◆ isClosed()

bool cugl::Path2::isClosed ( ) const
inline

Returns whether the path is closed.

Returns
whether the path is closed.

◆ isConvex()

bool cugl::Path2::isConvex ( ) const

Returns true if this path defines a convex shape.

This method returns false if the path is open.

Returns
true if this path defines a convex shape.

◆ isCorner()

bool cugl::Path2::isCorner ( size_t  index) const

Returns true if the point at the given index is a corner

Corner points will be assigned a joint style when extruded. Points that are not corners will be extruded smoothly (typically because they are the result of a bezier expansion).

Parameters
indexThe attribute index
Returns
true if the point at the given index is a corner

◆ leftTurns()

Uint32 cugl::Path2::leftTurns ( ) const

Returns the number of left turns in this path.

Left turns are determined by looking at the interior angle generated at each point (assuming that the path is intended to be counterclockwise). In the case of an open path, the first and last vertexes are not counted.

This method is a generalization of isConvex that can be used to analyze the convexity of a path.

Returns
true if this path defines a convex shape.

◆ operator Rect()

cugl::Path2::operator Rect ( ) const

Cast from Path2 to a Rect.

◆ operator std::string()

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

Cast from Path2 to a string.

◆ operator*() [1/4]

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

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

Note: This method does not modify the path.

Parameters
transformThe affine transform
Returns
The transformed path

◆ operator*() [2/4]

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

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

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

Note: This method does not modify the path.

Parameters
transformThe transform matrix
Returns
The transformed path

◆ operator*() [3/4]

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

Returns a new path 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 path of this path, then the path will be effectively translated by the scaling.

Note: This method does not modify the path.

Parameters
scaleThe non-uniform scaling factor
Returns
The scaled path

◆ operator*() [4/4]

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

Returns a new path by scaling the vertices uniformly.

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

Note: This method does not modify the path.

Parameters
scaleThe uniform scaling factor
Returns
The scaled path

◆ operator*=() [1/4]

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

Transforms all of the vertices of this path.

Parameters
transformThe affine transform
Returns
This path with the vertices transformed

◆ operator*=() [2/4]

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

Transforms all of the vertices of this path.

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

Parameters
transformThe transform matrix
Returns
This path with the vertices transformed

◆ operator*=() [3/4]

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

Nonuniformly scales all of the vertices of this path.

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

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

◆ operator*=() [4/4]

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

Uniformly scales all of the vertices of this path.

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

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

◆ operator+() [1/2]

Path2 cugl::Path2::operator+ ( const Path2 extra) const
inline

Returns a new path by appending extra to the end of this path

The vertices are appended in order to the end of the path. If the original path was closed, the copy is open (regardless of whether or not extra is closed)

Note: This method does not modify the original path.

Parameters
extraThe path to add
Returns
The extended path

◆ operator+() [2/2]

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

Returns a new path by translating the vertices

Note: This method does not modify the path.

Parameters
offsetThe translation amount
Returns
The translated path

◆ operator+=() [1/2]

Path2& cugl::Path2::operator+= ( const Path2 extra)

Appends the given path to the end of this one

The vertices are appended in order to the end of the path. If the original path was closed, it is now open (regardless of whether or not extra is closed)

Parameters
extraThe path to append
Returns
This path, extended.

◆ operator+=() [2/2]

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

Translates all of the vertices of this path.

Parameters
offsetThe translation amount
Returns
This path, translated.

◆ operator-()

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

Returns a new path by translating the vertices

Note: This method does not modify the path.

Parameters
offsetThe inverse of the translation amount
Returns
The translated path

◆ operator-=()

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

Translates all of the vertices of this path.

Parameters
offsetThe inverse of the translation amount
Returns
This path, translated

◆ operator/() [1/2]

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

Returns a new path 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 path of this path, then the path will be effectively translated by the scaling.

Note: This method does not modify the path.

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

◆ operator/() [2/2]

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

Returns a new path by scaling the vertices uniformly.

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

Note: This method does not modify the path.

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

◆ operator/=() [1/2]

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

Nonuniformly scales all of the vertices of this path.

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

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

◆ operator/=() [2/2]

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

Uniformly scales all of the vertices of this path.

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

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

◆ operator=() [1/4]

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

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

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

This method returns a reference to this path for chaining.

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

◆ operator=() [2/4]

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

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

The path will have four vertices, one for each corner of the rectangle. The path will be closed.

This method returns a reference to this path for chaining.

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

◆ operator=() [3/4]

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

Sets this path 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. All points are corners and the path is closed.

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

"vertices":  An (even) list of floats, representing the vertices
"corners":   A list of integers representing corner positions
"closed":    A boolean value, representing if the path is closed

All attributes are optional. If "vertices" are missing, then the path will be empty. If "corners" is missing, then all vertices are corners. If "closed" is missing, then the path is closed by default.

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

◆ operator=() [4/4]

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

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

This method returns a reference to this path for chaining.

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

◆ orientation() [1/4]

int cugl::Path2::orientation ( ) const

Returns -1, 0, or 1 indicating the path orientation.

If the method returns -1, this is a counter-clockwise path. If 1, it is a clockwise path. If 0, that means it is undefined. The orientation can be undefined if all the points are colinear.

Returns
-1, 0, or 1 indicating the path orientation.

◆ orientation() [2/4]

static int cugl::Path2::orientation ( const std::vector< Vec2 > &  path)
static

Returns -1, 0, or 1 indicating the path orientation.

If the method returns -1, this is a counter-clockwise path. If 1, it is a clockwise path. If 0, that means it is undefined. The orientation can be undefined if all the points are colinear.

Parameters
pathThe path to check
Returns
-1, 0, or 1 indicating the path orientation.

◆ orientation() [3/4]

static int cugl::Path2::orientation ( const Vec2 a,
const Vec2 b,
const Vec2 c 
)
static

Returns -1, 0, or 1 indicating the orientation of a -> b -> c

If the function returns -1, this is a counter-clockwise turn. If 1, it is a clockwise turn. If 0, it is colinear.

Parameters
aThe first point
bThe second point
cThe third point
Returns
-1, 0, or 1 indicating the orientation of a -> b -> c

◆ orientation() [4/4]

static int cugl::Path2::orientation ( const Vec2 path,
size_t  size 
)
static

Returns -1, 0, or 1 indicating the path orientation.

If the method returns -1, this is a counter-clockwise path. If 1, it is a clockwise path. If 0, that means it is undefined. The orientation can be undefined if all the points are colinear.

Parameters
pathThe path to check
sizeThe path size
Returns
-1, 0, or 1 indicating the path orientation.

◆ pop()

Vec2 cugl::Path2::pop ( )

Returns the former end point in the path, after removing it

If this path is empty, this will return the zero vector.

Returns
the former end point in the path

◆ push() [1/2]

void cugl::Path2::push ( float  x,
float  y,
bool  corner = false 
)

Adds a point to the end of this path

Parameters
xThe x-coordinate to add
yThe y-coordinate to add
cornerWhether this point is a corner

◆ push() [2/2]

void cugl::Path2::push ( Vec2  point,
bool  corner = false 
)

Adds a point to the end of this path

Parameters
pointThe point to add
cornerWhether this point is a corner

◆ remove()

Vec2 cugl::Path2::remove ( size_t  index)

Returns the former point at the given index, after removing it

If this path is empty, this will return the zero vector.

Returns
the former point at the given index

◆ reserve()

void cugl::Path2::reserve ( size_t  size)

Allocates space in this path for the given number of points.

This method can help performance when a path is being constructed piecemeal.

Parameters
sizeThe number of spots allocated for future points.

◆ reverse()

Path2& cugl::Path2::reverse ( )

Reverses the orientation of this path in place

The path will have all of its vertices in the reverse order from the original. This path will not be affected.

Returns
This path, returned for chaining

◆ reversed()

Path2 cugl::Path2::reversed ( ) const

Returns a path with the reverse orientation of this one.

The path will have all of its vertices in the reverse order from the original. This path will not be affected.

Returns
a path with the reverse orientation of this one.

◆ set() [1/5]

Path2& cugl::Path2::set ( const Path2 path)

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

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

This method returns a reference to this path for chaining.

Parameters
pathThe path to copy
Returns
This path, returned for chaining

◆ set() [2/5]

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

Sets the path to represent the given rectangle.

The path will have four vertices, one for each corner of the rectangle. The path will be closed.

This method returns a reference to this path for chaining.

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

◆ set() [3/5]

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

Sets this path 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. All points are corners and the path is closed.

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

"vertices":  An (even) list of floats, representing the vertices
"corners":   A list of integers representing corner positions
"closed":    A boolean value, representing if the path is closed

All attributes are optional. If "vertices" are missing, then the path will be empty. If "corners" is missing, then all vertices are corners. If "closed" is missing, then the path is closed by default.

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

◆ set() [4/5]

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

Sets the path to have the given vertices

No vertices are marked are as corner vertices. The path will be open.

This method returns a reference to this path for chaining.

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

◆ set() [5/5]

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

Sets the path to have the given vertices.

No vertices are marked are as corner vertices. The path will be open.

This method returns a reference to this path for chaining.

Parameters
verticesThe array of vertices in this path
vertsizeThe number of elements to use from vertices
Returns
This path, returned for chaining

◆ size()

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

Returns the number of vertices in a path.

Returns
the number of vertices in a path.

◆ slice()

Path2 cugl::Path2::slice ( size_t  start,
size_t  end 
) const

Returns the slice of this path between start and end.

The sliced path will use the indices from start to end (not including end). It will include the vertices referenced by those indices, and only those vertices. The resulting path is open.

Parameters
startThe start index
endThe end index
Returns
the slice of this mesh between start and end.

◆ sliceFrom()

Path2 cugl::Path2::sliceFrom ( size_t  start) const
inline

Returns the slice of this mesh from the start index to the end.

The sliced mesh will use the indices from start to the end. It will include the vertices referenced by those indices, and only those vertices. The resulting path is open.

Parameters
startThe start index
Returns
the slice of this mesh between start and end.

◆ sliceTo()

Path2 cugl::Path2::sliceTo ( size_t  end) const
inline

Returns the slice of this mesh from the begining to end.

The sliced mesh will use the indices up to (but not including) end. It will include the vertices referenced by those indices, and only those vertices. The resulting path is open.

Parameters
endThe end index
Returns
the slice of this mesh between start and end.

◆ toString()

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

Returns a string representation of this path 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 path for debugging purposes.

Friends And Related Function Documentation

◆ operator* [1/2]

Path2 operator* ( const Vec2  scale,
const Path2 path 
)
friend

Returns a new path 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 path of this path, then the path will be effectively translated by the scaling.

Parameters
scaleThe non-uniform scaling factor
pathThe path to scale
Returns
The scaled path

◆ operator* [2/2]

Path2 operator* ( float  scale,
const Path2 path 
)
friend

Returns a new path by scaling the vertices uniformly.

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

Parameters
scaleThe uniform scaling factor
pathThe path to scale
Returns
The scaled path

◆ PathSmoother

friend class PathSmoother
friend

Friend classes

Member Data Documentation

◆ closed

bool cugl::Path2::closed

Whether or not this path is closed

◆ corners

std::unordered_set<size_t> cugl::Path2::corners

The corner points of this path (used for extrusion).

◆ vertices

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

The vector of vertices in this path


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