vivid v0.4.2 Vivid.Box 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"

Link to this section 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

Link to this section Types

Link to this section Functions

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
#Vivid.Point<{1, 1}>

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
#Vivid.Point<{4, 1}>

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))
#Vivid.Box<[bottom_left: #Vivid.Point<{1, 1}>, top_right: #Vivid.Point<{4, 4}>]>
Link to this function init(bottom_left, top_right, fill) View Source

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))
#Vivid.Box<[bottom_left: #Vivid.Point<{1, 1}>, top_right: #Vivid.Point<{4, 4}>]>
Link to this function init_from_bounds(shape, fill \\ false) View Source
init_from_bounds(Vivid.Shape.t, boolean) :: Vivid.Box.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
#Vivid.Box<[bottom_left: #Vivid.Point<{0.0, 0.2447174185242318}>, top_right: #Vivid.Point<{10.0, 9.755282581475768}>]>

Convert a Box into a Polygon.

Example

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

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
#Vivid.Point<{1, 4}>

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
#Vivid.Point<{4, 4}>