Skip to content

Commit

Permalink
Slightly refactored
Browse files Browse the repository at this point in the history
  • Loading branch information
bsekachev committed Feb 5, 2025
1 parent c40e9a2 commit 97cc505
Showing 1 changed file with 26 additions and 24 deletions.
50 changes: 26 additions & 24 deletions cvat-core/src/object-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,37 +79,39 @@ export function checkShapeArea(shapeType: ShapeType, points: number[]): boolean
return area >= 1;
}

let width = 0;
let height = 0;

if (shapeType === ShapeType.RECTANGLE) {
const [xtl, ytl, xbr, ybr] = points;
return (xbr - xtl) >= MIN_SHAPE_SIZE && (ybr - ytl) >= MIN_SHAPE_SIZE;
}

if (shapeType === ShapeType.ELLIPSE) {
[width, height] = [xbr - xtl, ybr - ytl];
} else if (shapeType === ShapeType.ELLIPSE) {
const [cx, cy, rightX, topY] = points;
const [width, height] = [(rightX - cx) * 2, (cy - topY) * 2];
return width >= MIN_SHAPE_SIZE && height >= MIN_SHAPE_SIZE;
}
[width, height] = [(rightX - cx) * 2, (cy - topY) * 2];
} else {
// polygon, polyline, cuboid, skeleton
let xmin = Number.MAX_SAFE_INTEGER;
let xmax = Number.MIN_SAFE_INTEGER;
let ymin = Number.MAX_SAFE_INTEGER;
let ymax = Number.MIN_SAFE_INTEGER;

for (let i = 0; i < points.length - 1; i += 2) {
xmin = Math.min(xmin, points[i]);
xmax = Math.max(xmax, points[i]);
ymin = Math.min(ymin, points[i + 1]);
ymax = Math.max(ymax, points[i + 1]);
}

// polygon, polyline, cuboid, skeleton
let xmin = Number.MAX_SAFE_INTEGER;
let xmax = Number.MIN_SAFE_INTEGER;
let ymin = Number.MAX_SAFE_INTEGER;
let ymax = Number.MIN_SAFE_INTEGER;

for (let i = 0; i < points.length - 1; i += 2) {
xmin = Math.min(xmin, points[i]);
xmax = Math.max(xmax, points[i]);
ymin = Math.min(ymin, points[i + 1]);
ymax = Math.max(ymax, points[i + 1]);
}
if (shapeType === ShapeType.POLYLINE) {
// horizontal / vertical lines have one of dimensions equal to zero
const length = Math.max(xmax - xmin, ymax - ymin);
return length >= MIN_SHAPE_SIZE;
}

if (shapeType === ShapeType.POLYLINE) {
// horizontal / vertical lines have one of dimensions equal to zero
const length = Math.max(xmax - xmin, ymax - ymin);
return length >= MIN_SHAPE_SIZE;
[width, height] = [xmax - xmin, ymax - ymin];
}

return (xmax - xmin) >= MIN_SHAPE_SIZE && (ymax - ymin) >= MIN_SHAPE_SIZE;
return width >= MIN_SHAPE_SIZE && height >= MIN_SHAPE_SIZE;
}

export function rotatePoint(x: number, y: number, angle: number, cx = 0, cy = 0): number[] {
Expand Down

0 comments on commit 97cc505

Please sign in to comment.