# `Kreuzberg.LayoutRegion`
[🔗](https://github.com/kreuzberg-dev/kreuzberg/blob/main/lib/kreuzberg/layout_region.ex#L1)

A detected layout region on a page.

When layout detection is enabled, each page may have layout regions
identifying different content types (text, pictures, tables, etc.)
with confidence scores and spatial positions.

## Fields

  * `:class` - Layout class name (e.g. "picture", "table", "text", "section_header")
  * `:confidence` - Detection confidence score (0.0 to 1.0)
  * `:bounding_box` - Map with x0, y0, x1, y1 coordinates, or nil
  * `:area_fraction` - Fraction of page area covered (0.0 to 1.0)

## Examples

    iex> region = %Kreuzberg.LayoutRegion{
    ...>   class: "picture",
    ...>   confidence: 0.95,
    ...>   area_fraction: 0.3
    ...> }
    iex> region.class
    "picture"

# `t`

```elixir
@type t() :: %Kreuzberg.LayoutRegion{
  area_fraction: float(),
  bounding_box: map() | nil,
  class: String.t(),
  confidence: float()
}
```

# `from_map`

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

Creates a LayoutRegion struct from a map.

## Parameters

  * `data` - A map containing layout region fields

## Returns

A `LayoutRegion` struct with properly typed fields.

## Examples

    iex> Kreuzberg.LayoutRegion.from_map(%{"class" => "table", "confidence" => 0.9, "area_fraction" => 0.2})
    %Kreuzberg.LayoutRegion{class: "table", confidence: 0.9, area_fraction: 0.2}

# `to_map`

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

Converts a LayoutRegion struct to a map.

## Parameters

  * `region` - A `LayoutRegion` struct

## Returns

A map with string keys representing all fields.

## Examples

    iex> region = %Kreuzberg.LayoutRegion{class: "picture", confidence: 0.95, area_fraction: 0.3}
    iex> Kreuzberg.LayoutRegion.to_map(region)
    %{"class" => "picture", "confidence" => 0.95, "bounding_box" => nil, "area_fraction" => 0.3}

---

*Consult [api-reference.md](api-reference.md) for complete listing*
