Kreuzberg.BoundingBox (kreuzberg v4.4.2)

Copy Markdown View Source

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

t()

@type t() :: %Kreuzberg.BoundingBox{
  x0: float(),
  x1: float(),
  y0: float(),
  y1: float()
}

Functions

from_map(data)

@spec from_map(map()) :: t()

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}

height(bounding_box)

@spec height(t()) :: float()

Calculates the height of the bounding box.

Parameters

  • bbox - A BoundingBox struct

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

to_map(bbox)

@spec to_map(t()) :: map()

Converts a BoundingBox struct to a map.

Useful for serialization and passing to external systems.

Parameters

  • bbox - A BoundingBox struct

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}

width(bounding_box)

@spec width(t()) :: float()

Calculates the width of the bounding box.

Parameters

  • bbox - A BoundingBox struct

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