collision v0.3.1 Collision.Polygon.Vertex
A vertex is a point in the Cartesian space where a polygon’s edges meet.
Summary
Functions
Convert a tuple to a Vertex
Calculate the convex hull of a list of vertices
Rounds the x and y components of a vertex
Rounds a list of vertices
Convert a vertex to a tuple
Types
t :: Collision.Polygon.Vertex.t
Vertices in two dimensional space are defined by x
and y
coordinates.
Functions
Specs
from_tuple({number, number}) :: Collision.Polygon.Vertex.t
Convert a tuple to a Vertex.
Returns: %Vertex{}
Example
iex> Vertex.from_tuple({2, 5})
%Vertex{x: 2, y: 5}
Specs
graham_scan([Collision.Polygon.Vertex.t]) :: Collision.Polygon.Vertex.t
Calculate the convex hull of a list of vertices.
In the case of a convex polygon, it returns the polygon’s vertices.
For a concave polygon, it returns a subset of the vertices that form a convex polygon.
Examples
iex> convex_polygon = [
...> %Vertex{x: 2, y: 2}, %Vertex{x: -2, y: 2},
...> %Vertex{x: -2, y: -2}, %Vertex{x: 2, y: -2}
...> ]
...> Vertex.graham_scan(convex_polygon)
[%Vertex{x: -2, y: -2}, %Vertex{x: 2, y: -2},
%Vertex{x: 2, y: 2}, %Vertex{x: -2, y: 2}]
iex> concave_polygon = [
...> %Vertex{x: 2, y: 2}, %Vertex{x: 0, y: 0}, %Vertex{x: -2, y: 2},
...> %Vertex{x: -2, y: -2}, %Vertex{x: 2, y: -2}
...> ]
...> Vertex.graham_scan(concave_polygon)
[%Vertex{x: -2, y: -2}, %Vertex{x: 2, y: -2},
%Vertex{x: 2, y: 2}, %Vertex{x: -2, y: 2}]
Specs
round_vertex(Collision.Polygon.Vertex.t) :: Collision.Polygon.Vertex.t
Rounds the x and y components of a vertex.
Returns: Vertex.t
Examples
iex> Vertex.round_vertex(%Vertex{x: 1.9999999, y: 1.9999999})
%Vertex{x: 2.0, y: 2.0}
Specs
round_vertices([Collision.Polygon.Vertex.t]) :: [Collision.Polygon.Vertex.t]
Rounds a list of vertices.
Returns: [Vertex.t]
Examples
iex> Vertex.round_vertices([
...> %Vertex{x: 1.9999999, y: 1.99999999}, %Vertex{x: 2.11111111, y: 2.11111111}
...> ])
[%Vertex{x: 2.0, y: 2.0}, %Vertex{x: 2.11111, y: 2.11111}]
Specs
to_tuple(Collision.Polygon.Vertex.t) :: {number, number}
Convert a vertex to a tuple.
Returns: {}
Example
iex> Vertex.to_tuple(%Vertex{x: 2, y: 5})
{2, 5}