Vivid.Box (vivid v0.4.5)

Copy Markdown View Source

Short-hand for creating rectangle polygons.

This module doesn't have very much logic other than knowing how to turn itself into a Polygon.

Example

iex> use Vivid
...> Box.init(Point.init(5,10), Point.init(15,20))
...> |> to_string()
"@@@@@@@@@@@@@\n" <>
"@           @\n" <>
"@ @@@@@@@@@ @\n" <>
"@ @@@@@@@@@ @\n" <>
"@ @@@@@@@@@ @\n" <>
"@ @@@@@@@@@ @\n" <>
"@ @@@@@@@@@ @\n" <>
"@ @@@@@@@@@ @\n" <>
"@ @@@@@@@@@ @\n" <>
"@ @@@@@@@@@ @\n" <>
"@ @@@@@@@@@ @\n" <>
"@           @\n" <>
"@@@@@@@@@@@@@\n"

Summary

Functions

Return the bottom left corner of the box.

Return the top right corner of the box.

Initialize an unfilled Box from it's bottom left and top right points.

Initialize a Box from it's bottom left and top right points and whether it's filled.

Initialize a box from the bounds of an arbitrary shape.

Convert a Box into a Polygon.

Return the top left corner of the box.

Return the top right corner of the box.

Types

t()

@type t() :: t()

Functions

bottom_left(box)

@spec bottom_left(t()) :: Vivid.Point.t()

Return the bottom left corner of the box.

Example

iex> use Vivid
...> Box.init(Point.init(1,1), Point.init(4,4))
...> |> Box.bottom_left
Point.init(1, 1)

bottom_right(box)

@spec bottom_right(t()) :: Vivid.Point.t()

Return the top right corner of the box.

Example

iex> use Vivid
...> Box.init(Point.init(1,1), Point.init(4,4))
...> |> Box.bottom_right
Point.init(4, 1)

init(bottom_left, top_right)

@spec init(Vivid.Point.t(), Vivid.Point.t()) :: t()

Initialize an unfilled Box from it's bottom left and top right points.

  • bottom_left - the bottom left Point of the box.
  • top_right - the top right Point of the box.

Examples

iex> use Vivid
...> Box.init(Point.init(1,1), Point.init(4,4))
%Box{bottom_left: Point.init(1, 1), top_right: Point.init(4, 4)}

init(bottom_left, top_right, fill)

@spec init(Vivid.Point.t(), Vivid.Point.t(), boolean()) :: t()

Initialize a Box from it's bottom left and top right points and whether it's filled.

  • bottom_left - the bottom left Point of the box.
  • top_right - the top right Point of the box.
  • fill - whether or not the box should be filled.

Examples

iex> use Vivid
...> Box.init(Point.init(1,1), Point.init(4,4))
%Box{bottom_left: Point.init(1, 1), top_right: Point.init(4, 4)}

init_from_bounds(shape, fill \\ false)

@spec init_from_bounds(Vivid.Shape.t(), boolean()) :: t()

Initialize a box from the bounds of an arbitrary shape.

Examples

iex> use Vivid
...> Circle.init(Point.init(5,5), 5)
...> |> Box.init_from_bounds
Box.init(Point.init(0.0, 0.2447174185242318), Point.init(10.0, 9.755282581475768))

to_polygon(box)

@spec to_polygon(t()) :: Vivid.Polygon.t()

Convert a Box into a Polygon.

Example

iex> use Vivid
...> Box.init(Point.init(1,1), Point.init(4,4))
...> |> Box.to_polygon
Polygon.init([Point.init(1, 1), Point.init(1, 4), Point.init(4, 4), Point.init(4, 1)])

top_left(box)

@spec top_left(t()) :: Vivid.Point.t()

Return the top left corner of the box.

Example

iex> use Vivid
...> Box.init(Point.init(1,1), Point.init(4,4))
...> |> Box.top_left
Point.init(1, 4)

top_right(box)

@spec top_right(t()) :: Vivid.Point.t()

Return the top right corner of the box.

Example

iex> use Vivid
...> Box.init(Point.init(1,1), Point.init(4,4))
...> |> Box.top_right
Point.init(4, 4)