Cinder  0.9.1
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Friends | List of all members
cinder::Path2d Class Reference

#include <Path2d.h>

Public Types

enum  SegmentType {
  MOVETO, LINETO, QUADTO, CUBICTO,
  CLOSE
}
 

Public Member Functions

 Path2d ()
 
 Path2d (const BSpline2f &spline, float subdivisionStep=0.01f)
 
void moveTo (const vec2 &p)
 
void moveTo (float x, float y)
 
void lineTo (const vec2 &p)
 
void lineTo (float x, float y)
 
void quadTo (const vec2 &p1, const vec2 &p2)
 
void quadTo (float x1, float y1, float x2, float y2)
 
void curveTo (const vec2 &p1, const vec2 &p2, const vec2 &p3)
 
void curveTo (float x1, float y1, float x2, float y2, float x3, float y3)
 
void arc (const vec2 &center, float radius, float startRadians, float endRadians, bool forward=true)
 
void arc (float centerX, float centerY, float radius, float startRadians, float endRadians, bool forward=true)
 
void arcTo (const vec2 &p, const vec2 &t, float radius)
 
void arcTo (float x, float y, float tanX, float tanY, float radius)
 
void close ()
 
bool isClosed () const
 
void reverse ()
 
bool empty () const
 
void clear ()
 
size_t getNumSegments () const
 
size_t getNumPoints () const
 
vec2 getPosition (float t) const
 
vec2 getSegmentPosition (size_t segment, float t) const
 
vec2 getTangent (float t) const
 
vec2 getSegmentTangent (size_t segment, float t) const
 
void getSegmentRelativeT (float t, size_t *segment, float *relativeT) const
 
std::vector< vec2 > subdivide (float approximationScale=1.0f) const
 
void subdivide (std::vector< vec2 > *resultPositions, std::vector< vec2 > *resultTangents, float approximationScale=1.0f) const
 
void scale (const vec2 &amount, vec2 scaleCenter=vec2())
 
void transform (const mat3 &matrix)
 
Path2d transformed (const mat3 &matrix) const
 
const std::vector< vec2 > & getPoints () const
 
std::vector< vec2 > & getPoints ()
 
const vec2 & getPoint (size_t point) const
 
vec2 & getPoint (size_t point)
 
const vec2 & getCurrentPoint () const
 
void setPoint (size_t index, const vec2 &p)
 
SegmentType getSegmentType (size_t segment) const
 
const std::vector< SegmentType > & getSegments () const
 
std::vector< SegmentType > & getSegments ()
 
void removeSegment (size_t segment)
 
Rectf calcBoundingBox () const
 
Rectf calcPreciseBoundingBox () const
 
bool contains (const vec2 &pt) const
 
float calcLength () const
 
float calcSegmentLength (size_t segment, float minT=0, float maxT=1) const
 
float calcNormalizedTime (float relativeTime, bool wrap=true, float tolerance=1.0e-03f, int maxIterations=16) const
 
float calcTimeForDistance (float distance, bool wrap=true, float tolerance=1.0e-03f, int maxIterations=16) const
 
float segmentSolveTimeForDistance (size_t segment, float segmentLength, float segmentRelativeDistance, float tolerance, int maxIterations) const
 

Static Public Member Functions

static int calcQuadraticBezierMonotoneRegions (const vec2 p[3], float resultT[2])
 
static vec2 calcQuadraticBezierPos (const vec2 p[3], float t)
 
static vec2 calcQuadraticBezierDerivative (const vec2 p[3], float t)
 
static int calcCubicBezierMonotoneRegions (const vec2 p[4], float resultT[4])
 
static vec2 calcCubicBezierPos (const vec2 p[4], float t)
 
static vec2 calcCubicBezierDerivative (const vec2 p[4], float t)
 

Static Public Attributes

static const int sSegmentTypePointCounts [] = { 0, 1, 2, 3, 0 }
 

Friends

class Shape2d
 
class Path2dCalcCache
 
std::ostream & operator<< (std::ostream &out, const Path2d &p)
 

Member Enumeration Documentation

Enumerator
MOVETO 
LINETO 
QUADTO 
CUBICTO 
CLOSE 

Constructor & Destructor Documentation

cinder::Path2d::Path2d ( )
cinder::Path2d::Path2d ( const BSpline2f spline,
float  subdivisionStep = 0.01f 
)
explicit

Member Function Documentation

void cinder::Path2d::moveTo ( const vec2 &  p)

Sets the start point of the path to p. This is the only legal first command, and only legal as the first command.

void cinder::Path2d::moveTo ( float  x,
float  y 
)

Sets the start point of the path to (x, y ). This is the only legal first command, and only legal as the first command.

void cinder::Path2d::lineTo ( const vec2 &  p)
void cinder::Path2d::lineTo ( float  x,
float  y 
)
void cinder::Path2d::quadTo ( const vec2 &  p1,
const vec2 &  p2 
)
void cinder::Path2d::quadTo ( float  x1,
float  y1,
float  x2,
float  y2 
)
void cinder::Path2d::curveTo ( const vec2 &  p1,
const vec2 &  p2,
const vec2 &  p3 
)
void cinder::Path2d::curveTo ( float  x1,
float  y1,
float  x2,
float  y2,
float  x3,
float  y3 
)
void cinder::Path2d::arc ( const vec2 &  center,
float  radius,
float  startRadians,
float  endRadians,
bool  forward = true 
)
void cinder::Path2d::arc ( float  centerX,
float  centerY,
float  radius,
float  startRadians,
float  endRadians,
bool  forward = true 
)
void cinder::Path2d::arcTo ( const vec2 &  p,
const vec2 &  t,
float  radius 
)
void cinder::Path2d::arcTo ( float  x,
float  y,
float  tanX,
float  tanY,
float  radius 
)
void cinder::Path2d::close ( )

Closes the path, by drawing a straight line from the first to the last point. This is only legal as the last command.

bool cinder::Path2d::isClosed ( ) const
void cinder::Path2d::reverse ( )

Reverses the order of the path's points, inverting its winding order.

bool cinder::Path2d::empty ( ) const
void cinder::Path2d::clear ( )
size_t cinder::Path2d::getNumSegments ( ) const
size_t cinder::Path2d::getNumPoints ( ) const
vec2 cinder::Path2d::getPosition ( float  t) const

Returns the point on the curve at parameter t, which lies in the range [0,1]

vec2 cinder::Path2d::getSegmentPosition ( size_t  segment,
float  t 
) const

Returns the point in segment # segment in the range [0,getNumSegments()) at parameter t in the range [0,1]

vec2 cinder::Path2d::getTangent ( float  t) const

Returns the tangent on the curve at parameter t, which lies in the range [0,1]

vec2 cinder::Path2d::getSegmentTangent ( size_t  segment,
float  t 
) const

Returns the point in segment # segment in the range [0,getNumSegments()) at parameter t in the range [0,1]

void cinder::Path2d::getSegmentRelativeT ( float  t,
size_t *  segment,
float *  relativeT 
) const

Stores into segment the segment # associated with t, and if relativeT is not NULL, the t relative to its segment, in the range [0,1]

std::vector< vec2 > cinder::Path2d::subdivide ( float  approximationScale = 1.0f) const
void cinder::Path2d::subdivide ( std::vector< vec2 > *  resultPositions,
std::vector< vec2 > *  resultTangents,
float  approximationScale = 1.0f 
) const

if resultTangents aren't null then un-normalized tangents corresponding to resultPositions are calculated.

void cinder::Path2d::scale ( const vec2 &  amount,
vec2  scaleCenter = vec2() 
)

Scales the Path2d by amount.x on X and amount.y on Y around the center scaleCenter.

void cinder::Path2d::transform ( const mat3 &  matrix)

Transforms the Path2d by matrix.

Path2d cinder::Path2d::transformed ( const mat3 &  matrix) const

Returns a copy transformed by matrix.

const std::vector<vec2>& cinder::Path2d::getPoints ( ) const
std::vector<vec2>& cinder::Path2d::getPoints ( )
const vec2& cinder::Path2d::getPoint ( size_t  point) const
vec2& cinder::Path2d::getPoint ( size_t  point)
const vec2& cinder::Path2d::getCurrentPoint ( ) const
void cinder::Path2d::setPoint ( size_t  index,
const vec2 &  p 
)
SegmentType cinder::Path2d::getSegmentType ( size_t  segment) const
const std::vector<SegmentType>& cinder::Path2d::getSegments ( ) const
std::vector<SegmentType>& cinder::Path2d::getSegments ( )
void cinder::Path2d::removeSegment ( size_t  segment)
Rectf cinder::Path2d::calcBoundingBox ( ) const

Returns the bounding box around all control points. As with Shape2d, note this is not necessarily the bounding box of the Path's shape.

Rectf cinder::Path2d::calcPreciseBoundingBox ( ) const

Returns the precise bounding box around the curve itself. Slower to calculate than calcBoundingBox().

bool cinder::Path2d::contains ( const vec2 &  pt) const

Returns whether the point pt is contained within the boundaries of the path.

float cinder::Path2d::calcLength ( ) const

Calculates the length of the Path2d.

float cinder::Path2d::calcSegmentLength ( size_t  segment,
float  minT = 0,
float  maxT = 1 
) const

Calculates the length of a specific segment in the range [minT,maxT], where minT and maxT range from 0 to 1 and are relative to the segment.

float cinder::Path2d::calcNormalizedTime ( float  relativeTime,
bool  wrap = true,
float  tolerance = 1.0e-03f,
int  maxIterations = 16 
) const

Calculates the t value corresponding to relativeTime in the range [0,1) within epsilon of tolerance. For example, relativeTime of 0.5f returns the t-value corresponding to half the length. maxIterations dictates the number of refinement loop iterations allowed, setting an upper bound for worst-case performance. Consider a Path2dCalcCache if using frequently.

float cinder::Path2d::calcTimeForDistance ( float  distance,
bool  wrap = true,
float  tolerance = 1.0e-03f,
int  maxIterations = 16 
) const

Calculates a t-value corresponding to arc length distance. If wrap then the t-value loops inside the 0-1 range as distance exceeds the arc length. Consider a Path2dCalcCache if using frequently.

int cinder::Path2d::calcQuadraticBezierMonotoneRegions ( const vec2  p[3],
float  resultT[2] 
)
static
vec2 cinder::Path2d::calcQuadraticBezierPos ( const vec2  p[3],
float  t 
)
static
vec2 cinder::Path2d::calcQuadraticBezierDerivative ( const vec2  p[3],
float  t 
)
static
int cinder::Path2d::calcCubicBezierMonotoneRegions ( const vec2  p[4],
float  resultT[4] 
)
static
vec2 cinder::Path2d::calcCubicBezierPos ( const vec2  p[4],
float  t 
)
static
vec2 cinder::Path2d::calcCubicBezierDerivative ( const vec2  p[4],
float  t 
)
static
float cinder::Path2d::segmentSolveTimeForDistance ( size_t  segment,
float  segmentLength,
float  segmentRelativeDistance,
float  tolerance,
int  maxIterations 
) const

Solves the time corresponding to segmentRelativeDistance (a measure of arc length). Generally you should use calcNormalizedTime() or calcTimeForDistance() instead.

Friends And Related Function Documentation

friend class Shape2d
friend
friend class Path2dCalcCache
friend
std::ostream& operator<< ( std::ostream &  out,
const Path2d p 
)
friend

Member Data Documentation

const int cinder::Path2d::sSegmentTypePointCounts = { 0, 1, 2, 3, 0 }
static

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