vivid v0.4.1 Vivid.Path
Describes a path as a series of vertices.
Path implements both the Enumerable
and Collectable
protocols.
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
Types
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}]}
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 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}
]}
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}
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}}]