path2d.c File Reference


Detailed Description

This file is in the public domain.

Definition in file path2d.c.

#include "path2d.h"

Go to the source code of this file.

Data Structures

struct  SEGITERATOR
struct  RECTITERATOR
struct  ELLIPSEITERATOR
struct  RRITERATOR
struct  PATHSEGITERATOR
struct  CURVEFLATSTATUS
struct  CURVEFLATTENER
struct  FLATPATHINTERNAL

Defines

#define PCV   0.77614237491539666
#define NCV   0.22385762508460333
#define NCV   0.22385762508460333
#define HORNERQUAD(x, a, b, c)   ( (a) + (x) * ( (b) + (x) * (c) ))
#define HORNERCUBIC(x, a, b, c, d)   ( (a) + (x) * ( (b) + (x) * ( (c) + (x) * (d) ) ))

Enumerations

enum  ArcInternalFlags { ArcCheckEndPoint = 1, ArcDrawLine = 2, ArcMoveTo = 4, ArcHaveEndCoords = 8 }
enum  CLOSEDPATHFLAGS { PathNewMoveTo = 0x01, PathEndOfPath = 0x02, PathMask = 0x07, PathHaveLineTo = 0x08 }

Functions

BOOL RectContainsPoint (RECTDBL *rc, double x, double y)
BOOL RectIntersectsRect (RECTDBL *rc, double x, double y, double x1, double y1)
BOOL RectContainsRect (RECTDBL *rc, double x, double y, double x1, double y1)
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.
double CubeRoot (double x)
double PointDistance (double x1, double y1, double x2, double y2)
double SegmentDistanceSq (double x0, double y0, double x1, double y1, double ptx, double pty)
double QuadFlatnessSq (double *c)
double CubicFlatnessSq (double *c)
void CubicCurveFromQuadratic (double *pSrc, double *pDst)
 Converts a quadratic curve into a cubic curve.
double PerpendicularDistance (double x0, double y0, double x1, double y1, double ptx, double pty)
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 * 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 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 PathAddSegment (ITEMARRAY *ia, PATHSEGMENT *ps)
 Adds a path segment to the path.
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 DebugOutFullPathSegment (FULLPATHSEGMENT *ps, LPCTSTR add)
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.
BOOL PathGetEndPoint (ITEMARRAY *ia, double *endpt)
 Finds the path's current end point.
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.
BOOL PathSegmentTransform (PATHSEGMENT *ps, MATRIX *xfm)
 Applies a transform matrix to a path segment.
static int SegIterator_GetWinding (LPVOID h)
static LPVOID SegIterator_Init (double *data, DWORD numpoints)
static void SegIterator_Free (LPVOID h)
static LPVOID LineIterator_Init (double *data)
static int LineIterator_Next (LPVOID h, PATHSEGMENT *ps)
static LPVOID QuadIterator_Init (double *data)
static int QuadIterator_Next (LPVOID h, PATHSEGMENT *ps)
static LPVOID CubicIterator_Init (double *data)
static int CubicIterator_Next (LPVOID h, PATHSEGMENT *ps)
static int RectPath_GetWinding (LPVOID h)
static LPVOID RectPath_Init (LPVOID data)
static void RectPath_Free (LPVOID h)
static int RectPath_Next (LPVOID h, PATHSEGMENT *ps)
static int EllipsePath_GetWinding (LPVOID h)
static LPVOID EllipsePath_Init (LPVOID data)
static void EllipsePath_Free (LPVOID h)
static int EllipsePath_Next (LPVOID handle, PATHSEGMENT *ps)
static int RoundRectPath_GetWinding (LPVOID h)
static LPVOID RoundRectPath_Init (LPVOID data)
static void RoundRectPath_Free (LPVOID h)
static int RoundRectPath_Next (LPVOID handle, PATHSEGMENT *ps)
static BOOL CubicCurveFromArc (double x0, double y0, double rx, double ry, double startangle, double sweepangle, double *P)
static double FixAngle (double radiusX, double radiusY, double angle)
static int CubicCurvesFromArc (double x, double y, double rx, double ry, double start, double sweep, double *vertices)
static BOOL PathAddArcInternal (ITEMARRAY *ia, ArcInternalFlags mode, double centerX, double centerY, double radiusX, double radiusY, double start, double sweep, double phi, double x0, double y0, double x, double y)
static BOOL PathAddSvgArcInternal (ITEMARRAY *ia, BOOL arcto, double x0, double y0, double x, double y, double rx, double ry, double phi, BOOL large_arc, BOOL sweep)
BOOL PathAddArcMultiSweep (ITEMARRAY *ia, double centerX, double centerY, double radiusX, double radiusY, double start, double sweep, double phi)
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 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 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.
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 EllipseContainsPoint (RECTDBL *rc, double x, double y)
BOOL EllipseContainsRect (RECTDBL *rc, double x0, double y0, double x1, double y1)
static int PathSegmentsNonZero_GetWinding (LPVOID h)
static int PathSegmentsEvenOdd_GetWinding (LPVOID h)
static LPVOID PathSegments_Init (LPVOID data)
static void PathSegments_Free (LPVOID h)
static int PathSegments_Next (LPVOID h, PATHSEGMENT *ps)
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 ClosedPathIteratorNext (PATHITERATOR *iter, LPVOID h, FULLPATHCONTEXT *fpc, FULLPATHSEGMENT *fps, MATRIX *matrix)
 An alternative path iterator where all subpaths are explicitly closed.
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.
static void CurveFlattenerPush (CURVEFLATTENER *f)
static LPVOID CurveFlattenerCreate (double flatness, int flatnessmode)
static void CurveFlattenerFree (LPVOID pf)
static void CurveFlattenerReset (LPVOID pf, FULLPATHSEGMENT *fps)
BOOL QuadFlatEnough (double *curve, double tolerance, double *endpt)
BOOL CubicFlatEnough (double *curve, double tolerance, double *endpt)
static BOOL CurveFlattenerNextLine (CURVEFLATTENER *f, double *line)
static void MidpointCubicToQuad (double *cubic, double *quad)
static BOOL CubicIteratorNextQuadAlt (CURVEFLATTENER *f, double *quad)
static BOOL CubicIteratorNextQuad (CURVEFLATTENER *f, double *quad)
static LPVOID FlatPathIterator_InitInternal (FLATPATHPARAMS *fpp, int mode)
static LPVOID FlatPathIterator_Init (FLATPATHPARAMS *fpp)
static LPVOID CubicToQuadIterator_Init (FLATPATHPARAMS *fpp)
static void FlatPathIterator_Free (LPVOID h)
static int FlatPathIterator_GetWinding (LPVOID h)
static int FlatPathIterator_Next (LPVOID h, PATHSEGMENT *seg)
static int CubicToQuadIterator_Next (LPVOID h, PATHSEGMENT *seg)
int SolveLinear (double c[2], double s[1])
 Solves a linear equation and finds its non-complex roots.
int SolveQuadratic (double eqn[3], double s[2])
 Solves a quadratic equation and finds its non-complex roots.
static double NewtonFixup (double s, double c0, double c1, double c2, double c3)
int SolveCubic (double c[4], double s[3])
 Solves a cubic equation and finds its non-complex roots.
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)
double EllipseArea (double radiusX, double radiusY, MATRIX *xfm)
static BOOL RectAccumulate (RECTDBL *prc, double x, double y, BOOL first)
static int CubicDerivatives (double *zeros, double cur, double cp0, double cp1, double end)
int PathGetBounds (PATHITERATOR *pcb, LPVOID data, MATRIX *xfm, RECTDBL *prc)
 Calculates a path's bounding box.

Variables

static double ctrlpts [4][6]
static double rrctrlpts []
static int rrindices []
static int rrtypes []
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 RectPath
 A path iterator that retrieves the path of a rectangle.
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 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.
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.


Define Documentation

#define HORNERCUBIC x,
a,
b,
c,
 )     ( (a) + (x) * ( (b) + (x) * ( (c) + (x) * (d) ) ))
 

Definition at line 2332 of file path2d.c.

#define HORNERQUAD x,
a,
b,
 )     ( (a) + (x) * ( (b) + (x) * (c) ))
 

Definition at line 2330 of file path2d.c.

#define NCV   0.22385762508460333
 

Definition at line 955 of file path2d.c.

#define NCV   0.22385762508460333
 

Definition at line 955 of file path2d.c.

#define PCV   0.77614237491539666
 

Definition at line 892 of file path2d.c.


Enumeration Type Documentation

enum ArcInternalFlags
 

Enumerator:
ArcCheckEndPoint 
ArcDrawLine 
ArcMoveTo 
ArcHaveEndCoords 

Definition at line 1168 of file path2d.c.

enum CLOSEDPATHFLAGS
 

Enumerator:
PathNewMoveTo 
PathEndOfPath 
PathMask 
PathHaveLineTo 

Definition at line 1532 of file path2d.c.


Function Documentation

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 CubeRoot double  x  )  [inline]
 

Definition at line 97 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.

static BOOL CubicCurveFromArc double  x0,
double  y0,
double  rx,
double  ry,
double  startangle,
double  sweepangle,
double *  P
[static]
 

Definition at line 1073 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.

static int CubicCurvesFromArc double  x,
double  y,
double  rx,
double  ry,
double  start,
double  sweep,
double *  vertices
[static]
 

Definition at line 1126 of file path2d.c.

static int CubicDerivatives double *  zeros,
double  cur,
double  cp0,
double  cp1,
double  end
[static]
 

Definition at line 2586 of file path2d.c.

BOOL CubicFlatEnough double *  curve,
double  tolerance,
double *  endpt
 

Definition at line 1835 of file path2d.c.

double CubicFlatnessSq double *  c  ) 
 

Definition at line 137 of file path2d.c.

static LPVOID CubicIterator_Init double *  data  )  [static]
 

Definition at line 801 of file path2d.c.

static int CubicIterator_Next LPVOID  h,
PATHSEGMENT ps
[static]
 

Definition at line 804 of file path2d.c.

static BOOL CubicIteratorNextQuad CURVEFLATTENER f,
double *  quad
[static]
 

Definition at line 2114 of file path2d.c.

static BOOL CubicIteratorNextQuadAlt CURVEFLATTENER f,
double *  quad
[static]
 

Definition at line 2048 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.

static LPVOID CubicToQuadIterator_Init FLATPATHPARAMS fpp  )  [static]
 

Definition at line 2238 of file path2d.c.

static int CubicToQuadIterator_Next LPVOID  h,
PATHSEGMENT seg
[static]
 

Definition at line 2285 of file path2d.c.

static LPVOID CurveFlattenerCreate double  flatness,
int  flatnessmode
[static]
 

Definition at line 1748 of file path2d.c.

static void CurveFlattenerFree LPVOID  pf  )  [static]
 

Definition at line 1766 of file path2d.c.

static BOOL CurveFlattenerNextLine CURVEFLATTENER f,
double *  line
[static]
 

Definition at line 1933 of file path2d.c.

static void CurveFlattenerPush CURVEFLATTENER f  )  [static]
 

Definition at line 1736 of file path2d.c.

static void CurveFlattenerReset LPVOID  pf,
FULLPATHSEGMENT fps
[static]
 

Definition at line 1775 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.

double EllipseArea double  radiusX,
double  radiusY,
MATRIX xfm
 

Definition at line 2571 of file path2d.c.

BOOL EllipseContainsPoint RECTDBL rc,
double  x,
double  y
 

Definition at line 1417 of file path2d.c.

BOOL EllipseContainsRect RECTDBL rc,
double  x0,
double  y0,
double  x1,
double  y1
 

Definition at line 1426 of file path2d.c.

static void EllipsePath_Free LPVOID  h  )  [static]
 

Definition at line 918 of file path2d.c.

static int EllipsePath_GetWinding LPVOID  h  )  [static]
 

Definition at line 900 of file path2d.c.

static LPVOID EllipsePath_Init LPVOID  data  )  [static]
 

Definition at line 903 of file path2d.c.

static int EllipsePath_Next LPVOID  handle,
PATHSEGMENT ps
[static]
 

Definition at line 921 of file path2d.c.

static double FixAngle double  radiusX,
double  radiusY,
double  angle
[static]
 

Definition at line 1099 of file path2d.c.

static void FlatPathIterator_Free LPVOID  h  )  [static]
 

Definition at line 2243 of file path2d.c.

static int FlatPathIterator_GetWinding LPVOID  h  )  [static]
 

Definition at line 2251 of file path2d.c.

static LPVOID FlatPathIterator_Init FLATPATHPARAMS fpp  )  [static]
 

Definition at line 2235 of file path2d.c.

static LPVOID FlatPathIterator_InitInternal FLATPATHPARAMS fpp,
int  mode
[static]
 

Definition at line 2209 of file path2d.c.

static int FlatPathIterator_Next LPVOID  h,
PATHSEGMENT seg
[static]
 

Definition at line 2256 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,