collidex v0.1.1 Collidex.Utils
Assorted utilities and geometric transformations.
Summary
Functions
Convert the numeric parts of arguments to floats. Accepts a single number, a 2-tuple of numbers, or a list of 2-tuples of numbers
Find the minimum and maximum point of a shape, as that shape is projected along an arbitrary axis. Supports Rects, Circles, and Polygons, but note that the projection of a Circle will only be accurate if the axis of projection is a unit vector
Returns a vector normal to each edge of the shape, in a right-handed coordinate space
Given two numeric ranges as a pair of 2-tuples {a1, a2}, {b1, b2}
, or
a list containing a pair of 2-tuples [{a1, a2}, {b1, b2}]
returns
true if those ranges overlap
Find the projection of the vertices of a shape (Rect or Polygon) on an arbitrary axis. Returns a list of floats representing the projection of each vertex
Returns a unit-vector in the same direction as the argument
Functions
Convert the numeric parts of arguments to floats. Accepts a single number, a 2-tuple of numbers, or a list of 2-tuples of numbers.
Examples
iex> Collidex.Utils.coerce_floats [ {1, 3}, {-1.5, -2} ]
[ {1.0, 3.0}, {-1.5, -2.0} ]
iex> Collidex.Utils.coerce_floats {1, 3}
{1.0, 3.0}
iex> Collidex.Utils.coerce_floats 6
6.0
Find the minimum and maximum point of a shape, as that shape is projected along an arbitrary axis. Supports Rects, Circles, and Polygons, but note that the projection of a Circle will only be accurate if the axis of projection is a unit vector.
Returns a 2-tuple representing the minimum and maximum point of the
shape's "shadow" as projected onto axis
.
Returns a vector normal to each edge of the shape, in a right-handed coordinate space.
Given two numeric ranges as a pair of 2-tuples {a1, a2}, {b1, b2}
, or
a list containing a pair of 2-tuples [{a1, a2}, {b1, b2}]
returns
true if those ranges overlap.
Examples
iex> Collidex.Utils.overlap?({0.0,5.0}, {5.0, 10.0})
true
iex> Collidex.Utils.overlap?({-1.0, -3.0}, {-6.1, 3.5})
true
iex> Collidex.Utils.overlap?({-1.0, 0.0}, {0.01, 1.0} )
false
Find the projection of the vertices of a shape (Rect or Polygon) on an arbitrary axis. Returns a list of floats representing the projection of each vertex.