Using QPolygonF instead of drawLine
This commit is contained in:
@@ -16,8 +16,9 @@ from PySide6.QtGui import (
|
|||||||
QKeyEvent,
|
QKeyEvent,
|
||||||
QMouseEvent,
|
QMouseEvent,
|
||||||
QPaintEvent,
|
QPaintEvent,
|
||||||
|
QPolygonF,
|
||||||
)
|
)
|
||||||
from PySide6.QtCore import Qt, QEvent, Signal, QPoint, QRect
|
from PySide6.QtCore import Qt, QEvent, Signal, QPoint, QPointF, QRect
|
||||||
from typing import Any, Dict, List, Optional, Tuple
|
from typing import Any, Dict, List, Optional, Tuple
|
||||||
|
|
||||||
from src.utils.image import Image, ImageLoadError
|
from src.utils.image import Image, ImageLoadError
|
||||||
@@ -496,8 +497,10 @@ class AnnotationCanvasWidget(QWidget):
|
|||||||
)
|
)
|
||||||
|
|
||||||
painter.setPen(pen)
|
painter.setPen(pen)
|
||||||
for (x1, y1), (x2, y2) in zip(polyline[:-1], polyline[1:]):
|
# Use QPolygonF for efficient polygon rendering (single call vs N-1 calls)
|
||||||
painter.drawLine(int(x1), int(y1), int(x2), int(y2))
|
# drawPolygon() automatically closes the shape, ensuring proper visual closure
|
||||||
|
polygon = QPolygonF([QPointF(x, y) for x, y in polyline])
|
||||||
|
painter.drawPolygon(polygon)
|
||||||
|
|
||||||
# Draw bounding boxes (dashed) if enabled
|
# Draw bounding boxes (dashed) if enabled
|
||||||
if self.show_bboxes and self.original_pixmap is not None and self.bboxes:
|
if self.show_bboxes and self.original_pixmap is not None and self.bboxes:
|
||||||
|
|||||||
Reference in New Issue
Block a user