View Source Vivid.Box (vivid v0.4.4)

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

Functions

@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)
@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)
Link to this function

init(bottom_left, top_right)

View Source
@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)}
Link to this function

init(bottom_left, top_right, fill)

View Source
@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)}
Link to this function

init_from_bounds(shape, fill \\ false)

View Source
@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))
@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)])
@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)
@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)