1 // Copyright 2013 Howling Moon Software. All rights reserved.
2 // See http://chipmunk2d.net/legal.php for more information.
3 
4 // Polylines are just arrays of vertexes.
5 // They are looped if the first vertex is equal to the last.
6 // cpPolyline structs are intended to be passed by value and destroyed when you are done with them.
7 typedef struct cpPolyline {
8   int count, capacity;
9   cpVect verts[];
10 } cpPolyline;
11 
12 /// Destroy and free a polyline instance.
13 CP_EXPORT void cpPolylineFree(cpPolyline *line);
14 
15 /// Returns true if the first vertex is equal to the last.
16 CP_EXPORT cpBool cpPolylineIsClosed(cpPolyline *line);
17 
18 /**
19 	Returns a copy of a polyline simplified by using the Douglas-Peucker algorithm.
20 	This works very well on smooth or gently curved shapes, but not well on straight edged or angular shapes.
21 */
22 CP_EXPORT cpPolyline *cpPolylineSimplifyCurves(cpPolyline *line, cpFloat tol);
23 
24 /**
25 	Returns a copy of a polyline simplified by discarding "flat" vertexes.
26 	This works well on straigt edged or angular shapes, not as well on smooth shapes.
27 */
28 CP_EXPORT cpPolyline *cpPolylineSimplifyVertexes(cpPolyline *line, cpFloat tol);
29 
30 /// Get the convex hull of a polyline as a looped polyline.
31 CP_EXPORT cpPolyline *cpPolylineToConvexHull(cpPolyline *line, cpFloat tol);
32 
33 
34 /// Polyline sets are collections of polylines, generally built by cpMarchSoft() or cpMarchHard().
35 typedef struct cpPolylineSet {
36   int count, capacity;
37   cpPolyline **lines;
38 } cpPolylineSet;
39 
40 /// Allocate a new polyline set.
41 CP_EXPORT cpPolylineSet *cpPolylineSetAlloc(void);
42 
43 /// Initialize a new polyline set.
44 CP_EXPORT cpPolylineSet *cpPolylineSetInit(cpPolylineSet *set);
45 
46 /// Allocate and initialize a polyline set.
47 CP_EXPORT cpPolylineSet *cpPolylineSetNew(void);
48 
49 /// Destroy a polyline set.
50 CP_EXPORT void cpPolylineSetDestroy(cpPolylineSet *set, cpBool freePolylines);
51 
52 CP_EXPORT /// Destroy and free a polyline set.
53 void cpPolylineSetFree(cpPolylineSet *set, cpBool freePolylines);
54 
55 /**
56 	Add a line segment to a polyline set.
57 	A segment will either start a new polyline, join two others, or add to or loop an existing polyline.
58 	This is mostly intended to be used as a callback directly from cpMarchSoft() or cpMarchHard().
59 */
60 CP_EXPORT void cpPolylineSetCollectSegment(cpVect v0, cpVect v1, cpPolylineSet *lines);
61 
62 /**
63 	Get an approximate convex decomposition from a polyline.
64 	Returns a cpPolylineSet of convex hulls that match the original shape to within 'tol'.
65 	NOTE: If the input is a self intersecting polygon, the output might end up overly simplified.
66 */
67 
68 CP_EXPORT cpPolylineSet *cpPolylineConvexDecomposition(cpPolyline *line, cpFloat tol);
69 
70 #define cpPolylineConvexDecomposition_BETA cpPolylineConvexDecomposition
71