Geometry
app.ui.qt.widgets.preview.layer_bbox.geometryGeometry and coordinate-space helpers for bbox overlay interactions.
This module converts between image space and widget space, and provides proximity lookup for selecting the nearest bbox around the cursor.
See Also
BBoxState— tracks selected and edited geometryget_drag_mode_for_rect_at_pos— detects handle hits
Layer: Presentation. Context: Contains concrete Qt presentation components and supporting utilities.
image_rect_to_widget_space(x1: int, y1: int, x2: int, y2: int, pixmap_rect: QRect, image_size: QSize | None) -> QRect
Convert image-space coordinates into a widget-space rectangle.
| PARAMETER | DESCRIPTION |
|---|---|
x1
|
Left image-space coordinate.
TYPE:
|
y1
|
Top image-space coordinate.
TYPE:
|
x2
|
Right image-space coordinate.
TYPE:
|
y2
|
Bottom image-space coordinate.
TYPE:
|
pixmap_rect
|
Displayed image rectangle in widget coordinates.
TYPE:
|
image_size
|
Original image dimensions, or
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
QRect
|
Normalized widget-space rectangle, or an empty rectangle if conversion is unavailable. |
widget_rect_to_image_space(rect: QRect, pixmap_rect: QRect, image_size: QSize | None) -> BBoxXYXYTuple
Convert a widget-space rectangle into clamped image-space coordinates.
| PARAMETER | DESCRIPTION |
|---|---|
rect
|
Bounding rectangle in widget coordinates.
TYPE:
|
pixmap_rect
|
Displayed image rectangle in widget coordinates.
TYPE:
|
image_size
|
Original image dimensions, or
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
BBoxXYXYTuple
|
|
find_bbox_at_pos(active_bboxes: dict[str, BBoxXYXYTuple], pos: QPoint, pixmap_rect: QRect, image_size: QSize | None, snap_radius_sq: int = 2500) -> tuple[str | None, QRect | None]
Find a bbox at the cursor or snap to the nearest bbox center within radius.
| PARAMETER | DESCRIPTION |
|---|---|
active_bboxes
|
Box keys mapped to image-space coordinate tuples.
TYPE:
|
pos
|
Cursor position in widget coordinates.
TYPE:
|
pixmap_rect
|
Displayed image rectangle in widget coordinates.
TYPE:
|
image_size
|
Original image dimensions, or
TYPE:
|
snap_radius_sq
|
Maximum squared widget-pixel distance from a box center for snapping.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[str | None, QRect | None]
|
|
image_rect_to_widget_space_with_transforms(x1: int, y1: int, x2: int, y2: int, pixmap_rect: QRect, image_size: QSize | None, zoom: float = 1.0, pan_x: float = 0.0, pan_y: float = 0.0) -> QRect
Convert image-space box coordinates using the displayed image rectangle.
The video widget already applies zoom/pan to the displayed image, so the overlay should use that same pixmap rect rather than re-scaling the bbox rectangle again.
| PARAMETER | DESCRIPTION |
|---|---|
x1
|
Left image-space coordinate.
TYPE:
|
y1
|
Top image-space coordinate.
TYPE:
|
x2
|
Right image-space coordinate.
TYPE:
|
y2
|
Bottom image-space coordinate.
TYPE:
|
pixmap_rect
|
Displayed image rectangle in widget coordinates.
TYPE:
|
image_size
|
Original image dimensions, or
TYPE:
|
zoom
|
Retained for API compatibility; coordinate conversion uses
TYPE:
|
pan_x
|
Retained for API compatibility; coordinate conversion uses
TYPE:
|
pan_y
|
Retained for API compatibility; coordinate conversion uses
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
QRect
|
Normalized widget-space rectangle. |
find_bbox_at_pos_with_transforms(active_bboxes: dict[str, BBoxXYXYTuple], pos: QPoint, pixmap_rect: QRect, image_size: QSize | None, zoom: float = 1.0, pan_x: float = 0.0, pan_y: float = 0.0, snap_radius_sq: int = 2500) -> tuple[str | None, QRect | None]
Find a bbox at the cursor using the viewport-aligned widget-space rect.
| PARAMETER | DESCRIPTION |
|---|---|
active_bboxes
|
Box keys mapped to image-space coordinate tuples.
TYPE:
|
pos
|
Cursor position in widget coordinates.
TYPE:
|
pixmap_rect
|
Displayed image rectangle in widget coordinates.
TYPE:
|
image_size
|
Original image dimensions, or
TYPE:
|
zoom
|
Retained for API compatibility; the supplied
TYPE:
|
pan_x
|
Retained for API compatibility; the supplied
TYPE:
|
pan_y
|
Retained for API compatibility; the supplied
TYPE:
|
snap_radius_sq
|
Maximum squared widget-pixel distance from a box center for snapping.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[str | None, QRect | None]
|
|
find_bbox_keys_intersecting_rect(active_bboxes: dict[str, BBoxXYXYTuple], selection_rect: QRect, pixmap_rect: QRect, image_size: QSize | None) -> list[str]
Return box keys whose widget-space bounds intersect a marquee rectangle.
| PARAMETER | DESCRIPTION |
|---|---|
active_bboxes
|
Box keys mapped to image-space coordinate tuples.
TYPE:
|
selection_rect
|
Marquee rectangle in widget coordinates.
TYPE:
|
pixmap_rect
|
Displayed image rectangle in widget coordinates.
TYPE:
|
image_size
|
Original image dimensions, or
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[str]
|
Keys of boxes whose widget-space rectangles intersect the marquee. |