vivid v0.3.0 Vivid.Line

Represents a line segment between two Points in 2D space.

Summary

Functions

Calculates the absolute Y (vertical) distance between the origin and termination points

Creates a Line

Calculates straight-line distance between the two ends of the line segment using Pythagoras’ Theorem

Returns whether a point is on the line

Returns the origin (starting) point of the line segment

Returns the termination (ending) point of the line segment

Calculates the absolute X (horizontal) distance between the origin and termination points

Calculates the X (horizontal) distance between the origin and termination points

Calculates the Y (vertical) distance between the origin and termination points

Types

t()
t

Functions

height(line)
height(Vivid.Line.t) :: number

Calculates the absolute Y (vertical) distance between the origin and termination points.

Example

iex> Vivid.Line.init(Vivid.Point.init(1,1), Vivid.Point.init(4,14)) |> Vivid.Line.height
13
init(list)

Creates a Line.

Examples

iex> Vivid.Line.init(Vivid.Point.init(1,1), Vivid.Point.init(4,4))
%Vivid.Line{origin: %Vivid.Point{x: 1, y: 1}, termination: %Vivid.Point{x: 4, y: 4}}
length(line)
length(Vivid.Line.t) :: number

Calculates straight-line distance between the two ends of the line segment using Pythagoras’ Theorem

Example

iex> Vivid.Line.init(Vivid.Point.init(1,1), Vivid.Point.init(4,5)) |> Vivid.Line.length
5.0
on?(line, point)
on?(Vivid.Line.t, Vivid.Point.t) :: boolean

Returns whether a point is on the line.

Example

iex> use Vivid …> Line.init(Point.init(1,1), Point.init(3,1)) …> |> Line.on?(Point.init(2,1)) true

iex> use Vivid …> Line.init(Point.init(1,1), Point.init(3,1)) …> |> Line.on?(Point.init(2,2)) false

origin(line)

Returns the origin (starting) point of the line segment.

Example

iex> Vivid.Line.init(Vivid.Point.init(1,1), Vivid.Point.init(4,4)) |> Vivid.Line.origin
%Vivid.Point{x: 1, y: 1}
termination(line)
termination(Vivid.Line.t) :: Vivid.Point.t

Returns the termination (ending) point of the line segment.

Example

iex> Vivid.Line.init(Vivid.Point.init(1,1), Vivid.Point.init(4,4)) |> Vivid.Line.termination
%Vivid.Point{x: 4, y: 4}
width(line)
width(Vivid.Line.t) :: number

Calculates the absolute X (horizontal) distance between the origin and termination points.

Example

iex> Vivid.Line.init(Vivid.Point.init(1,1), Vivid.Point.init(14,4)) |> Vivid.Line.width
13
x_distance(line)
x_distance(Vivid.Line.t) :: number

Calculates the X (horizontal) distance between the origin and termination points.

Example

iex> Vivid.Line.init(Vivid.Point.init(14,1), Vivid.Point.init(1,4)) |> Vivid.Line.x_distance
-13
y_distance(line)
y_distance(Vivid.Line.t) :: number

Calculates the Y (vertical) distance between the origin and termination points.

Example

iex> Vivid.Line.init(Vivid.Point.init(1,14), Vivid.Point.init(4,1)) |> Vivid.Line.y_distance
-13