View Source Vivid.Point (vivid v0.4.4)

Represents an individual point in (2D) space.

Example

iex> use Vivid ...> point = Point.init(2,2) ...> Frame.init(5,5, RGBA.white()) ...> |> Frame.push(point, RGBA.black()) ...> |> to_string() "@@@@@\n" <> "@@@@@\n" <> "@@ @@\n" <> "@@@@@\n" <> "@@@@@\n"

Summary

Functions

Creates a Point using x and y coordinates.

Round the coordinates in the point to the nearest integer value.

Simple helper to swap X and Y coordinates - used when translating the frame buffer to vertical.

Return the vector in x and y between point a and point b.

Returns the X coordinate of the point.

Returns the Y coordinate of the point.

Types

@type t() :: %Vivid.Point{x: number(), y: number()}

Functions

@spec init(number(), number()) :: t()

Creates a Point using x and y coordinates.

Examples

iex> Vivid.Point.init(13, 27)
%Vivid.Point{x: 13, y: 27}
@spec round(t()) :: t()

Round the coordinates in the point to the nearest integer value.

Example

iex> Vivid.Point.init(1.23, 4.56)
...> |> Vivid.Point.round
Vivid.Point.init(1, 5)
@spec swap_xy(t()) :: t()

Simple helper to swap X and Y coordinates - used when translating the frame buffer to vertical.

Example

iex> Vivid.Point.init(13, 27)
...> |> Vivid.Point.swap_xy
Vivid.Point.init(27, 13)
@spec vector(t(), t()) :: {number(), number()}

Return the vector in x and y between point a and point b.

Example

iex> use Vivid
...> a = Point.init(10, 10)
...> b = Point.init(20, 20)
...> Point.vector(a, b)
{10, 10}
@spec x(t()) :: number()

Returns the X coordinate of the point.

Examples

iex> Vivid.Point.init(13, 27) |> Vivid.Point.x
13
@spec y(t()) :: number()

Returns the Y coordinate of the point.

Examples

iex> Vivid.Point.init(13, 27) |> Vivid.Point.y
27