## Documentation

A high-level wrapper for Chipmunk2D.

Richard van Roy

## Requirements

### Vectors

#### Creation

create-vect x yprocedure

Creates a new vector.

#### Properties

vect-x vectprocedure
vect-y vectprocedure

#### Methods

vect-=? vect-a vect-bprocedure

Check if two vectors are equal.

vect-sub vect-a vect-bprocedure

Substracts two vectors

vect-neg vectprocedure

Negate a vector.

vect-mult vect scalarprocedure

Scalar multiplication

vect-dot vect-a vect-bprocedure

Vector dot product.

vect-cross vect-a vect-bprocedure

2D vector cross product analog. The cross product of 2D vectors results in a 3D vector with only a z component. This function returns the value along the z-axis.

vect-perp vectprocedure

Returns a perpendicular vector. (90 degree rotation)

vect-rperp vectprocedure

Returns a perpendicular vector. (-90 degree rotation)

vect-project vect-a vect-bprocedure

Returns the vector projection of vect-a onto vect-b.

vect-rotate vect-a vect-bprocedure

Uses complex multiplication to rotate vect-a by vect-b. Scaling will occur if vect-a is not a unit vector.

vect-unrotate vect-a vect-bprocedure

Inverse of (vect-rotate).

vect-length vectprocedure

Returns the length of v.

vect-length-squared vectprocedure

Returns the squared length of v. Faster than (vect-length) when you only need to compare lengths.

vect-lerp vect-a vect-b tprocedure

Linearly interpolate between vect-a and vect-b.

vect-lerpconst vect-a vect-b tprocedure

Linearly interpolate between vect-a towards vect-b by distance d.

vect-slerp vect-a vect-b tprocedure

Spherical linearly interpolate between vect-a and vect-b.

vect-slerpconst vect-a vect-b angleprocedure

Spherical linearly interpolate between vect-a towards vect-b by no more than angle angle in radians.

vect-normalize vectprocedure

Returns a normalized copy of v. As a special case, it returns (vect-zero) when called on (vect-zero).

vect-clamp vect lengthprocedure

Clamp v to length length.

vect-dist vect-a vect-bprocedure

Returns the distance between vect-a and vect-b.

vect-dist-squared vect-a vect-bprocedure

Returns the squared distance between vect-a and vect-b. Faster than (cpvdist) when you only need to compare distances.

vect-near? vect-a vect-b distanceprocedure

Returns true if the distance between vect-a and vect-b is less than distance.

#### Conversions

angle->vect angleprocedure

Returns the unit length vector for the given angle (in radians).

vect->angle vectprocedure

Returns the angular direction vect is pointing in (in radians).

### Axis Aligned Bounding Boxes

#### Creation

create-bb left-bottom right-topprocedure

Creates a new Axis Aligned Bounding Box

#### Properties

bb-left-bottom bbprocedure
bb-right-top bbprocedure

#### Methods

bb-intersects? bb-a bb-bprocedure

Returns true if the bounding boxes intersect.

bb-contains-bb? bb otherprocedure

Returns true if bb completely contains other.

bb-contains-vect? bb vectprocedure

Returns true if bb contains vect.

bb-merge bb-a bb-bprocedure

Return the minimal bounding box that contains both bb-a and bb-b.

bb-expand bb vectprocedure

Return the minimal bounding box that contains both bb and vect.

bb-center bbprocedure

Return the center of bb.

bb-area bbprocedure

Return the area of bb.

bb-merged-area bb-a bb-bprocedure

Merges bb-a and bb-b then returns the area of the merged bounding box.

bb-seqment-query bb vect-a vect-bprocedure

Returns the fraction along the segment query the bounding box is hit. Returns infinity if it doesn’t hit.

bb-intersects-seqment bb vect-a vect-bprocedure

Returns true if the segment defined by endpoints vect-a and vect-b intersect bb.

bb-clamp-vect bb vectprocedure

Returns a copy of vect clamped to the bounding box.

bb-wrap-vect bb vectprocedure

Returns a copy of vect wrapped to the bounding box.

### Bodies

#### Creation

create-body mass inertiaprocedure

Returns a new body. mass and inertia are the mass and moment of inertia for the body. Guessing the mass for a body is usually fine, but guessing a moment of inertia can lead to a very poor simulation.

create-static-bodyprocedure

Create additional static bodies with infinite mass and moment of inertia.

#### Properties

body-mass bodyprocedure
set! (body-mass body) valuesetter

Mass of the body.

body-moment bodyprocedure
set! (body-moment body) valuesetter

Moment of inertia (MoI or sometimes just moment) of the body. The moment is like the rotational mass of a body. See below for function to help calculate the moment.

body-position bodyprocedure
set! (body-position body) valuesetter

Position of the center of gravity of the body. When changing the position you may also want to call (space-reindex-shapes-for-body) to update the collision detection information for the attached shapes if plan to make any queries against the space.

body-velocity bodyprocedure
set! (body-velocity body) valuesetter

Linear velocity of the center of gravity of the body.

body-force bodyprocedure
set! (body-force body) valuesetter

Force applied to the center of gravity of the body.

body-angle bodyprocedure
set! (body-angle body) valuesetter

Rotation of the body in radians. When changing the rotation you may also want to call (space-reindex-shapes-for-body) to update the collision detection information for the attached shapes if plan to make any queries against the space.

body-angle-velocity bodyprocedure
set! (body-angle-velocity body) valuesetter

The angular velocity of the body in radians per second.

body-torque bodyprocedure
set! (body-torque body) valuesetter

The torque applied to the body.

body-rotation bodyprocedure

The rotation vector for the body. Can be used with (vect-rotate) or (vect-unrotate) to perform fast rotations.

body-velocity-limit bodyprocedure
set! (body-velocity-limit body) valuesetter

Velocity limit of the body. Defaults to infinity unless you set it specifically. Can be used to limit falling speeds, etc.

body-angularvelocity-limit bodyprocedure
set! (body-angular-velocity-limit body) valuesetter

Angular velocity limit of the body in radians per second. Defaults to infinity unless you set it specifically.

body-space bodyprocedure

Get the space that body has been added to.

body-userdata bodyprocedure
set! (body-userdata body) valuesetter

Userdata can be set to any object and is not used internally.

#### Sleeping Functions

body-sleeping? bodyprocedure

Returns #t if body is sleeping.

body-activate bodyprocedure

Reset the idle timer on a body. If it was sleeping, wake it and any other bodies it was touching.

body-sleep bodyprocedure

Forces a body to fall asleep immediately even if it’s in midair. Cannot be called from a callback.

body-activate-static body #!optional filter-shapeprocedure

Similar in function to (body-activate). Activates all bodies touching body. If filter-shape is set, then only bodies touching through it will be awoken.

body-sleep-with-group body #!optional groupprocedure

When objects in Chipmunk sleep, they sleep as a group of all objects that are touching or jointed together. When an object is woken up, all of the objects in it’s group are woken up. this function allows you group sleeping objects together. It acts identically to (body-sleep) if you don't pass a group by starting a new group. If you pass a sleeping body for group, body will be awoken when group is awoken. You can use this to initialize levels and start stacks of objects in a pre-sleeping state.

#### Iterators

body-each-shape body procprocedure

This functions calls proc on every shape inside this body.

proc should have the following form:

`(lambda (shape) ...)`
body-each-constraint body procprocedure

This functions calls proc on every constraint inside this body.

proc should have the following form:

`(lambda (constraint) ...)`
body-each-arbiter body procprocedure

This functions calls proc on every arbiter inside this body.

proc should have the following form:

`(lambda (arbiter) ...)`

#### Moment of Inertia and Area Helper Functions

Use the following functions to approximate the moment of inertia for your body, adding the results together if you want to use more than one.

Calculate the moment of inertia for a hollow circle, radius-a and radius-b are the inner and outer diameters in no particular order. (A solid circle has an inner diameter of 0)

moment-for-seqment mass vect-a vect-bprocedure

Calculate the moment of inertia for a line segment. The endpoints vect-a and vect-b are relative to the body.

moment-for-polygon vertices offsetprocedure

Calculate the moment of inertia for a solid polygon shape assuming it’s center of gravity is at it’s centroid. The offset is added to each vertex.

moment-for-box width heightprocedure

Calculate the moment of inertia for a solid box centered on the body.

Area of a hollow circle.

Area of a beveled segment. (Will always be zero if radius is zero)

area-for-polygon verticesprocedure

Signed area of a polygon shape. Returns a negative number for polygons with a backwards winding.

#### Coordinate Conversion Functions

Many things are defined in coordinates local to a body meaning that the (0,0) is at the center of gravity of the body and the axis rotate along with the body.

body-local->world body vectprocedure

Convert from body local coordinates to world space coordinates.

body-world->local body vectprocedure

Convert from world space coordinates to body local coordinates.

#### Applying Forces and Torques

People are sometimes confused by the difference between a force and an impulse. An impulse is basically a very large force applied over a very short period of time, like a ball hitting a wall or cannon firing. Chipmunk treats impulses as if they occur instantaneously by simply adding directly to the velocity of an object. Both impulses and forces are affected the mass of an object. Double the mass of the object and halve the effect.

body-reset-forces bodyprocedure

Zero both the forces and torques currently applied to the body.

body-apply-force body f rprocedure

Add the force f to body at a relative offset r from the center of gravity.

body-apply-impulse body i jprocedure

Add the impulse j to body at a relative offset r from the center of gravity.

Note: Both the (body-apply-force) and (body-apply-impulse) functions take a force or impulse in absolute coordinates and applies it at a relative offset in absolute coordinates. (The offset is relative to the center of gravity, but is not rotated with the body)

#### Misc functions

body-static? bodyprocedure

Returns #t if body is a static body. Either (space-static-body) or a body created with (create-static-body).

body-roque? bodyprocedure

Returns #t if body has never been added to a space.

### Collision Shapes

#### Properties

shape-body shapeprocedure
set! (shape-body shape) valuesetter

The rigid body the shape is attached to. Can only be set when the shape is not added to a space.

shape-bb shapeprocedure
set! (shape-bb shape) valuesetter

The bounding box of the shape. Only guaranteed to be valid after (shape-cache-bb) or (space-step) is called. Moving a body that a shape is connected to does not update it’s bounding box. For shapes used for queries that aren’t attached to bodies, you can also use (shape-update).

shape-sensor shapeprocedure
set! (shape-sensor shape) valuesetter

A boolean value if this shape is a sensor or not. Sensors only call collision callbacks, and never generate real collisions.

shape-elasticity shapeprocedure
set! (shape-elasticity shape) valuesetter

Elasticity of the shape. A value of 0.0 gives no bounce, while a value of 1.0 will give a “perfect” bounce. However due to inaccuracies in the simulation using 1.0 or greater is not recommended however. The elasticity for a collision is found by multiplying the elasticity of the individual shapes together.

shape-friction shapeprocedure
set! (shape-friction shape) valuesetter

Friction coefficient. Chipmunk uses the Coulomb friction model, a value of 0.0 is frictionless. The friction for a collision is found by multiplying the friction of the individual shapes together.

shape-surface-velocity shapeprocedure
set! (shape-surface-velocity shape) valuesetter

The surface velocity of the object. Useful for creating conveyor belts or players that move around. This value is only used when calculating friction, not resolving the collision.

shape-collision-type shapeprocedure
set! (shape-collision-type shape) valuesetter

You can assign types to Chipmunk collision shapes that trigger callbacks when objects of certain types touch.

shape-group shapeprocedure
set! (shape-group shape) valuesetter
High-levelprocedure

TODO

shape-layers shapeprocedure
set! (shape-layers shape) valuesetter
High-levelprocedure

TODO

shape-space shapeprocedure

Get the space that shape has been added to.

shape-userdata shapeprocedure
set! (shape-userdata shape) valuesetter

This can be set to any value.

#### Misc Functions

shape-cache-bb shapeprocedure

Synchronizes shape with the body its attached to.

shape-update shape position rotationprocedure

Sets the position and rotation of the shape.

reset-id-counterprocedure

Chipmunk keeps a counter so that every new shape is given a unique hash value to be used in the spatial index. Because this affects the order in which the collisions are found and handled, you can reset the shape counter every time you populate a space with new shapes. If you don’t, there might be (very) slight differences in the simulation.

#### Circles

##### Creation

body is the body to attach the circle to, offset is the offset from the body’s center of gravity in body local coordinates.

##### Properties
circle-offset cirlce-shapeprocedure

#### Segments

##### Creation

body is the body to attach the segment to, vect-a and vect-b are the endpoints, and radius is the thickness of the segment.

##### Properties
segment-shape-a segment-shapeprocedure
segment-shape-b segment-shapeprocedure
segment-shape-normal segment-shapeprocedure

#### Polygons

##### Creation
create-polygon-shape body vertices offset #!optional radiusprocedure

body is the body to attach the poly to, vertices is an list of vectors defining a convex hull with a clockwise winding, offset is the offset from the body’s center of gravity in body local coordinates. An assertion will be thrown the vertexes are not convex or do not have a clockwise winding.

##### Properties
polygon-shape-vertex-count polygon-shapeprocedure
polygon-shape-vertices polygonprocedure
##### Helper Functions
valid-polygon? verticesprocedure

Check if a vertex array is convex and with the correct winding.

centroid-for-polygon verticesprocedure

Calculate the centroid for a polygon.

centroid-for-polygon verticesprocedure

Center a polygon to (0,0). Subtracts the centroid from each vertex.

TODO

TODO

### Space

#### Creation

create-spaceprocedure

#### Properties

space-iterations spaceprocedure
set! (space-iterations space) valuesetter

Iterations allow you to control the accuracy of the solver. Defaults to 10.

space-gravity spaceprocedure
set! (space-gravity space) valuesetter

Global gravity applied to the space. Defaults to (vect-zero). Can be overridden on a per body basis by writing custom integration functions.

space-damping spaceprocedure
set! (space-damping space) valuesetter

Amount of simple damping to apply to the space. A value of 0.9 means that each body will lose 10% of it’s velocity per second. Defaults to 1. Like gravity can be overridden on a per body basis.

space-idle-speed-treshold spaceprocedure
set! (space-idle-speed-treshold space) valuesetter

Speed threshold for a body to be considered idle. The default value of 0 means to let the space guess a good threshold based on gravity.

space-sleep-time-treshold spaceprocedure
set! (space-sleep-time-treshold space) valuesetter

Time a group of bodies must remain idle in order to fall asleep. The default value of INFINITY disables the sleeping feature.

space-collision-slop spaceprocedure
set! (space-collision-slop space) valuesetter

Amount of overlap between shapes that is allowed. It’s encouraged to set this as high as you can without noticable overlapping as it improves the stability. It defaults to 0.1.

space-collision-bias spaceprocedure
set! (space-collision-bias space) valuesetter

Chipmunk allows fast moving objects to overlap, then fixes the overlap over time. Overlapping objects are unavoidable even if swept collisions are supported, and this is an efficient and stable way to deal with overlapping objects. The bias value controls what percentage of overlap remains unfixed after a second and defaults to ~0.2%. Valid values are in the range from 0 to 1, but using 0 is not recommended for stability reasons. The default value is calculated as (vect-pow((- 1.0 0.1) 60.0) meaning that Chipmunk attempts to correct 10% of error ever 160th of a second. 'Note<procedure> Very very few games will need to change this value.</procedure>

space-collision-persistence spaceprocedure
set! (space-collision-persistence space) valuesetter

The number of frames the space keeps collision solutions around for. Helps prevent jittering contacts from getting worse. This defaults to 3 and very very very few games will need to change this value.

space-current-time-step spaceprocedure

Retrieves the current (if you are in a callback from (space-step)) or most recent (outside of a (space-step) call) timestep.

space-locked?procedure

Returns true when in a callback meaning that you cannot add''remove objects from the space. Can be used to choose to create a post-step callback instead.

space-userdata spaceprocedure
set! (space-userdata space) valuesetter

This can be set to any value.

space-static-body spaceprocedure

A dedicated static body for the space. You don’t have to use it, but because it’s memory is managed automatically with the space it’s very convenient. You can set its user data pointer to something helpful if you want for callbacks.

space-bodies spaceprocedure

Returns a list of all bodies added to this space.

space-shapes spaceprocedure

Returns a list of all shapes added to this space.

space-constraints spaceprocedure

Returns a list of all constraints added to this space.

#### Operations

Note: It is not possible to add/remove something to/from a space inside callbacks other then post-step.

space-remove-shape space shapeprocedure
space-has-shape? space shapeprocedure
space-remove-body space bodyprocedure
space-has-body? space bodyprocedure
space-remove-constraint space constraintprocedure
space-has-constraint? space constraintprocedure

#### Iterators

space-each-body space funcprocedure

This functions calls proc on every body inside this space.

proc should have the following form:

`(lambda (body) ...)`
space-each-shape space funcprocedure

This functions calls proc on every shape inside this space.

proc should have the following form:

`(lambda (shape) ...)`
space-each-constraint space funcprocedure

This functions calls proc on every constraint inside this space.

proc should have the following form:

`(lambda (constraint) ...)`

#### Simulating the Space

space-step spaceprocedure

Update the space for the given time step. Using a fixed time step is highly recommended.

#### Enabling and Tuning the Spatial Hash

If you have thousands of objects that are all approximately the same size, the spatial hash may be for you.

space-use-spatital-hash space dim countprocedure

Switch the space to use a spatial hash instead of the bounding box tree.

#### Collision Handlers

space-on-collision-begin spaceprocedure
set! (space-on-collision-begin space) funcsetter

Two shapes just started touching for the first time this step. Return true from the callback to process the collision normally or false to cause Chipmunk to ignore the collision entirely. If you return false, the /presolve/ and /postsolve/ callbacks will never be run, but you will still recieve a separate event when the shapes stop overlapping.

func must have the form:

`(lambda (arbiter space data) ...) -> boolean`

Return #t from the callback to process the collision normally or #f to cause Chipmunk to ignore the collision entirely. If you return #f, the (presolve) and (postSolve) callbacks will never be run, but you will still recieve a separate event when the shapes stop overlapping.

space-on-collision-presolve spaceprocedure
set! (space-on-collision-presolve space) funcsetter

Two shapes are touching during this step. Return #f from the callback to make Chipmunk ignore the collision this step or #t to process it normally. Additionally, you may override collision values using /(set! arbiter-fricion ...)/ /(set! arbiter-elasticity ...)/ or /(set! arbiter-surface-velocity ...)/ to provide custom friction, elasticity, or surface velocity values.

func must have the form:

`(lambda (arbiter space data) ...)`
space-on-collision-postsolve spaceprocedure
set! (space-on-collision-postsolve space) funcsetter

Two shapes are touching and their collision response has been processed. You can retrieve the collision impulse or kinetic energy at this time if you want to use it to calculate sound volumes or damage amounts.

func must have the form:

`(lambda (arbiter space data) ...)`
space-on-collision-seperate spaceprocedure
set! (space-on-collision-seperate space) funcsetter

Two shapes have just stopped touching for the first time this step. To ensure that (begin) and (separate) are always called in balanced pairs, it will also be called when removing a shape while its in contact with something or when deallocating the space.

func must have the form:

`(lambda (arbiter space data) ...) -> boolean`
space-add-collision-handler space type-a type-b begin presolve postsolve seperate #!optional dataprocedure

Adds callback functions for collision types type-a and type-b see previous sections for the forms of the callback functions.

space-remove-collision-handler space type-a type-bprocedure

Remove a collision handler for a given collision type pair.

space-add-poststep-callback space func key #!optional dataprocedure

Register a default collision handler to be used when no specific collision handler is found. The space is given a default handler when created that returns #t for all collisions in (begin) and (presolve) and does nothing in the (postsolve) and (separate) callbacks.

### Constraints

#### Properties

constraint-a constraintprocedure
constraint-b constraintprocedure

Getters for the two bodies the constraint is attached to.

constraint-max-force constraintprocedure
set! (constraint-max-force constraint) valuesetter

The maximum force that the constraint can use to act on the two bodies. Defaults to infinity.

constraint-error-bias constraintprocedure
set! (constraint-error-bias constraint) valuesetter

The percentage of joint error that remains unfixed after a second. This works exactly the same as the collision bias property of a space, but applies to fixing error (stretching) of joints instead of overlapping collisions.

constraint-max-bias constraintprocedure
set! (constraint-max-bias constraint) valuesetter

The maximum speed at which the constraint can apply error correction. Defaults to infinity.

constraint-space constraintprocedure

Get the space that constraint has been added to.

constraint-impulse constraintprocedure

The most recent impulse that constraint applied. To convert this to a force, divide by the timestep passed to (space-step). You can use this to implement breakable joints to check if the force they attempted to apply exceeded a certain threshold.

space-userdata spaceprocedure
set! (space-userdata space) valuesetter

This can be set to any value.

constraint-userdata constraintprocedure
set! (constraint-userdata constraint) valuesetter

This can be set to any value.

#### Pin Joints

##### Creation

<procedure>(create-pin-joint body-a body-b anchor-a anchor-b)<procedure> a and b are the two bodies to connect, and anchor-a and anchor-b are the anchor points on those bodies. The distance between the two anchor points is measured when the joint is created. If you want to set a specific distance, use the setter function to override it

##### Properties
constraint-anchor-a constraintprocedure
set! (constraint-anchor-a constraint) valuesetter
constraint-anchor-b constraintprocedure
set! (constraint-anchor-b constraint) valuesetter
constraint-distance constraintprocedure
set! (constraint-distance constraint) valuesetter

#### Slide Joints

##### Creation
create-slide-joint body-a body-b anchor-a anchor-b min maxprocedure

a and b are the two bodies to connect, anchor-a and anchor-b are the anchor points on those bodies, and min and max'' define the allowed distances of the anchor points.

##### Properties
constraint-anchor-a constraintprocedure
set! (constraint-anchor-a constraint) valuesetter
constraint-anchor-b constraintprocedure
set! (constraint-anchor-b constraint) valuesetter
constraint-min constraintprocedure
set! (constraint-min constraint) valuesetter
constraint-max constraintprocedure
set! (constraint-max constraint) valuesetter

#### Pivot Joints

##### Creation
create-pivot-joint-with-pivot body-a body-b pivotprocedure
create-pivot-joint-with-anchors body-a body-b anchor-a anchor-bprocedure

a and b are the two bodies to connect, and pivot is the point in world coordinates of the pivot. Because the pivot location is given in world coordinates, you must have the bodies moved into the correct positions already. Alternatively you can specify the joint based on a pair of anchor points, but make sure you have the bodies in the right place as the joint will fix itself as soon as you start simulating the space.

##### Properties
constraint-anchor-a constraintprocedure
set! (constraint-anchor-a constraint) valuesetter
constraint-anchor-b constraintprocedure
set! (constraint-anchor-b constraint) valuesetter

#### Groove Joints

##### Creation
create-groove-joint body-a body-b groove-a groove-b anchor-bprocedure

The groove goes from 'groove-a to groove-b on body-a, and the pivot is attached to anchor-b on body-b''. All coordinates are body local.

##### Properties
constraint-anchor constraintprocedure
set! (constraint-anchor constraint) valuesetter
constraint-groove-a constraintprocedure
set! (constraint-groove-a constraint) valuesetter
constraint-groove-b constraintprocedure
set! (constraint-groove-b constraint) valuesetter

#### Damped Spring

##### Creation
create-damped-spring body-a body-b anchor-a anchor-b rest-length stiffness dampingprocedure

Defined much like a slide joint. rest-length is the distance the spring wants to be, stiffness is the spring constant (Young’s modulus), and damping is how soft to make the damping of the spring.

##### Properties
constraint-anchor-a constraintprocedure
set! (constraint-anchor-a constraint) valuesetter
constraint-anchor-b constraintprocedure
set! (constraint-anchor-b constraint) valuesetter
constraint-rest-length constraintprocedure
set! (constraint-rest-length constraint) valuesetter
constraint-stiffness constraintprocedure
set! (constraint-stiffness constraint) valuesetter
constraint-damping constraintprocedure
set! (constraint-damping constraint) valuesetter

#### Damped Rotary Spring

##### Creation
create-damped-rotary-spring body-a body-b anchor-a anchor-b rest-angle stiffness dampingprocedure

Like a damped spring, but works in an angular fashion. rest-angle is the relative angle in radians that the bodies want to have, stiffness and damping work basically the same as on a damped spring.

##### Properties
constraint-length constraintprocedure
set! (constraint-length constraint) valuesetter
constraint-stiffness constraintprocedure
set! (constraint-stiffness constraint) valuesetter
constraint-damping constraintprocedure
set! (constraint-damping constraint) valuesetter

#### Rotary Limit Joint

##### Creation
create-rotary-limit-joint body-a body-b min maxprocedure

Constrains the relative rotations of two bodies. min and max are the angular limits in radians. It is implemented so that it’s possible to for the range to be greater than a full revolution.

##### Properties
constraint-min constraintprocedure
set! (constraint-min constraint) valuesetter
constraint-max constraintprocedure
set! (constraint-max constraint) valuesetter

#### Ratchet Joint

##### Creation
create-ratchet-joint body-a body-b ratchet phaseprocedure

Works like a socket wrench. ratchet is the distance between “clicks”, phase is the initial offset to use when deciding where the ratchet angles are.

##### Properties
constraint-angle constraintprocedure
set! (constraint-angle constraint) valuesetter
constraint-phase constraintprocedure
set! (constraint-phase constraint) valuesetter
constraint-ratchet constraintprocedure
set! (constraint-ratchet constraint) valuesetter

#### Gear Joint

##### Creation
create-gear-joint body-a body-b phase ratioprocedure

Keeps the angular velocity ratio of a pair of bodies constant. 'ratio' is always measured in absolute terms. It is currently not possible to set the ratio in relation to a third body’s angular velocity. 'phase' is the initial angular offset of the two bodies.

##### Properties
constraint-phase constraintprocedure
set! (constraint-phase constraint) valuesetter
constraint-ratio constraintprocedure
set! (constraint-ratio constraint) valuesetter

#### Simple Motor

##### Creation
create-simple-motor body-a body-b rateprocedure

Keeps the relative angular velocity of a pair of bodies constant. rate is the desired relative angular velocity. You will usually want to set an force (torque) maximum for motors as otherwise they will be able to apply a nearly infinite torque to keep the bodies moving.

##### Properties
constraint-rate constraintprocedure
set! (constraint-rate constraint) valuesetter

### Queries

TODO Documentation TODO Make something nice for passing layers

space-nearest-point-query space point max-distance layers group #!optional dataprocedure
space-segment-query space start end layers group #!optional dataprocedure
space-bb-query space bb layers group func dataprocedure

TODO Make data optional

space-shape-query space shape func #!optional dataprocedure