vivid v0.4.1 Vivid.Polygon
Describes a Polygon as a series of vertices.
Polygon implements both the Enumerable
and Collectable
protocols.
Summary
Functions
Remove a vertex from a Polygon
Remove a vertex at a specific index in the Polygon
Turn on or off filling for this polygon
Is the polygon filled or not?
Return the first vertex in the Polygon
Initialize an empty Polygon
Initialize a Polygon from a list of points
Insert a vertex at a specific index in the Polygon
Return the last vertext in the Polygon
Replace a vertex at a specific index in the Polygon
Convert a Polygon into a list of lines joined by the vertices
Types
Functions
Remove a vertex from a Polygon.
Example
iex> Vivid.Polygon.init([Vivid.Point.init(1,1), Vivid.Point.init(2,2)]) |> Vivid.Polygon.delete(Vivid.Point.init(2,2))
%Vivid.Polygon{vertices: [%Vivid.Point{x: 1, y: 1}]}
Remove a vertex at a specific index in the Polygon.
Example
iex> Vivid.Polygon.init([Vivid.Point.init(1,1), Vivid.Point.init(2,2)]) |> Vivid.Polygon.delete_at(1)
%Vivid.Polygon{vertices: [%Vivid.Point{x: 1, y: 1}]}
Turn on or off filling for this polygon.
Example
iex> use Vivid
...> Polygon.init([Point.init(1,1), Point.init(2,2), Point.init(1,2)])
...> |> Polygon.fill(true)
...> |> Polygon.filled?
true
Is the polygon filled or not?
Example
iex> use Vivid
...> Polygon.init([Point.init(1,1), Point.init(2,2), Point.init(1,2)])
...> |> Polygon.filled?
false
iex> use Vivid
...> Polygon.init([Point.init(1,1), Point.init(2,2), Point.init(1,2)], true)
...> |> Polygon.filled?
true
iex> use Vivid
...> Polygon.init([Point.init(1,1), Point.init(2,2), Point.init(1,2)], false)
...> |> Polygon.filled?
false
Return the first vertex in the Polygon.
Example
iex> Vivid.Polygon.init([Vivid.Point.init(1,1), Vivid.Point.init(2,2)]) |> Vivid.Polygon.first
%Vivid.Point{x: 1, y: 1}
Initialize a Polygon from a list of points.
Example
iex> Vivid.Polygon.init([Vivid.Point.init(1,1), Vivid.Point.init(1,2), Vivid.Point.init(2,2), Vivid.Point.init(2,1)])
%Vivid.Polygon{vertices: [
%Vivid.Point{x: 1, y: 1},
%Vivid.Point{x: 1, y: 2},
%Vivid.Point{x: 2, y: 2},
%Vivid.Point{x: 2, y: 1}
]}
insert_at(Vivid.Polygon.t, integer, Vivid.Point.t) :: Vivid.Polygon.t
Insert a vertex at a specific index in the Polygon.
Example
iex> Vivid.Polygon.init([Vivid.Point.init(1,1), Vivid.Point.init(2,2)]) |> Vivid.Polygon.insert_at(1, Vivid.Point.init(3,3))
%Vivid.Polygon{vertices: [
%Vivid.Point{x: 1, y: 1},
%Vivid.Point{x: 3, y: 3},
%Vivid.Point{x: 2, y: 2}
]}
Return the last vertext in the Polygon.
Example
iex> Vivid.Polygon.init([Vivid.Point.init(1,1), Vivid.Point.init(2,2)]) |> Vivid.Polygon.last
%Vivid.Point{x: 2, y: 2}
replace_at(Vivid.Polygon.t, integer, Vivid.Point.t) :: Vivid.Polygon.t
Replace a vertex at a specific index in the Polygon.
Example
iex> Vivid.Polygon.init([Vivid.Point.init(1,1), Vivid.Point.init(2,2), Vivid.Point.init(3,3)]) |> Vivid.Polygon.replace_at(1, Vivid.Point.init(4,4))
%Vivid.Polygon{vertices: [
%Vivid.Point{x: 1, y: 1},
%Vivid.Point{x: 4, y: 4},
%Vivid.Point{x: 3, y: 3}
]}
Convert a Polygon into a list of lines joined by the vertices.
Examples
iex> Vivid.Polygon.init([Vivid.Point.init(1,1), Vivid.Point.init(1,2), Vivid.Point.init(2,2), Vivid.Point.init(2,1)]) |> Vivid.Polygon.to_lines
[%Vivid.Line{origin: %Vivid.Point{x: 1, y: 1},
termination: %Vivid.Point{x: 1, y: 2}},
%Vivid.Line{origin: %Vivid.Point{x: 1, y: 2},
termination: %Vivid.Point{x: 2, y: 2}},
%Vivid.Line{origin: %Vivid.Point{x: 2, y: 2},
termination: %Vivid.Point{x: 2, y: 1}},
%Vivid.Line{origin: %Vivid.Point{x: 2, y: 1},
termination: %Vivid.Point{x: 1, y: 1}}]