Bounding box coordinates for element positioning in documents.
Represents the rectangular region where an element appears within a document, using float coordinates for precise positioning.
Fields
:x0- Left x-coordinate (0.0 is the left edge):y0- Bottom y-coordinate (0.0 is the bottom edge):x1- Right x-coordinate (document width is the right edge):y1- Top y-coordinate (document height is the top edge)
Examples
iex> bbox = %Kreuzberg.BoundingBox{
...> x0: 10.5,
...> y0: 20.5,
...> x1: 100.5,
...> y1: 50.5
...> }
iex> bbox.x0
10.5
Summary
Functions
Creates a BoundingBox struct from a map.
Calculates the height of the bounding box.
Converts a BoundingBox struct to a map.
Calculates the width of the bounding box.
Types
Functions
Creates a BoundingBox struct from a map.
Converts a plain map (typically from NIF/Rust) into a proper struct.
Parameters
data- A map containing x0, y0, x1, y1 fields
Returns
A BoundingBox struct with float coordinates.
Examples
iex> bbox_map = %{"x0" => 10.5, "y0" => 20.5, "x1" => 100.5, "y1" => 50.5}
iex> Kreuzberg.BoundingBox.from_map(bbox_map)
%Kreuzberg.BoundingBox{x0: 10.5, y0: 20.5, x1: 100.5, y1: 50.5}
Calculates the height of the bounding box.
Parameters
bbox- ABoundingBoxstruct
Returns
The height (y1 - y0).
Examples
iex> bbox = %Kreuzberg.BoundingBox{x0: 10.0, y0: 20.0, x1: 110.0, y1: 70.0}
iex> Kreuzberg.BoundingBox.height(bbox)
50.0
Converts a BoundingBox struct to a map.
Useful for serialization and passing to external systems.
Parameters
bbox- ABoundingBoxstruct
Returns
A map with string keys and float values.
Examples
iex> bbox = %Kreuzberg.BoundingBox{x0: 10.5, y0: 20.5, x1: 100.5, y1: 50.5}
iex> Kreuzberg.BoundingBox.to_map(bbox)
%{"x0" => 10.5, "y0" => 20.5, "x1" => 100.5, "y1" => 50.5}
Calculates the width of the bounding box.
Parameters
bbox- ABoundingBoxstruct
Returns
The width (x1 - x0).
Examples
iex> bbox = %Kreuzberg.BoundingBox{x0: 10.0, y0: 20.0, x1: 110.0, y1: 50.0}
iex> Kreuzberg.BoundingBox.width(bbox)
100.0