vivid v0.4.2 Vivid.Path View Source

Describes a path as a series of vertices.

Path implements both the Enumerable and Collectable protocols.

Example

iex> use Vivid
...> 0..3
...> |> Stream.map(fn
...> i when rem(i, 2) == 0 -> Point.init(i * 3, i * 4)
...> i -> Point.init(i * 3, i * 2)
...> end)
...> |> Enum.into(Path.init())
...> |> to_string()
"@@@@@@@@@@@@\n" <>
"@@@@@@@ @@@@\n" <>
"@@@@@@@   @@\n" <>
"@@@@@@ @@@ @\n" <>
"@@@@@@ @@@@@\n" <>
"@@@@@ @@@@@@\n" <>
"@@@@@ @@@@@@\n" <>
"@@@@ @@@@@@@\n" <>
"@@  @@@@@@@@\n" <>
"@ @@@@@@@@@@\n" <>
"@@@@@@@@@@@@\n"

Link to this section Summary

Functions

Remove a vertex from a Path

Remove a vertex at a specific index in the Path

Return the first vertex in the Path

Initialize an empty path

Initialize a path from a list of points

Insert a vertex at a specific index in the Path

Return the last vertex in the Path

Replace a vertex at a specific index in the Path

Convert a path into a list of lines joined by the vertices

Link to this section Types

Link to this section Functions

Remove a vertex from a Path.

Example

iex> Vivid.Path.init([Vivid.Point.init(1,1), Vivid.Point.init(2,2)]) |> Vivid.Path.delete(Vivid.Point.init(2,2))
%Vivid.Path{vertices: [%Vivid.Point{x: 1, y: 1}]}
Link to this function delete_at(path, index) View Source
delete_at(Vivid.Path.t, integer) :: Vivid.Path.t

Remove a vertex at a specific index in the Path.

Example

iex> Vivid.Path.init([Vivid.Point.init(1,1), Vivid.Point.init(2,2)]) |> Vivid.Path.delete_at(1)
%Vivid.Path{vertices: [%Vivid.Point{x: 1, y: 1}]}

Return the first vertex in the Path.

Example

iex> Vivid.Path.init([Vivid.Point.init(1,1), Vivid.Point.init(2,2)]) |> Vivid.Path.first
%Vivid.Point{x: 1, y: 1}

Initialize an empty path.

Example

iex> Vivid.Path.init
%Vivid.Path{vertices: []}

Initialize a path from a list of points.

Example

iex> Vivid.Path.init([Vivid.Point.init(1,1), Vivid.Point.init(1,2), Vivid.Point.init(2,2), Vivid.Point.init(2,1)])
%Vivid.Path{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}
]}
Link to this function insert_at(path, index, point) View Source
insert_at(Vivid.Path.t, integer, Vivid.Point.t) :: Vivid.Path.t

Insert a vertex at a specific index in the Path.

Example

iex> Vivid.Path.init([Vivid.Point.init(1,1), Vivid.Point.init(2,2)]) |> Vivid.Path.insert_at(1, Vivid.Point.init(3,3))
%Vivid.Path{vertices: [
  %Vivid.Point{x: 1, y: 1},
  %Vivid.Point{x: 3, y: 3},
  %Vivid.Point{x: 2, y: 2}
]}

Return the last vertex in the Path.

Example

iex> Vivid.Path.init([Vivid.Point.init(1,1), Vivid.Point.init(2,2)]) |> Vivid.Path.last
%Vivid.Point{x: 2, y: 2}
Link to this function replace_at(path, index, point) View Source
replace_at(Vivid.Path.t, integer, Vivid.Point.t) :: Vivid.Path.t

Replace a vertex at a specific index in the Path.

Example

iex> Vivid.Path.init([Vivid.Point.init(1,1), Vivid.Point.init(2,2), Vivid.Point.init(3,3)]) |> Vivid.Path.replace_at(1, Vivid.Point.init(4,4))
%Vivid.Path{vertices: [
  %Vivid.Point{x: 1, y: 1},
  %Vivid.Point{x: 4, y: 4},
  %Vivid.Point{x: 3, y: 3}
]}

Convert a path into a list of lines joined by the vertices.

Examples

iex> Vivid.Path.init([Vivid.Point.init(1,1), Vivid.Point.init(1,2), Vivid.Point.init(2,2), Vivid.Point.init(2,1)]) |> Vivid.Path.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}}]