[dali_2.3.21] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-physics / third-party / chipmunk2d / objectivec / include / ObjectiveChipmunk / ChipmunkAutoGeometry.h
1 // Copyright 2013 Howling Moon Software. All rights reserved.
2 // See http://chipmunk2d.net/legal.php for more information.
3
4 #import "ObjectiveChipmunk/ObjectiveChipmunk.h"
5
6 #import "chipmunk/cpMarch.h"
7 #import "chipmunk/cpPolyline.h"
8
9 @class ChipmunkPolylineSet;
10
11 /// Wrapper for the cpPolyline type.
12 @interface ChipmunkPolyline : NSObject {
13 @private
14         cpPolyline *_line;
15         cpFloat _area;
16 }
17
18 -(id)initWithPolyline:(cpPolyline *)line;
19 +(ChipmunkPolyline *)fromPolyline:(cpPolyline *)line;
20
21 /// Returns true if the first and last vertex are equal.
22 @property(nonatomic, readonly) bool isClosed;
23
24 /// Returns the signed area of the polyline calculated by cpAreaForPoly.
25 /// Non-closed polylines return an area of 0.
26 @property(nonatomic, readonly) cpFloat area;
27
28 /// Centroid of the polyline calculated by cpCentroidForPoly.
29 /// It is an error to call this on a non-closed polyline.
30 @property(nonatomic, readonly) cpVect centroid;
31
32 /// Calculates the moment of inertia for a closed polyline with the given mass and offset.
33 -(cpFloat)momentForMass:(cpFloat)mass offset:(cpVect)offset;
34
35
36 /// Vertex count.
37 @property(nonatomic, readonly) NSUInteger count;
38
39 /// Array of vertexes.
40 @property(nonatomic, readonly) const cpVect *verts;
41
42 /**
43         Returns a copy of a polyline simplified by using the Douglas-Peucker algorithm.
44         This works very well on smooth or gently curved shapes, but not well on straight edged or angular shapes.
45 */
46 -(ChipmunkPolyline *)simplifyCurves:(cpFloat)tolerance;
47
48 /**
49         Returns a copy of a polyline simplified by discarding "flat" vertexes.
50         This works well on straigt edged or angular shapes, not as well on smooth shapes.
51 */
52 -(ChipmunkPolyline *)simplifyVertexes:(cpFloat)tolerance;
53
54 /// Generate a convex hull that contains a polyline. (closed or not)
55 -(ChipmunkPolyline *)toConvexHull;
56
57 /// Generate an approximate convex hull that contains a polyline. (closed or not)
58 -(ChipmunkPolyline *)toConvexHull:(cpFloat)tolerance;
59
60 /// Generate a set of convex hulls for a polyline.
61 /// See the note on cpPolylineConvexDecomposition_BETA() for more information.
62 -(ChipmunkPolylineSet *)toConvexHulls_BETA:(cpFloat)tolerance;
63
64 /// Create an array of segments for each segment in this polyline.
65 -(NSArray *)asChipmunkSegmentsWithBody:(ChipmunkBody *)body radius:(cpFloat)radius offset:(cpVect)offset;
66
67 /// Create a ChipmunkPolyShape from this polyline. (Must be convex!)
68 -(ChipmunkPolyShape *)asChipmunkPolyShapeWithBody:(ChipmunkBody *)body transform:(cpTransform)transform radius:(cpFloat)radius;
69
70 @end
71
72
73 /// Wrapper for the cpPolylineSet type.
74 @interface ChipmunkPolylineSet : NSObject<NSFastEnumeration> {
75 @private
76         NSMutableArray *_lines;
77 }
78
79 -(id)initWithPolylineSet:(cpPolylineSet *)set;
80 +(ChipmunkPolylineSet *)fromPolylineSet:(cpPolylineSet *)set;
81
82 @property(nonatomic, readonly) NSUInteger count;
83
84 -(ChipmunkPolyline *)lineAtIndex:(NSUInteger)index;
85
86 @end
87
88
89 /**
90         A sampler is an object that provides a basis function to build shapes from.
91         This can be from a block of pixel data (loaded from a file, or dumped from the screen), or even a mathematical function such as Perlin noise.
92 */
93 @interface ChipmunkAbstractSampler : NSObject {
94 @protected
95         cpFloat _marchThreshold;
96         cpMarchSampleFunc _sampleFunc;
97 }
98
99 /// The threshold passed to the cpMarch*() functions.
100 /// The value of the contour you want to extract.
101 @property(nonatomic, assign) cpFloat marchThreshold;
102
103 /// Get the primitive cpMarchSampleFunc used by this sampler.
104 @property(nonatomic, readonly) cpMarchSampleFunc sampleFunc;
105
106 /// Designated initializer.
107 -(id)initWithSamplingFunction:(cpMarchSampleFunc)sampleFunc;
108
109 /// Sample at a specific point.
110 -(cpFloat)sample:(cpVect)pos;
111
112 /// March a certain area of the sampler.
113 -(ChipmunkPolylineSet *)march:(cpBB)bb xSamples:(NSUInteger)xSamples ySamples:(NSUInteger)ySamples hard:(bool)hard;
114
115 @end
116
117
118
119 /// A simple sampler type that wraps a block as it's sampling function.
120 typedef cpFloat (^ChipmunkMarchSampleBlock)(cpVect point);
121
122 @interface ChipmunkBlockSampler : ChipmunkAbstractSampler {
123         ChipmunkMarchSampleBlock _block;
124 }
125
126 /// Initializes the sampler using a copy of the passed block.
127 -(id)initWithBlock:(ChipmunkMarchSampleBlock)block;
128 +(ChipmunkBlockSampler *)samplerWithBlock:(ChipmunkMarchSampleBlock)block;
129
130 @end
131
132
133
134 #import "ChipmunkImageSampler.h"
135 #import "ChipmunkPointCloudSampler.h"
136 #import "ChipmunkTileCache.h"