# viewport_clipper

Python API: `depthai_nodes.utils.viewport_clipper`

## Classes

| Name | Description |
| --- | --- |
| [`ViewportClipper`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/utils/viewport_clipper.md#viewport_clipper-Classes-ViewportClipper) | Adjusts coordinates of points such that they are not outside of a specified viewport. |

### class `ViewportClipper`

```python
class ViewportClipper
```

Adjusts coordinates of points such that they are not outside of a specified viewport.

Methods

| Name | Description |
| --- | --- |
| [`__init__`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/utils/viewport_clipper.md#viewport_clipper-Classes-ViewportClipper-__init__) | Define rectangular clipping bounds. |
| [`clip_line`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/utils/viewport_clipper.md#viewport_clipper-Classes-ViewportClipper-clip_line) | Clips a line segment to viewport (0,1). |
| [`clip_rect`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/utils/viewport_clipper.md#viewport_clipper-Classes-ViewportClipper-clip_rect) | Clips a rectangle defined by points to viewport. |

#### method `__init__`

```python
def __init__(min_x: float, max_x: float, min_y: float, max_y: float)
```

Define rectangular clipping bounds.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `min_x` | `float` | Left coordinate of the viewport. | required |
| `max_x` | `float` | Right coordinate of the viewport. | required |
| `min_y` | `float` | Top coordinate of the viewport. | required |
| `max_y` | `float` | Bottom coordinate of the viewport. | required |

#### method `clip_line`

```python
def clip_line(pt1: tuple[float, float], pt2: tuple[float, float])
```

Clips a line segment to viewport (0,1).

Uses Cohen-Sutherland line clipping algorithm.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `pt1` | `tuple[float, float]` | Start point of the line | required |
| `pt2` | `tuple[float, float]` | End point of the line | required |

Returns

 * `tuple[tuple[float, float], tuple[float, float]] | None`: * `Clipped line`: segment as (start_point, end_point) or None if line
   is completely outside of the viewport

#### method `clip_rect`

```python
def clip_rect(points: list[tuple[float, float]]) -> list[tuple[float, float]]
```

Clips a rectangle defined by points to viewport.

Uses Sutherland-Hodgman polygon clipping algorithm.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `points` | `list[tuple[float, float]]` | List of points defining the polygon vertices | required |

Returns

| Type | Description |
| --- | --- |
| `list[tuple[float, float]]` | List of points defining the clipped polygon vertices |
