Munk2D Documentation  8.x.x
Loading...
Searching...
No Matches
chipmunk_ffi.h
1/* Copyright (c) 2025 Victor Blomqvist
2 * Copyright (c) 2007-2024 Scott Lembcke and Howling Moon Software
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 * SOFTWARE.
21*/
22
23#ifdef CHIPMUNK_FFI
24
25// Create non static inlined copies of Chipmunk functions, useful for working with dynamic FFIs
26// For many languages, it may be faster to reimplement these functions natively instead.
27// Note: This file should only be included by chipmunk.c.
28
29#ifdef _MSC_VER
30 #if _MSC_VER >= 1600
31 #define MAKE_REF(name) CP_EXPORT decltype(name) *_##name = name
32 #else
33 #define MAKE_REF(name)
34 #endif
35#else
36 #define MAKE_REF(name) __typeof__(name) *_##name = name
37#endif
38
39#ifdef __cplusplus
40extern "C" {
41#endif
42
43MAKE_REF(cpv); // makes a variable named _cpv that contains the function pointer for cpv()
44MAKE_REF(cpveql);
45MAKE_REF(cpvadd);
46MAKE_REF(cpvneg);
47MAKE_REF(cpvsub);
48MAKE_REF(cpvmult);
49MAKE_REF(cpvdot);
50MAKE_REF(cpvcross);
51MAKE_REF(cpvperp);
52MAKE_REF(cpvrperp);
53MAKE_REF(cpvproject);
54MAKE_REF(cpvforangle);
55MAKE_REF(cpvtoangle);
56MAKE_REF(cpvrotate);
57MAKE_REF(cpvunrotate);
58MAKE_REF(cpvlengthsq);
59MAKE_REF(cpvlength);
60MAKE_REF(cpvlerp);
61MAKE_REF(cpvnormalize);
62MAKE_REF(cpvclamp);
63MAKE_REF(cpvlerpconst);
64MAKE_REF(cpvdist);
65MAKE_REF(cpvdistsq);
66MAKE_REF(cpvnear);
67
68MAKE_REF(cpfmax);
69MAKE_REF(cpfmin);
70MAKE_REF(cpfabs);
71MAKE_REF(cpfclamp);
72MAKE_REF(cpflerp);
73MAKE_REF(cpflerpconst);
74
75MAKE_REF(cpBBNew);
76MAKE_REF(cpBBNewForExtents);
77MAKE_REF(cpBBNewForCircle);
78MAKE_REF(cpBBIntersects);
79MAKE_REF(cpBBContainsBB);
80MAKE_REF(cpBBContainsVect);
81MAKE_REF(cpBBMerge);
82MAKE_REF(cpBBExpand);
83MAKE_REF(cpBBCenter);
84MAKE_REF(cpBBArea);
85MAKE_REF(cpBBMergedArea);
86MAKE_REF(cpBBSegmentQuery);
87MAKE_REF(cpBBIntersectsSegment);
88MAKE_REF(cpBBClampVect);
89
90MAKE_REF(cpSpatialIndexDestroy);
91MAKE_REF(cpSpatialIndexCount);
92MAKE_REF(cpSpatialIndexEach);
94MAKE_REF(cpSpatialIndexInsert);
95MAKE_REF(cpSpatialIndexRemove);
96MAKE_REF(cpSpatialIndexReindex);
99MAKE_REF(cpSpatialIndexQuery);
101
102#ifdef __cplusplus
103}
104#endif
105
106#endif
static cpFloat cpflerpconst(cpFloat f1, cpFloat f2, cpFloat d)
Linearly interpolate from f1 to f2 by no more than d.
Definition chipmunk_types.h:158
static cpFloat cpfclamp(cpFloat f, cpFloat min, cpFloat max)
Clamp f to be between min and max.
Definition chipmunk_types.h:138
static cpFloat cpfabs(cpFloat f)
Return the absolute value of a cpFloat.
Definition chipmunk_types.h:132
static cpFloat cpflerp(cpFloat f1, cpFloat f2, cpFloat t)
Linearly interpolate (or extrapolate) between f1 and f2 by t percent.
Definition chipmunk_types.h:152
static cpFloat cpfmin(cpFloat a, cpFloat b)
Return the min of two cpFloats.
Definition chipmunk_types.h:126
static cpFloat cpfmax(cpFloat a, cpFloat b)
Return the max of two cpFloats.
Definition chipmunk_types.h:120
static cpBB cpBBNewForExtents(const cpVect c, const cpFloat hw, const cpFloat hh)
Constructs a cpBB centered on a point with the given extents (half sizes).
Definition cpBB.h:47
static cpBB cpBBNew(const cpFloat l, const cpFloat b, const cpFloat r, const cpFloat t)
Convenience constructor for cpBB structs.
Definition cpBB.h:39
static cpVect cpBBCenter(cpBB bb)
Returns the center of a bounding box.
Definition cpBB.h:98
static cpBool cpBBIntersectsSegment(cpBB bb, cpVect a, cpVect b)
Return true if the bounding box intersects the line segment with ends a and b.
Definition cpBB.h:147
static cpFloat cpBBMergedArea(cpBB a, cpBB b)
Merges a and b and returns the area of the merged bounding box.
Definition cpBB.h:110
static cpVect cpBBClampVect(const cpBB bb, const cpVect v)
Clamp a vector to a bounding box.
Definition cpBB.h:154
static cpBool cpBBIntersects(const cpBB a, const cpBB b)
Returns true if a and b intersect.
Definition cpBB.h:59
static cpBB cpBBMerge(const cpBB a, const cpBB b)
Returns a bounding box that holds both bounding boxes.
Definition cpBB.h:77
static cpBB cpBBExpand(const cpBB bb, const cpVect v)
Returns a bounding box that holds both bb and v.
Definition cpBB.h:87
static cpFloat cpBBArea(cpBB bb)
Returns the area of the bounding box.
Definition cpBB.h:104
static cpBool cpBBContainsBB(const cpBB bb, const cpBB other)
Returns true if other lies completely within bb.
Definition cpBB.h:65
static cpBool cpBBContainsVect(const cpBB bb, const cpVect v)
Returns true if bb contains v.
Definition cpBB.h:71
static cpFloat cpBBSegmentQuery(cpBB bb, cpVect a, cpVect b)
Returns the fraction along the segment query the cpBB is hit. Returns INFINITY if it doesn't hit.
Definition cpBB.h:116
static cpBB cpBBNewForCircle(const cpVect p, const cpFloat r)
Constructs a cpBB for a circle with the given position and radius.
Definition cpBB.h:53
static void cpSpatialIndexReindexQuery(cpSpatialIndex *index, cpSpatialIndexQueryFunc func, void *data)
Simultaneously reindex and find all colliding objects.
Definition cpSpatialIndex.h:223
static void cpSpatialIndexReindexObject(cpSpatialIndex *index, void *obj, cpHashValue hashid)
Reindex a single object in the spatial index.
Definition cpSpatialIndex.h:203
static void cpSpatialIndexRemove(cpSpatialIndex *index, void *obj, cpHashValue hashid)
Remove an object from a spatial index.
Definition cpSpatialIndex.h:191
static void cpSpatialIndexReindex(cpSpatialIndex *index)
Perform a full reindex of a spatial index.
Definition cpSpatialIndex.h:197
static void cpSpatialIndexInsert(cpSpatialIndex *index, void *obj, cpHashValue hashid)
Add an object to a spatial index.
Definition cpSpatialIndex.h:184
static int cpSpatialIndexCount(cpSpatialIndex *index)
Get the number of objects in the spatial index.
Definition cpSpatialIndex.h:164
static void cpSpatialIndexDestroy(cpSpatialIndex *index)
Destroy a spatial index.
Definition cpSpatialIndex.h:158
static void cpSpatialIndexQuery(cpSpatialIndex *index, void *obj, cpBB bb, cpSpatialIndexQueryFunc func, void *data)
Perform a rectangle query against the spatial index, calling func for each potential match.
Definition cpSpatialIndex.h:209
static cpBool cpSpatialIndexContains(cpSpatialIndex *index, void *obj, cpHashValue hashid)
Returns true if the spatial index contains the given object.
Definition cpSpatialIndex.h:177
static void cpSpatialIndexSegmentQuery(cpSpatialIndex *index, void *obj, cpVect a, cpVect b, cpFloat t_exit, cpSpatialIndexSegmentQueryFunc func, void *data)
Perform a segment query against the spatial index, calling func for each potential match.
Definition cpSpatialIndex.h:215
static void cpSpatialIndexEach(cpSpatialIndex *index, cpSpatialIndexIteratorFunc func, void *data)
Iterate the objects in the spatial index. func will be called once for each object.
Definition cpSpatialIndex.h:170
static cpFloat cpvdist(const cpVect v1, const cpVect v2)
Returns the distance between v1 and v2.
Definition cpVect.h:192
static cpVect cpvrperp(const cpVect v)
Returns a perpendicular vector. (-90 degree rotation)
Definition cpVect.h:93
static cpVect cpvnormalize(const cpVect v)
Returns a normalized copy of v.
Definition cpVect.h:147
static cpVect cpvadd(const cpVect v1, const cpVect v2)
Add two vectors.
Definition cpVect.h:49
static cpVect cpvclamp(const cpVect v, const cpFloat len)
Clamp v to length len.
Definition cpVect.h:180
static cpBool cpvnear(const cpVect v1, const cpVect v2, const cpFloat dist)
Returns true if the distance between v1 and v2 is less than dist.
Definition cpVect.h:204
static cpFloat cpvdot(const cpVect v1, const cpVect v2)
Vector dot product.
Definition cpVect.h:73
static cpVect cpvmult(const cpVect v, const cpFloat s)
Scalar multiplication.
Definition cpVect.h:67
static cpVect cpv(const cpFloat x, const cpFloat y)
Convenience constructor for cpVect structs.
Definition cpVect.h:36
static cpFloat cpvtoangle(const cpVect v)
Returns the angular direction v is pointing in (in radians).
Definition cpVect.h:111
static cpFloat cpvlength(const cpVect v)
Returns the length of v.
Definition cpVect.h:135
static cpVect cpvlerpconst(cpVect v1, cpVect v2, cpFloat d)
Linearly interpolate between v1 towards v2 by distance d.
Definition cpVect.h:186
static cpVect cpvneg(const cpVect v)
Negate a vector.
Definition cpVect.h:61
static cpVect cpvlerp(const cpVect v1, const cpVect v2, const cpFloat t)
Linearly interpolate between v1 and v2.
Definition cpVect.h:141
static cpVect cpvunrotate(const cpVect v1, const cpVect v2)
Inverse of cpvrotate().
Definition cpVect.h:123
static cpVect cpvperp(const cpVect v)
Returns a perpendicular vector. (90 degree rotation)
Definition cpVect.h:87
static cpVect cpvrotate(const cpVect v1, const cpVect v2)
Uses complex number multiplication to rotate v1 by v2. Scaling will occur if v1 is not a unit vector.
Definition cpVect.h:117
static cpFloat cpvdistsq(const cpVect v1, const cpVect v2)
Returns the squared distance between v1 and v2. Faster than cpvdist() when you only need to compare d...
Definition cpVect.h:198
static cpFloat cpvlengthsq(const cpVect v)
Returns the squared length of v. Faster than cpvlength() when you only need to compare lengths.
Definition cpVect.h:129
static cpBool cpveql(const cpVect v1, const cpVect v2)
Check if two vectors are equal. (Be careful when comparing floating point numbers!...
Definition cpVect.h:43
static cpVect cpvproject(const cpVect v1, const cpVect v2)
Returns the vector projection of v1 onto v2.
Definition cpVect.h:99
static cpFloat cpvcross(const cpVect v1, const cpVect v2)
2D vector cross product analog.
Definition cpVect.h:81
static cpVect cpvforangle(const cpFloat a)
Returns the unit length vector for the given angle (in radians).
Definition cpVect.h:105
static cpVect cpvsub(const cpVect v1, const cpVect v2)
Subtract two vectors.
Definition cpVect.h:55