View Source Vivid.Bounds (vivid v0.4.4)

Provides information about the bounds of a box and pixel positions within it.

Example

iex> use Vivid ...> Box.init(Point.init(5,10),Point.init(15,20)) ...> |> Bounds.bounds() %Vivid.Bounds{min: Vivid.Point.init(5, 10), max: Vivid.Point.init(15, 20)}

Summary

Functions

Return the bounding box required to encapsulate the shape.

Returns the center point of the bounds.

Returns true if the point is within the bounds.

Returns the height of a shape.

Initialise arbitrary bounds.

Returns the top-right point of the bounds.

Returns the bottom-left point of the bounds.

Returns the width of a shape.

Types

@type t() :: %Vivid.Bounds{max: Vivid.Point.t(), min: Vivid.Point.t()}

Functions

@spec bounds(Vivid.Shape.t()) :: t()

Return the bounding box required to encapsulate the shape.

  • shape - A shape whose bounds you want to measure.

Example

iex> Vivid.Circle.init(Vivid.Point.init(10,10), 10)
...> |> Vivid.Bounds.bounds
%Vivid.Bounds{min: Vivid.Point.init(0.0, 0.0), max: Vivid.Point.init(20.0, 20.0)}
@spec center_of(Vivid.Shape.t()) :: Vivid.Point.t()

Returns the center point of the bounds.

  • shape - The shape whose center-most pixel you want to find.

Example

iex> Vivid.Circle.init(Vivid.Point.init(10,10), 10)
...> |> Vivid.Circle.to_polygon
...> |> Vivid.Bounds.center_of
Vivid.Point.init(10.0, 10.0)
@spec contains?(Vivid.Shape.t(), Vivid.Point.t()) :: boolean()

Returns true if the point is within the bounds.

  • shape - A shape you wish to test.
  • point - The point you wish to test.

Examples

  iex> Vivid.Bounds.init(0, 0, 10, 10)
  ...> |> Vivid.Bounds.contains?(Vivid.Point.init(0, 0))
  true

  iex> Vivid.Bounds.init(0, 0, 10, 10)
  ...> |> Vivid.Bounds.contains?(Vivid.Point.init(5, 5))
  true

  iex> Vivid.Bounds.init(0, 0, 10, 10)
  ...> |> Vivid.Bounds.contains?(Vivid.Point.init(-1, -1))
  false

  iex> Vivid.Bounds.init(0, 0, 10, 10)
  ...> |> Vivid.Bounds.contains?(Vivid.Point.init(-10, -10))
  false

  iex> Vivid.Bounds.init(0, 0, 10, 10)
  ...> |> Vivid.Bounds.contains?(Vivid.Point.init(10, 10))
  true

  iex> Vivid.Bounds.init(0, 0, 10, 10)
  ...> |> Vivid.Bounds.contains?(Vivid.Point.init(11, 11))
  false
@spec height(Vivid.Shape.t()) :: number()

Returns the height of a shape.

  • shape - The shape whose height you want to measure.

Example

iex> Vivid.Circle.init(Vivid.Point.init(10,10), 10)
...> |> Vivid.Bounds.height
20.0
@spec init(number(), number(), number(), number()) :: t()

Initialise arbitrary bounds.

  • x0 - The x coordinate of the bottom-left pixel.
  • y0 - The y coordinate of the bottom-left pixel.
  • x1 - The x coordinate of the top-right pixel.
  • y1 - The y coordinate of the top-right pixel.

Example

iex> Vivid.Bounds.init(0, 0, 5, 5)
%Vivid.Bounds{min: Vivid.Point.init(0, 0), max: Vivid.Point.init(5, 5)}
@spec max(Vivid.Shape.t()) :: Vivid.Point.t()

Returns the top-right point of the bounds.

  • shape - The shape whose top-right pixel you want to find.

Example

iex> Vivid.Circle.init(Vivid.Point.init(10,10), 10)
...> |> Vivid.Bounds.max
Vivid.Point.init(20.0, 20.0)
@spec min(Vivid.Shape.t()) :: Vivid.Point.t()

Returns the bottom-left point of the bounds.

  • shape - The shape whose bottom-left pixel you want to find.

Example

iex> Vivid.Circle.init(Vivid.Point.init(10,10), 10)
...> |> Vivid.Bounds.min
Vivid.Point.init(0.0, 0.0)
@spec width(Vivid.Shape.t()) :: number()

Returns the width of a shape.

  • shape - The shape whose width you want to measure.

Example

iex> Vivid.Circle.init(Vivid.Point.init(10,10), 10)
...> |> Vivid.Bounds.width
20.0