File: ChipmunkAutoGeometry.h

package info (click to toggle)
chipmunk 7.0.3-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,968 kB
  • sloc: ansic: 29,265; objc: 4,313; ruby: 409; makefile: 10; sh: 1
file content (136 lines) | stat: -rw-r--r-- 4,347 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
// Copyright 2013 Howling Moon Software. All rights reserved.
// See http://chipmunk2d.net/legal.php for more information.

#import "ObjectiveChipmunk/ObjectiveChipmunk.h"

#import "chipmunk/cpMarch.h"
#import "chipmunk/cpPolyline.h"

@class ChipmunkPolylineSet;

/// Wrapper for the cpPolyline type.
@interface ChipmunkPolyline : NSObject {
@private
	cpPolyline *_line;
	cpFloat _area;
}

-(id)initWithPolyline:(cpPolyline *)line;
+(ChipmunkPolyline *)fromPolyline:(cpPolyline *)line;

/// Returns true if the first and last vertex are equal.
@property(nonatomic, readonly) bool isClosed;

/// Returns the signed area of the polyline calculated by cpAreaForPoly.
/// Non-closed polylines return an area of 0.
@property(nonatomic, readonly) cpFloat area;

/// Centroid of the polyline calculated by cpCentroidForPoly.
/// It is an error to call this on a non-closed polyline.
@property(nonatomic, readonly) cpVect centroid;

/// Calculates the moment of inertia for a closed polyline with the given mass and offset.
-(cpFloat)momentForMass:(cpFloat)mass offset:(cpVect)offset;


/// Vertex count.
@property(nonatomic, readonly) NSUInteger count;

/// Array of vertexes.
@property(nonatomic, readonly) const cpVect *verts;

/**
	Returns a copy of a polyline simplified by using the Douglas-Peucker algorithm.
	This works very well on smooth or gently curved shapes, but not well on straight edged or angular shapes.
*/
-(ChipmunkPolyline *)simplifyCurves:(cpFloat)tolerance;

/**
	Returns a copy of a polyline simplified by discarding "flat" vertexes.
	This works well on straigt edged or angular shapes, not as well on smooth shapes.
*/
-(ChipmunkPolyline *)simplifyVertexes:(cpFloat)tolerance;

/// Generate a convex hull that contains a polyline. (closed or not)
-(ChipmunkPolyline *)toConvexHull;

/// Generate an approximate convex hull that contains a polyline. (closed or not)
-(ChipmunkPolyline *)toConvexHull:(cpFloat)tolerance;

/// Generate a set of convex hulls for a polyline.
/// See the note on cpPolylineConvexDecomposition_BETA() for more information.
-(ChipmunkPolylineSet *)toConvexHulls_BETA:(cpFloat)tolerance;

/// Create an array of segments for each segment in this polyline.
-(NSArray *)asChipmunkSegmentsWithBody:(ChipmunkBody *)body radius:(cpFloat)radius offset:(cpVect)offset;

/// Create a ChipmunkPolyShape from this polyline. (Must be convex!)
-(ChipmunkPolyShape *)asChipmunkPolyShapeWithBody:(ChipmunkBody *)body transform:(cpTransform)transform radius:(cpFloat)radius;

@end


/// Wrapper for the cpPolylineSet type.
@interface ChipmunkPolylineSet : NSObject<NSFastEnumeration> {
@private
	NSMutableArray *_lines;
}

-(id)initWithPolylineSet:(cpPolylineSet *)set;
+(ChipmunkPolylineSet *)fromPolylineSet:(cpPolylineSet *)set;

@property(nonatomic, readonly) NSUInteger count;

-(ChipmunkPolyline *)lineAtIndex:(NSUInteger)index;

@end


/**
	A sampler is an object that provides a basis function to build shapes from.
	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.
*/
@interface ChipmunkAbstractSampler : NSObject {
@protected
	cpFloat _marchThreshold;
	cpMarchSampleFunc _sampleFunc;
}

/// The threshold passed to the cpMarch*() functions.
/// The value of the contour you want to extract.
@property(nonatomic, assign) cpFloat marchThreshold;

/// Get the primitive cpMarchSampleFunc used by this sampler.
@property(nonatomic, readonly) cpMarchSampleFunc sampleFunc;

/// Designated initializer.
-(id)initWithSamplingFunction:(cpMarchSampleFunc)sampleFunc;

/// Sample at a specific point.
-(cpFloat)sample:(cpVect)pos;

/// March a certain area of the sampler.
-(ChipmunkPolylineSet *)march:(cpBB)bb xSamples:(NSUInteger)xSamples ySamples:(NSUInteger)ySamples hard:(bool)hard;

@end



/// A simple sampler type that wraps a block as it's sampling function.
typedef cpFloat (^ChipmunkMarchSampleBlock)(cpVect point);

@interface ChipmunkBlockSampler : ChipmunkAbstractSampler {
	ChipmunkMarchSampleBlock _block;
}

/// Initializes the sampler using a copy of the passed block.
-(id)initWithBlock:(ChipmunkMarchSampleBlock)block;
+(ChipmunkBlockSampler *)samplerWithBlock:(ChipmunkMarchSampleBlock)block;

@end



#import "ChipmunkImageSampler.h"
#import "ChipmunkPointCloudSampler.h"
#import "ChipmunkTileCache.h"