collidex v0.2.0 Collidex.Detection.MixedShapes

Handles detection of collisions between disparate shapes. (i.e. Rects and Circles, Rects and Polygons, Polygons and Circles)

Summary

Functions

Check for collisions between any two shapes not of the same type. Return value is truthy if the shapes overlap on the plane

Functions

collision?(shape1, shape2, method \\ :accurate)

Check for collisions between any two shapes not of the same type. Return value is truthy if the shapes overlap on the plane.

method defaults to :accurate and is ignored if any of the shapes are circles. See Collidex.Detection.Polygons for an explanation of method.

Examples

iex> Collidex.Detection.MixedShapes.collision?(
...>   Collidex.Geometry.Rect.make(-1.0, -1.0, 1.0, 1.0),
...>   Collidex.Geometry.Polygon.make([{0.9,0}, {2,1}, {2,-1}])
...> )
{ :collision, "todo_provide_vector"}

iex> Collidex.Detection.MixedShapes.collision?(
...>   Collidex.Geometry.Rect.make(-1.0, -1.0, 1.0, 1.0),
...>   Collidex.Geometry.Polygon.make([{1.1,0}, {2,1}, {2,-1}])
...> )
false

iex> Collidex.Detection.MixedShapes.collision?(
...>   Collidex.Geometry.Circle.make(0,0,1.0),
...>   Collidex.Geometry.Rect.make(1,-1,2,1)
...> )
{ :collision, "todo_provide_vector" }

iex> Collidex.Detection.MixedShapes.collision?(
...>   Collidex.Geometry.Circle.make(0,0,1.0),
...>   Collidex.Geometry.Rect.make(1.1,-1,2,1)
...> )
false

iex> Collidex.Detection.MixedShapes.collision?(
...>   Collidex.Geometry.Circle.make(0,0,1.0),
...>   Collidex.Geometry.Polygon.make([{0.9,0}, {2,1}, {2,-1}])
...> )
{ :collision, "todo_provide_vector"}

iex> Collidex.Detection.MixedShapes.collision?(
...>   Collidex.Geometry.Circle.make(0,0,1.0),
...>   Collidex.Geometry.Polygon.make([{1.1,0}, {2,1}, {2,-1}])
...> )
false