path2d.h File Reference


Detailed Description

This file is in the public domain.

Definition in file path2d.h.

#include "user.h"
#include "matrix.h"
#include "itemarr.h"

Go to the source code of this file.

Data Structures

struct  PTDBL
 This structure holds data on the X and Y coordinates of a point, in double precision. More...
struct  RECTDBL
 This structure holds data on the location of a rectangle, in double precision. More...
struct  ROUNDRECT
 This structure holds data on the location of a rounded rectangle, in double precision. More...
struct  PATHSEGMENT
 This structure holds data on the ending points and other parameters of each path segment. More...
struct  FULLPATHSEGMENT
 This structure holds data on the starting and ending points and other parameters of each path segment. More...
struct  PATHITERATOR
struct  FULLPATHCONTEXT
struct  FLATPATHPARAMS
 This structure contains parameters for the iterators FlatPathIterator and CubicToQuadIterator. More...
struct  SVGARC
struct  CENTERARC

Defines

#define ISONE(value)   (abs(value-1.0)<2.22E-15)
#define ISZERO(value)   (abs(value)<2.22E-15)
#define DoubleIsFinite(x)   (abs(x)<=1.7976931348623157e+308)
#define FloatIsFinite(x)   (abs(x)<=3.402823E+38f)
#define RectDblToInt(rcdbl, rcint)
#define RectNormalize(rc, tmp)
#define RectIsEmpty(rc)   ((rc)->left>=(rc)->right||(rc)->top>=(rc)->bottom)
#define RectAddPoint(rc, x, y)
#define RectAddRect(rc, rc2)
#define PATH_MOVETO   1
#define PATH_LINETO   2
#define PATH_QUADTO   3
#define PATH_CUBICTO   4
#define PATH_CLOSE   5
#define WIND_NONZERO   1
#define WIND_EVENODD   2

Functions

double ModDouble (double x, double y)
int ModInt (int x, int y)
BOOL AreClose (double a, double b)
BOOL LessThan (double a, double b)
BOOL LessOrClose (double a, double b)
BOOL GreaterThan (double a, double b)
BOOL GreaterOrClose (double a, double b)
double SegmentDistanceSq (double x0, double y0, double x1, double y1, double ptx, double pty)
double PerpendicularDistance (double x0, double y0, double x1, double y1, double ptx, double pty)
double PointDistance (double x1, double y1, double x2, double y2)
void LineSubdivide (double *src, double *left, double *right, double t)
 Subdivides a line into two lines, at the parameter value _t_.
void QuadSubdivide (double *src, double *left, double *right, double t)
 Subdivides a quadratic curve into two curves, at the parameter value _t_.
void CubicSubdivide (double *src, double *left, double *right, double t)
 Subdivides a cubic curve into two curves, at the parameter value _t_.
double QuadFlatnessSq (double *c)
double CubicFlatnessSq (double *c)
void CubicCurveFromQuadratic (double *pSrc, double *pDst)
 Converts a quadratic curve into a cubic curve.
double QuadControlPolygonLength (double *qc)
double QuadChordLength (double *qc)
double QuadCalcLength (double *qc, double tolerance)
double CubicControlPolygonLength (double *qc)
double CubicChordLength (double *qc)
double CubicCalcLength (double *qc, double tolerance)
int SolveLinear (double c[2], double s[1])
 Solves a linear equation and finds its non-complex roots.
int SolveQuadratic (double c[3], double s[2])
 Solves a quadratic equation and finds its non-complex roots.
int SolveCubic (double c[4], double s[3])
 Solves a cubic equation and finds its non-complex roots.
BOOL PathMoveTo (ITEMARRAY *ia, double x, double y)
 Adds a "move to" command to the path.
BOOL PathAddPoint (ITEMARRAY *ia, double x, double y)
 Adds a "move to" command to the path, but only if its end point is different from the new position.
BOOL PathLineTo (ITEMARRAY *ia, double x, double y)
 Draws a line from the current position to a new one, starting at the path's current end point.
BOOL PathQuadTo (ITEMARRAY *ia, double x, double y, double x1, double y1)
 Adds a quadratic Bezier curve to the path, starting at the path's current end point.
BOOL PathCubicTo (ITEMARRAY *ia, double x, double y, double x1, double y1, double x2, double y2)
 Adds a cubic Bezier curve to the path, starting at the path's current end point.
BOOL PathSmoothQuadTo (ITEMARRAY *ia, double x, double y)
 Adds a quadratic Bezier curve to the path, starting at the path's current end point.
BOOL PathSmoothCubicTo (ITEMARRAY *ia, double x1, double y1, double x2, double y2)
 Adds a cubic Bezier curve to the path, starting at the path's current end point.
BOOL PathClose (ITEMARRAY *ia)
 Adds a "close path" command, where a straight line is drawn from the current position to the starting point.
BOOL PathGetEndPoint (ITEMARRAY *ia, double *endpt)
 Finds the path's current end point.
BOOL PathAddSegment (ITEMARRAY *ia, PATHSEGMENT *ps)
 Adds a path segment to the path.
BOOL PathAddArc (ITEMARRAY *ia, double centerX, double centerY, double radiusX, double radiusY, double start, double sweep, double phi)
 Adds an arc segment to the path, defined using center parameterization.
BOOL PathArcTo (ITEMARRAY *ia, double centerX, double centerY, double radiusX, double radiusY, double start, double sweep, double phi)
 Adds an arc segment to the path, defined using center parameterization, that is, where the arc is part of an ellipse defined using its center, radius, start and end angles, and rotation.
BOOL PathAddSvgArc (ITEMARRAY *ia, double x0, double x1, double x, double y, double rx, double ry, double phi, BOOL largeArc, BOOL sweep)
 Adds an arc segment to the path where the arc is defined as having a start and end point as well as additional parameters that define an imaginary ellipse, as in the SVG specification.
BOOL PathSvgArcTo (ITEMARRAY *ia, double x, double y, double rx, double ry, double phi, BOOL largeArc, BOOL sweep)
 Adds an arc segment to the path where the arc is defined as having a start and end point as well as additional parameters that define an imaginary ellipse, as in the SVG specification.
void PathCardinalSplineTo (ITEMARRAY *path, double *coords, LONG numpoints, double tension)
 Adds a cardinal spline to the path, starting with the path's current point.
void PathAddCardinalSpline (ITEMARRAY *path, double *coords, LONG numpoints, double tension, BOOL closefigure)
 Adds a cardinal spline to the path.
BOOL PathTransform (ITEMARRAY *path, MATRIX *xfm)
 Applies an affine transform to the path.
double * PathSegmentEndPoint (PATHSEGMENT *ps)
 Returns a pointer to the end point of the path segment _ps_, or NULL if the path segment has no end point.
BOOL PathSegmentTransform (PATHSEGMENT *ps, MATRIX *xfm)
 Applies a transform matrix to a path segment.
int PathGetBounds (PATHITERATOR *pcb, LPVOID data, MATRIX *xfm, RECTDBL *prc)
 Calculates a path's bounding box.
BOOL PathAppendPath (ITEMARRAY *ia, PATHITERATOR *pcb, LPVOID data, MATRIX *xfm, BOOL connect)
 Appends another path, in the form of a path iterator, to this path.
void DebugOutPathSegment (PATHSEGMENT *ps, LPCTSTR add)
 Displays output about a path segment to the debugger.
void DebugOutPathSegmentAsSvg (PATHSEGMENT *ps)
 Displays output about a path segment in SVG format to the debugger.
void DebugOutFullPathSegment (FULLPATHSEGMENT *ps, LPCTSTR add)
BOOL ViewSpaceCalcTransformEx (MATRIX *xfmDst, RECTDBL *rcViewport, RECTDBL *rcWindow, int align, int meetOrSlice)
 Calculates a transform matrix where units from one coordinate system are mapped to units in another coordinate system.
void FullPathContextInit (FULLPATHCONTEXT *fpc)
 Initializes a full path context for use in the iterator functions FullPathIteratorNext() and ClosedPathIteratorNext().
BOOL FullPathSegmentTransform (FULLPATHSEGMENT *ps, MATRIX *xfm)
 Applies a transform matrix to a full path segment.
void FullToPathSegment (FULLPATHSEGMENT *fullSegment, PATHSEGMENT *pathSegment)
int FullPathIteratorNext (PATHITERATOR *iter, LPVOID h, FULLPATHCONTEXT *fpc, FULLPATHSEGMENT *fps, MATRIX *matrix)
 An alternative path iterator that includes the starting points of each path segment.
int ClosedPathIteratorNext (PATHITERATOR *iter, LPVOID h, FULLPATHCONTEXT *fpc, FULLPATHSEGMENT *fps, MATRIX *matrix)
 An alternative path iterator where all subpaths are explicitly closed.

Variables

PATHITERATOR RectPath
 A path iterator that retrieves the path of a rectangle.
PATHITERATOR RoundRectPath
 A path iterator that retrieves the path of a rounded rectangle.
PATHITERATOR EllipsePath
 A path iterator that retrieves the path of an ellipse.
PATHITERATOR LinePath
 A path iterator that retrieves the path of a line.
PATHITERATOR QuadPath
 A path iterator that retrieves the path of a quadratic curve.
PATHITERATOR CubicPath
 A path iterator that retrieves the path of a cubic curve.
PATHITERATOR FlatPathIterator
 A path iterator that converts all curves in a path into lines.
PATHITERATOR CubicToQuadIterator
 A path iterator that converts all cubic curves in a path into quadratic curves.
PATHITERATOR PathSegmentsNonZero
 A path iterator that retrieves the segments of a path and uses the NONZERO fill rule.
PATHITERATOR PathSegmentsEvenOdd
 A path iterator that retrieves the segments of a path and uses the EVENODD fill rule.


Define Documentation

#define DoubleIsFinite  )     (abs(x)<=1.7976931348623157e+308)
 

Definition at line 111 of file path2d.h.

#define FloatIsFinite  )     (abs(x)<=3.402823E+38f)
 

Definition at line 112 of file path2d.h.

#define ISONE value   )     (abs(value-1.0)<2.22E-15)
 

Definition at line 109 of file path2d.h.

#define ISZERO value   )     (abs(value)<2.22E-15)
 

Definition at line 110 of file path2d.h.

#define PATH_CLOSE   5
 

Definition at line 191 of file path2d.h.

#define PATH_CUBICTO   4
 

Definition at line 190 of file path2d.h.

#define PATH_LINETO   2
 

Definition at line 188 of file path2d.h.

#define PATH_MOVETO   1
 

Definition at line 187 of file path2d.h.

#define PATH_QUADTO   3
 

Definition at line 189 of file path2d.h.

#define RectAddPoint rc,
x,
 ) 
 

Value:

do{(rc)->left=min((rc)->left,x);\
     (rc)->top=min((rc)->top,y);\
     (rc)->right=max((rc)->right,x);\
     (rc)->bottom=max((rc)->bottom,y);}while(0)

Definition at line 169 of file path2d.h.

#define RectAddRect rc,
rc2   ) 
 

Value:

do{\
     (rc)->left=min((rc)->left,(rc2)->left);\
     (rc)->top=min((rc)->top,(rc2)->top);\
     (rc)->right=max((rc)->right,(rc2)->left);\
     (rc)->bottom=max((rc)->bottom,(rc2)->top);\
     (rc)->left=min((rc)->left,(rc2)->right);\
     (rc)->top=min((rc)->top,(rc2)->bottom);\
     (rc)->right=max((rc)->right,(rc2)->right);\
     (rc)->bottom=max((rc)->bottom,(rc2)->bottom);\
  }while(0)

Definition at line 175 of file path2d.h.

#define RectDblToInt rcdbl,
rcint   ) 
 

Value:

do{(rcint)->left=floor((rcdbl)->left);\
     (rcint)->top=floor((rcdbl)->top);\
     (rcint)->right=ceil((rcdbl)->right);\
     (rcint)->bottom=ceil((rcdbl)->bottom);}while(0)

Definition at line 150 of file path2d.h.

#define RectIsEmpty rc   )     ((rc)->left>=(rc)->right||(rc)->top>=(rc)->bottom)
 

Definition at line 166 of file path2d.h.

#define RectNormalize rc,
tmp   ) 
 

Value:

do{\
   if((rc)->left>(rc)->right){\
    tmp=(rc)->left;(rc)->left=(rc)->right;(rc)->right=tmp;\
   }\
   if((rc)->top>(rc)->bottom){\
    tmp=(rc)->bottom;(rc)->bottom=(rc)->top;(rc)->top=tmp;\
   }\
  }while(0)

Definition at line 156 of file path2d.h.

#define WIND_EVENODD   2
 

Definition at line 194 of file path2d.h.

#define WIND_NONZERO   1
 

Definition at line 193 of file path2d.h.


Function Documentation

BOOL AreClose double  a,
double  b
[inline]
 

Definition at line 130 of file path2d.h.

int ClosedPathIteratorNext PATHITERATOR iter,
LPVOID  h,
FULLPATHCONTEXT fpc,
FULLPATHSEGMENT fps,
MATRIX matrix
 

An alternative path iterator where all subpaths are explicitly closed.

Parameters:
iter Pointer to a path iterator.
h Data handle created using the path iterator's Init function.
fpc Full path context (see FullPathContextInit).
fps Full path segment.
matrix A matrix to transform segments retrieved from the path iterator.

Definition at line 1539 of file path2d.c.

double CubicCalcLength double *  qc,
double  tolerance
 

Definition at line 2545 of file path2d.c.

double CubicChordLength double *  qc  ) 
 

Definition at line 2542 of file path2d.c.

double CubicControlPolygonLength double *  qc  ) 
 

Definition at line 2537 of file path2d.c.

void CubicCurveFromQuadratic double *  pSrc,
double *  pDst
 

Converts a quadratic curve into a cubic curve.

Parameters:
pSrc Source quadratic curve: three pairs of double-precision values specifying the X and Y values of the curve's start point, control point, and end point.
pDst Receives the coordinates of the destination cubic curve: four pairs of double-precision values specifying the X and Y values of the curve's start point, control points, and end point.

Definition at line 143 of file path2d.c.

double CubicFlatnessSq double *  c  ) 
 

Definition at line 137 of file path2d.c.

void CubicSubdivide double *  src,
double *  left,
double *  right,
double  t
 

Subdivides a cubic curve into two curves, at the parameter value _t_.

Parameters:
src Source curve: four pairs of double-precision values specifying the X and Y values of the curve's start point, control points, and end point.
left Receives the coordinates of the left-sided curve. This can be NULL.
right Receives the coordinates of the right-sided curve. This can be NULL.
t A value from 0 through 1 that specifies where to divide the curve.

Definition at line 238 of file path2d.c.

void DebugOutFullPathSegment FULLPATHSEGMENT ps,
LPCTSTR  add
 

Definition at line 477 of file path2d.c.

void DebugOutPathSegment PATHSEGMENT ps,
LPCTSTR  add
 

Displays output about a path segment to the debugger.

Definition at line 501 of file path2d.c.

void DebugOutPathSegmentAsSvg PATHSEGMENT ps  ) 
 

Displays output about a path segment in SVG format to the debugger.

No line breaks will be included.

Definition at line 527 of file path2d.c.

void FullPathContextInit FULLPATHCONTEXT fpc  ) 
 

Initializes a full path context for use in the iterator functions FullPathIteratorNext() and ClosedPathIteratorNext().

Definition at line 1491 of file path2d.c.

int FullPathIteratorNext PATHITERATOR iter,
LPVOID  h,
FULLPATHCONTEXT fpc,
FULLPATHSEGMENT fps,
MATRIX matrix
 

An alternative path iterator that includes the starting points of each path segment.

Parameters:
iter Pointer to a path iterator.
h Data handle created using the path iterator's Init function.
fpc Full path context (see FullPathContextInit).
fps Full path segment.
matrix A matrix to transform segments retrieved from the path iterator. This parameter can be NULL.

Definition at line 1651 of file path2d.c.

BOOL FullPathSegmentTransform FULLPATHSEGMENT ps,
MATRIX xfm
 

Applies a transform matrix to a full path segment.

Parameters:
ps Pointer to a full path segment.
xfm Transform to apply to the full path segment.
Returns:
TRUE if successful, FALSE otherwise.

Definition at line 1500 of file path2d.c.

void FullToPathSegment FULLPATHSEGMENT fullSegment,
PATHSEGMENT pathSegment
 

Definition at line 1524 of file path2d.c.

BOOL GreaterOrClose double  a,
double  b
[inline]
 

Definition at line 146 of file path2d.h.

BOOL GreaterThan double  a,
double  b
[inline]
 

Definition at line 142 of file path2d.h.

BOOL LessOrClose double  a,
double  b
[inline]
 

Definition at line 138 of file path2d.h.

BOOL LessThan double  a,
double  b
[inline]
 

Definition at line 134 of file path2d.h.

void LineSubdivide double *  src,
double *  left,
double *  right,
double  t
 

Subdivides a line into two lines, at the parameter value _t_.

Parameters:
src Source line: two pairs of double-precision values specifying the X and Y values of the line's end points.
left Receives the coordinates of the left-sided line. This can be NULL.
right Receives the coordinates of the right-sided line. This can be NULL.
t A value from 0 through 1 that specifies where to divide the line.

Definition at line 179 of file path2d.c.

double ModDouble double  x,
double  y
[inline]
 

Definition at line 115 of file path2d.h.

int ModInt int  x,
int  y
[inline]
 

Definition at line 122 of file path2d.h.

BOOL PathAddArc ITEMARRAY ia,
double  centerX,
double  centerY,
double  radiusX,
double  radiusY,
double  start,
double  sweep,
double  phi
 

Adds an arc segment to the path, defined using center parameterization.

Parameters:
ia Item array containing path segments.
centerX X coordinate for the center of the ellipse that the arc's points are on.
centerY Y coordinate for the center of the ellipse that the arc's points are on.
radiusX X-radius of the ellipse. The absolute value of this parameter will be used. If this value is 0, this function does nothing.
radiusY Y-radius of the ellipse. The absolute value of this parameter will be used. If this value is 0, this function does nothing.
start Starting angle of the arc, in degrees. The angle given here is adjusted modulo 360 degrees. 0 represents the 3-o'clock position, 90 represents the 6 o'clock position, and 180 represents the 9 o'clock position.
sweep Difference between the starting angle of the arc and the ending angle of the arc, in degrees. If this parameter is positive, the arc is drawn clockwise; otherwise, the angle is drawn counterclockwise. If the parameter is 360 or greater or is -360 or less, the result is a complete ellipse and the end of the arc becomes equal to its starting point.
phi Rotation of the ellipse about the X-axis, in degrees.
Returns:
TRUE if successful, FALSE otherwise.
Remarks:
In center parameterization, an arc is defined as part of an ellipse with a center, radius, start and end angles, and rotation. When the arc is added, this function converts the arc into cubic Bezier curves. Up to five path segments will be added to the path in this way.

Definition at line 1383 of file path2d.c.

void PathAddCardinalSpline ITEMARRAY path,
double *  coords,
LONG  numpoints,
double  tension,
BOOL  closefigure
 

Adds a cardinal spline to the path.

Parameters:
path Item array containing path segments.
coords An array of pairs of Double values specifying the X and Y values of each end point in the curve. The first point in the array specifies the curve's starting point.
numpoints The number of points (pairs of coordinates) in the _coords_ array. This value must be 2 or greater.
tension Specifies the tension of the curve.
closefigure If TRUE, this function draws a closed curve.

Definition at line 639 of file path2d.c.

BOOL PathAddPoint ITEMARRAY ia,
double  x,
double  y
 

Adds a "move to" command to the path, but only if its end point is different from the new position.

Parameters:
ia Item array containing path segments.
x X coordinate of a point.
y Y coordinate of a point.
Returns:
FALSE if out of memory or the path is invalid, TRUE otherwise.

Definition at line 311 of file path2d.c.

BOOL PathAddSegment ITEMARRAY ia,
PATHSEGMENT ps
 

Adds a path segment to the path.

Parameters:
ia Item array containing path segments.
ps Path segment.
Returns:
TRUE if successful. If the function fails, for example, if the path is NULL, returns FALSE.

Definition at line 404 of file path2d.c.

BOOL PathAddSvgArc ITEMARRAY ia,
double  x0,
double  x1,
double  x,
double  y,
double  rx,
double  ry,
double  phi,
BOOL  largeArc,
BOOL  sweep
 

Adds an arc segment to the path where the arc is defined as having a start and end point as well as additional parameters that define an imaginary ellipse, as in the SVG specification.

When the arc is added, this function converts the arc into cubic Bezier curves.

Parameters:
ia Item array containing path segments.
x0 X coordinate of the arc's starting point. This function will add a MoveTo command for the arc's starting point before drawing.
x1 Y coordinate of the arc's starting point.
x X coordinate of the arc's end point. If the arc's starting and ending points are equal, then the function draws nothing, but still returns TRUE for success.
y Y coordinate of the arc's end point.
radiusX X-radius of the ellipse. The absolute value of this parameter will be used. If this value is 0, then this function will draw a straight line.
radiusY Y-radius of the ellipse. The absolute value of this parameter will be used. If this value is 0, then this function will draw a straight line.
phi Rotation of the ellipse about the X axis, in degrees. The value of this parameter will be adjusted modulo 360 degrees.
largeArc In most cases, there are four solutions for ellipse arcs that satisfy the parameters given above. Two of these solutions have larger arc sweeps than the other two. If this parameter is TRUE, one of the two solutions with larger arc sweeps will be used.
sweep Two of the four arc solutions are drawn counterclockwise, and the other two are drawn clockwise. If this parameter is TRUE, the arc is drawn clockwise, or in a "positive angle" direction.
Returns:
TRUE if successful, FALSE otherwise.

Definition at line 1406 of file path2d.c.

BOOL PathAppendPath ITEMARRAY ia,
PATHITERATOR pcb,
LPVOID  data,
MATRIX xfm,
BOOL  connect
 

Appends another path, in the form of a path iterator, to this path.

Definition at line 424 of file path2d.c.

BOOL PathArcTo ITEMARRAY ia,
double  centerX,
double  centerY,
double  radiusX,
double  radiusY,
double  start,
double  sweep,
double  phi
 

Adds an arc segment to the path, defined using center parameterization, that is, where the arc is part of an ellipse defined using its center, radius, start and end angles, and rotation.

When the arc is added, this function converts the arc into cubic Bezier curves. Before drawing the arc, this function will draw a line from the current position to the starting point of the arc. See PathAddArc() for information on the parameters and return value.

Definition at line 1366 of file path2d.c.

void PathCardinalSplineTo ITEMARRAY path,
double *  coords,
LONG  numpoints,
double  tension
 

Adds a cardinal spline to the path, starting with the path's current point.

Parameters:
path Item array containing path segments.
coords An array of pairs of Double values specifying the X and Y values of each end point in the curve.
numpoints The number of points (pairs of coordinates) in the _coords_ array. This value must be 1 or greater.
tension Specifies the tension of the curve. "A tension of 0 corresponds to infinite physical tension, forcing the curve to take the shortest way (straight lines) between points. A tension of 1 corresponds to no physical tension, allowing the spline to take the path of least total bend. With tension values greater than 1, the curve behaves like a compressed spring, pushed to take a longer path." [http://msdn2.microsoft.com/en-us/library/4cf6we5y.aspx]

Definition at line 594 of file path2d.c.

BOOL PathClose ITEMARRAY ia  ) 
 

Adds a "close path" command, where a straight line is drawn from the current position to the starting point.

Due to stroking, closing a path in this way is distinct from adding a line to the starting point "manually".

Parameters:
ia Item array containing path segments.
Returns:
TRUE if successful, FALSE if out of memory or the path is empty.

Definition at line 393 of file path2d.c.

BOOL PathCubicTo ITEMARRAY ia,
double  x,
double  y,
double  x1,
double  y1,
double  x2,
double  y2
 

Adds a cubic Bezier curve to the path, starting at the path's current end point.

Parameters:
ia Item array containing path segments.
x X coordinate of the curve's first control point.
y Y coordinate of the curve's first control point.
x1 X coordinate of the curve's second control point.
y1 Y coordinate of the curve's second control point.
x2 X coordinate of the curve's end point.
y2 Y coordinate of the curve's end point.
Returns:
TRUE if successful, FALSE if out of memory or the path is empty.

Definition at line 343 of file path2d.c.

int PathGetBounds PATHITERATOR pcb,
LPVOID  data,
MATRIX xfm,
RECTDBL prc
 

Calculates a path's bound