The heart of all Nape simulations.

### Constructor

`new(?gravity:Vec2, ?broadphase:Broadphase)`

Construct a new Space object.

Parameters:

`gravity` | The gravity of this space. (default (0,0)) |
---|---|

`broadphase` | The broadphase type to use. (default DYNAMIC_AABB_TREE) |

Returns:

The constructed Space object.

Throws:

`#` | If gravity is non-null, and has been disposed of. |
---|

### Variables

List of all Bodys directly placed in space.

This list is mutable, and adding an element to this list is one way of
adding a Body to this Space equivalent to: `body.space = space`

This list is only those bodies directly placed in the space, any
body that is a child of a Compound will not be in this list.

`read onlycompounds:CompoundList`

List of all Compounds directly placed in space.

This list is mutable, and adding an element to this list is one way of
adding a Compound to this Space equivalent to: `compound.space = space`

This list is only those compounds directly placed in the space, any
compound that is a child of another compound will not be in this list.

`read onlyconstraints:ConstraintList`

List of all Constraints directly placed in space.

This list is mutable, and adding an element to this list is one way of
adding a Constraint to this Space equivalent to: `constraint.space = space`

This list is only those bodies directly placed in the space, any
constraint that is a child of a Compound will not be in this list.

`read onlyelapsedTime:Float`

The elapsed simulation time.

This is the total amount of 'time' that has elapsed in the Space simulation.

`read onlylisteners:ListenerList`

List of all Listeners in space.

This list is mutable, and adding an element to this list is one way of
adding a Listener to this Space equivalent to: `listener.space = space`

`read onlyliveBodies:BodyList`

List of all active dynamic Bodies in space.

This list contains all dynamic bodies that are awake regardless of their containment in a Compound.

This list is immutable.

`read onlyliveConstraints:ConstraintList`

List of all active Constraints in space.

This list contains all constraints regardless of their containment in a Compound.

This list is immutable.

Flag controlling sorting of contact points.

If true, then collisions will be resolved in an order defined by their
penetration depths. This can be shown to improve stability of the physics
as well as making simulations more consistent regardless of which broadphase
is used.

Having sorting enabled obviously incurs a cost, and you may consider
disabling it if you are having issues with performance (Though things
such as number of physics iterations will have much greater bearing on
performance than this, especcialy since enabling this may permit you
to use less iterations).

The time stamp of this Space object.

This is equal to the number of times that space.step(..) has been invoked.

`read onlyuserData:Dynamic<Dynamic>`

Dynamic object for user to store additional data.

This object cannot be set, only its dynamically created
properties may be set. In AS3 the type of this property is *

This object will be lazily constructed so that until accessed
for the first time, will be null internally.

Static, immutable Body for constraint purposes.

This is a completely static, uncollidable, uninteractable Body
with no Shapes, that cannot be modified in any way.

Its purpose is to provide a means for attaching Constraints
from one Body to the Space itself, for instance pinning a body
against a static point in space.

Angular drag applied to all bodies in Space.

This represents the fraction of a body's angular velocity which will be
removed per second. This value has no unit attached.

### Methods

`bodiesInAABB(aabb:AABB, containment:Bool = false, strict:Bool = true, ?filter:InteractionFilter, ?output:BodyList):BodyList`

Evaluate all Bodies given an AABB.

If the filter argument is non-null, then only bodies with a shape
classified as being part of the AABB, whose filter agrees to collide
will be considered.

Parameters:

`aabb` | The bounding box to query bodies by, |
---|---|

`containment` | If true, then only Bodies entirely contained (Rather than simply intersecting) will be considered. (default false) |

`strict` | If false, then the body's shape's bounding box will be used to classify the shapes of the body, instead of the Shape itself. (default true) |

`filter` | Optional filter to pick and choose shapes, based on whether the filters agree to collide. (default null) |

`output` | Optional list to append results to instead of creating a new list (default null). |

Returns:

A list of all the shapes for given AABB.

Throws:

`#` | If AABB is null, or is degenerate. |
---|

`bodiesInBody(body:Body, ?filter:InteractionFilter, ?output:BodyList):BodyList`

Evaluate all Bodies given a Body.

If the filter argument is non-null, then only bodies with a shape
classified as being part of the input body, whose filter agrees to collide
will be considered. The input body is considered a purely geometric

Parameters:

`body` | The body to use in classifying other bodies. |
---|---|

`filter` | Optional filter to pick and choose shapes, based on whether the filters agree to collide. (default null) |

`output` | Optional list to append results to instead of creating a new list (default null). |

Returns:

A list of all the bodies for given body.

Throws:

`#` | If body is null. |
---|---|

`#` | If body has a shape that is a polygon, and that polygon is not 'valid' |

`bodiesInCircle(position:Vec2, radius:Float, containment:Bool = false, ?filter:InteractionFilter, ?output:BodyList):BodyList`

Evaluate all Bodies given a circle.

If the filter argument is non-null, then only bodies with a shape
classified as being part of the circle, whose filter agrees to collide
will be considered.

Parameters:

`position` | The position of the centre of the circle. |
---|---|

`radius` | The radius of the circle. |

`containment` | If true, then only Bodies entirely contained (Rather than simply intersecting) will be considered. If a filter is supplied, only shapes that agree to collide will be used in this containment check. (default false) |

`filter` | Optional filter to pick and choose shapes, based on whether the filters agree to collide. (default null) |

`output` | Optional list to append results to instead of creating a new list (default null). |

Returns:

A list of all the shapes for given circle.

Throws:

`#` | If positions is null or disposed of. |
---|---|

`#` | If radius is not strictly positive. |

`bodiesInShape(shape:Shape, containment:Bool = false, ?filter:InteractionFilter, ?output:BodyList):BodyList`

Evaluate all Bodies given a shape.

If the filter argument is non-null, then only bodies with a shape
classified as being part of the input shape, whose filter agrees to collide
will be considered. The input shape is considered a purely geometric

The input shape must be part of a Body so as to be well defined.

Parameters:

`shape` | The shape to use in classifying other shapes. |
---|---|

`containment` | If true, then only Bodies entirely contained (Rather than simply intersecting) will be considered. (default false) |

`filter` | |

`output` | Optional list to append results to instead of creating a new list (default null). |

Returns:

A list of all the bodies for given shape.

Throws:

`#` | If shape is null or not part of a body. |
---|---|

`#` | If shape is a polygon, and that polygon is not 'valid' |

`bodiesUnderPoint(point:Vec2, ?filter:InteractionFilter, ?output:BodyList):BodyList`

Evaluate all Bodies under a given Point.

If the filter argument is non-null, then only bodies with a shape containing
the given point whose filter agrees to 'collide' will be considered.

Parameters:

`point` | The point to evaluate bodies. |
---|---|

`filter` | |

`output` | Optional list to append results to instead of creating a new list (default null). |

Returns:

A list of all the Bodies containing the given point.

Throws:

`#` | If point is null or disposed of. |
---|

Clear the Space of all objects.

Things such as the elapsed simulation time, and time step will too be
reset to 0.

Parameters such as gravity, and worldLinearDrag will be untouched by
this operation.

`convexCast(shape:Shape, deltaTime:Float, liveSweep:Bool = false, ?filter:InteractionFilter):Null<ConvexResult>`

Perform a convex cast for soonest collision.

This method will return only the soonest collision result (if any), to find
more than this, use the convexMultiCast method. The shape will not be
swept further than the time delta provided.
Shapes already intersecting
the sweep shape at t = 0 are ignored.

If the filter argument is null, then all shapes will be collidable
otherwise only those for whose filter agrees to 'collide'.

Parameters:

`shape` | The Shape to be cast through space. This shape must belong to a body whose velocity is used to define the sweep. |
---|---|

`deltaTime` | The amount of time to sweep the shape forward. |

`liveSweep` | If true, then moving objects in the space will have their motion considered during the sweep. Otherwise; like with normal rayCast, objects in the space are considered un-moving for the cast. (default false) |

`filter` |

Returns:

The soonest result (if any) of convex intersection.

Throws:

`#` | If shape is null, or not part of a body. |
---|---|

`#` | If deltaTime is negative. |

`convexMultiCast(shape:Shape, deltaTime:Float, liveSweep:Bool = false, ?filter:InteractionFilter, output:ConvexResultList):ConvexResultList`

Perform a convex cast for all collisions in time order.

This method will return all collisions, or an empty list if there are none.
The shape will not be
swept further than the time delta provided. Shapes already intersecting
the sweep shape at t = 0 are ignored.

If the filter argument is null, then all shapes will be collidable
otherwise only those for whose filter agrees to 'collide'.

Parameters:

`shape` | The Shape to be cast through space. This shape must belong to a body whose velocity is used to define the sweep. |
---|---|

`deltaTime` | The amount of time to sweep the shape forward. |

`liveSweep` | If true, then moving objects in the space will have their motion considered during the sweep. Otherwise; like with normal rayCast, objects in the space are considered un-moving for the cast. (default false) |

`filter` | |

`output` | A list to append results to instead of allocating a new one (default null) |

Returns:

The collision results in time order.

Throws:

`#` | If shape is null, or not part of a body. |
---|---|

`#` | If deltaTime is negative. |

`interactionType(shape1:Shape, shape2:Shape):Null<InteractionType>`

Determine the interaction type that would occur between a pair of Shapes.

This function takes into account everything possible, and ignoring the
callback system will tell you precisely the type of interaction (if any
at all) which will occur between these Shapes.

This function can only work if the Shapes belong to a Body.

This function can only make use of any constraints 'ignore' property
to determine if 'null' should be returned if the constraints being used
are inside of a Space.

Parameters:

`shape1` | The first Shape to test. |
---|---|

`shape2` | The second Shape to test. |

Returns:

The interaction type that will occur between these shapes, or null if no interaction will occur.

Throws:

`#` | If either shape is null, or is not contained within a body. |
---|

`rayCast(ray:Ray, inner:Bool = false, ?filter:InteractionFilter):Null<RayResult>`

Perform a ray cast for closest result.

This method will return only the closest result (if any), to find more
the first result, use the rayMultiCast method. The ray will not be
cast beyond its maxDistance.

If the filter argument is null, then all shapes will be intersectable
otherwise only those for whose filter agrees to 'collide'.

Parameters:

`ray` | The ray to cast through space. |
---|---|

`inner` | If true then inner surfaces of shapes will also be intersected. otherwise only the outer surfaces. (default false) |

`filter` |

Returns:

The closest result (if any) of ray intersection.

Throws:

`#` | If ray is null. |
---|

`rayMultiCast(ray:Ray, inner:Bool = false, ?filter:InteractionFilter, ?output:RayResultList):RayResultList`

Perform a ray cast for all valid results.

This method will return all intersections (in distance order) of ray
with shapes in the space up to the ray's maxDistance.

If the filter argument is null, then all shapes will be intersectable
otherwise only those for whose filter agrees to 'collide'.

Parameters:

`ray` | The ray to cast through space. |
---|---|

`inner` | If true then inner surfaces of shapes will also be intersected. otherwise only the outer surfaces. (default false) |

`filter` | |

`output` | A list to append results to instead of allocating a new one (default null) |

Returns:

All valid results of ray cast in distance order from closest to furthest.

Throws:

`#` | If ray is null. |
---|

`shapesInAABB(aabb:AABB, containment:Bool = false, strict:Bool = true, ?filter:InteractionFilter, ?output:ShapeList):ShapeList`

Evaluate all Shapes given an AABB.

If the filter argument is non-null, then only shapes who's filter
agrees to 'collide' will be considered.

Parameters:

`aabb` | The bounding box to query shapes by, |
---|---|

`containment` | If true, then only Shapes entirely contained (Rather than simply intersected) will be considered. (default false) |

`strict` | If false, then the Shape's bounding box will be used to classify the Shape, instead of the Shape itself. (default true) |

`filter` | |

`output` | Optional list to append results to instead of creating a new list (default null). |

Returns:

A list of all the shapes for given AABB.

Throws:

`#` | If AABB is null, or is degenerate. |
---|

`shapesInBody(body:Body, ?filter:InteractionFilter, ?output:ShapeList):ShapeList`

Evaluate all Shapes given a Body.

If the filter argument is non-null, then only shapes who's filter
agrees to 'collide' will be considered. The input body's shape's own filters
are never used in this method. The input body is considered a purely
geometric object.

Parameters:

`body` | The body to use in classifying other shapes. |
---|---|

`filter` | |

`output` | Optional list to append results to instead of creating a new list (default null). |

Returns:

A list of all the shapes for given body.

Throws:

`#` | If body is null. |
---|---|

`#` | If body has a shape that is a polygon, and that polygon is not 'valid' |

`shapesInCircle(position:Vec2, radius:Float, containment:Bool = false, ?filter:InteractionFilter, ?output:ShapeList):ShapeList`

Evaluate all Shapes given a circle.

If the filter argument is non-null, then only shapes who's filter
agrees to 'collide' will be considered.

Parameters:

`position` | The position of the centre of the circle. |
---|---|

`radius` | The radius of the circle. |

`containment` | If true, then only Shapes entirely contained (Rather than simply intersected) will be considered. (default false) |

`filter` | |

`output` | Optional list to append results to instead of creating a new list (default null). |

Returns:

A list of all the shapes for given circle.

Throws:

`#` | If positions is null or disposed of. |
---|---|

`#` | If radius is not strictly positive. |

`shapesInShape(shape:Shape, containment:Bool = false, ?filter:InteractionFilter, ?output:ShapeList):ShapeList`

Evaluate all Shapes given another shape.

If the filter argument is non-null, then only shapes who's filter
agrees to 'collide' will be considered. The input shape's own filter
is never used in this method. The input shape is considered a purely
geometric object.

The input shape must be part of a Body so as to be well defined.

Parameters:

`shape` | The shape to use in classifying other shapes. |
---|---|

`containment` | If true, then only Shapes entirely contained (Rather than simply intersected) will be considered. (default false) |

`filter` | |

`output` | Optional list to append results to instead of creating a new list (default null). |

Returns:

A list of all the shapes for given shape.

Throws:

`#` | If shape is null or not part of a body. |
---|---|

`#` | If shape is a polygon, and that polygon is not 'valid' |

`shapesUnderPoint(point:Vec2, ?filter:InteractionFilter, ?output:ShapeList):ShapeList`

Evaluate all Shapes under a given Point.

If the filter argument is non-null, then only shapes who's filter
agrees to 'collide' will be considered.

Parameters:

`point` | The point to evaluate shapes. |
---|---|

`filter` | |

`output` | Optional list to append results to instead of creating a new list (default null). |

Returns:

A list of all the Shapes containing the given point.

Throws:

`#` | If point is null or disposed of. |
---|

`step(deltaTime:Float, velocityIterations:Int = 10, positionIterations:Int = 10):Void`

Step simulation forward in time.

Parameters:

`deltaTime` | The number of seconds to simulate. For 60fps physics you would use a value of 1/60. |
---|---|

`velocityIterations` | The number of iterations to use in resolving errors in the velocities of objects. This is together with collision detection the most expensive phase of a simulation update, as well as the most important for stable results. (default 10) |

`positionIterations` | The number of iterations to use in resolving errors in the positions of objects. This is far more lightweight than velocity iterations, as well as being less important for the stability of results. (default 10) |

Throws:

`#` | If deltaTime is not strictly positive. |
---|---|

`#` | If either of the number of iterations is not strictly positive. |

`visitBodies(lambda:Body‑>Void):Void`

Apply given function to all bodies in space.

This method is a way to iterate over 'every' Body in the Space
regardless of containment in a Compound.

Parameters:

`lambda` | The function to apply to each Body. |
---|

Throws:

`#` | If lambda is null. |
---|

`visitCompounds(lambda:Compound‑>Void):Void`

Apply given function to all compounds in space.

This method is a way to iterate over 'every' Compound in the Space
regardless of containment in another Compound.

Parameters:

`lambda` | The function to apply to each Compound. |
---|

Throws:

`#` | If lambda is null. |
---|

`visitConstraints(lambda:Constraint‑>Void):Void`

Apply given function to all constraints in space.

This method is a way to iterate over 'every' Constraint in the Space
regardless of containment in a Compound.

Parameters:

`lambda` | The function to apply to each Constraint. |
---|

Throws:

`#` | If lambda is null. |
---|