# viewport_clipper

Python API: `depthai_nodes.utils.viewport_clipper`

## Classes

### ViewportClipper

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

#### Methods

##### init

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

Define rectangular clipping bounds.

Parameters

 * `min_x` (`float`): Left coordinate of the viewport.
 * `max_x` (`float`): Right coordinate of the viewport.
 * `min_y` (`float`): Top coordinate of the viewport.
 * `max_y` (`float`): Bottom coordinate of the viewport.

##### 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.

Parameters

 * `pt1` (`tuple[float, float]`): Start point of the line
 * `pt2` (`tuple[float, float]`): End point of the line

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

##### 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.

Parameters

 * `points` (`list[tuple[float, float]]`): List of points defining the polygon vertices

Returns

 * `list[tuple[float, float]]`: List of points defining the clipped polygon vertices
