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

t()
t

Functions

delete(polygon, point)

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}]}
delete_at(polygon, index)
delete_at(Vivid.Polygon.t, integer) :: Vivid.Polygon.t

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}]}
fill(polygon, fill)
fill(Vivid.Polygon.t, boolean) :: Vivid.Polygon.t

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
filled?(polygon)
filled?(Vivid.Polygon.t) :: boolean

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
first(polygon)

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}
init()
init() :: Vivid.Polygon.t

Initialize an empty Polygon.

Example

iex> Vivid.Polygon.init
%Vivid.Polygon{vertices: []}
init(points)

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(polygon, index, point)

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}
]}
last(polygon)

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(polygon, index, point)
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}
]}
to_lines(polygon)
to_lines(Vivid.Polygon.t) :: [Vivid.Line.t]

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}}]