1 // Copyright 2013 Howling Moon Software. All rights reserved.
2 // See http://chipmunk2d.net/legal.php for more information.
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 {
12 /// Destroy and free a polyline instance.
13 CP_EXPORT void cpPolylineFree(cpPolyline *line);
15 /// Returns true if the first vertex is equal to the last.
16 CP_EXPORT cpBool cpPolylineIsClosed(cpPolyline *line);
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.
22 CP_EXPORT cpPolyline *cpPolylineSimplifyCurves(cpPolyline *line, cpFloat tol);
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.
28 CP_EXPORT cpPolyline *cpPolylineSimplifyVertexes(cpPolyline *line, cpFloat tol);
30 /// Get the convex hull of a polyline as a looped polyline.
31 CP_EXPORT cpPolyline *cpPolylineToConvexHull(cpPolyline *line, cpFloat tol);
34 /// Polyline sets are collections of polylines, generally built by cpMarchSoft() or cpMarchHard().
35 typedef struct cpPolylineSet {
40 /// Allocate a new polyline set.
41 CP_EXPORT cpPolylineSet *cpPolylineSetAlloc(void);
43 /// Initialize a new polyline set.
44 CP_EXPORT cpPolylineSet *cpPolylineSetInit(cpPolylineSet *set);
46 /// Allocate and initialize a polyline set.
47 CP_EXPORT cpPolylineSet *cpPolylineSetNew(void);
49 /// Destroy a polyline set.
50 CP_EXPORT void cpPolylineSetDestroy(cpPolylineSet *set, cpBool freePolylines);
52 /// Destroy and free a polyline set.
53 CP_EXPORT void cpPolylineSetFree(cpPolylineSet *set, cpBool freePolylines);
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().
60 CP_EXPORT void cpPolylineSetCollectSegment(cpVect v0, cpVect v1, cpPolylineSet *lines);
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.
68 CP_EXPORT cpPolylineSet *cpPolylineConvexDecomposition(cpPolyline *line, cpFloat tol);
70 #define cpPolylineConvexDecomposition_BETA cpPolylineConvexDecomposition