From 204ea6d991d0a747e9c44ac7b96d4047fa71e906 Mon Sep 17 00:00:00 2001 From: Boris Sekachev Date: Wed, 5 Feb 2025 15:45:26 +0200 Subject: [PATCH] Updated creation constraints --- cvat-canvas/src/typescript/consts.ts | 5 ++--- cvat-canvas/src/typescript/drawHandler.ts | 23 ++++++++++++++--------- cvat-core/src/object-utils.ts | 3 ++- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/cvat-canvas/src/typescript/consts.ts b/cvat-canvas/src/typescript/consts.ts index 3ea75dbb557d..1e39c1316879 100644 --- a/cvat-canvas/src/typescript/consts.ts +++ b/cvat-canvas/src/typescript/consts.ts @@ -1,4 +1,5 @@ // Copyright (C) 2019-2022 Intel Corporation +// Copyright (C) CVAT.ai Corporation // // SPDX-License-Identifier: MIT @@ -6,8 +7,7 @@ const BASE_STROKE_WIDTH = 1.25; const BASE_GRID_WIDTH = 2; const BASE_POINT_SIZE = 4; const TEXT_MARGIN = 10; -const AREA_THRESHOLD = 9; -const SIZE_THRESHOLD = 3; +const SIZE_THRESHOLD = 1; const POINTS_STROKE_WIDTH = 1; const POINTS_SELECTED_STROKE_WIDTH = 4; const MIN_EDGE_LENGTH = 3; @@ -36,7 +36,6 @@ export default { BASE_GRID_WIDTH, BASE_POINT_SIZE, TEXT_MARGIN, - AREA_THRESHOLD, SIZE_THRESHOLD, POINTS_STROKE_WIDTH, POINTS_SELECTED_STROKE_WIDTH, diff --git a/cvat-canvas/src/typescript/drawHandler.ts b/cvat-canvas/src/typescript/drawHandler.ts index d54117c72957..c40ed60e90f0 100644 --- a/cvat-canvas/src/typescript/drawHandler.ts +++ b/cvat-canvas/src/typescript/drawHandler.ts @@ -46,17 +46,18 @@ interface FinalCoordinates { function checkConstraint(shapeType: string, points: number[], box: Box | null = null): boolean { if (shapeType === 'rectangle') { - const [xtl, ytl, xbr, ybr] = points; - return (xbr - xtl) * (ybr - ytl) >= consts.AREA_THRESHOLD; + const [width, height] = [box.xbr - box.xtl, box.ybr - box.ytl]; + return width >= consts.SIZE_THRESHOLD && height >= consts.SIZE_THRESHOLD; } if (shapeType === 'polygon') { - return (box.xbr - box.xtl) * (box.ybr - box.ytl) >= consts.AREA_THRESHOLD && points.length >= 3 * 2; + const [width, height] = [box.xbr - box.xtl, box.ybr - box.ytl]; + return width >= consts.SIZE_THRESHOLD && height > consts.SIZE_THRESHOLD && points.length >= 3 * 2; } if (shapeType === 'polyline') { - return (box.xbr - box.xtl >= consts.SIZE_THRESHOLD || - box.ybr - box.ytl >= consts.SIZE_THRESHOLD) && points.length >= 2 * 2; + const [width, height] = [box.xbr - box.xtl, box.ybr - box.ytl]; + return (width >= consts.SIZE_THRESHOLD || height >= consts.SIZE_THRESHOLD) && points.length >= 2 * 2; } if (shapeType === 'points') { @@ -64,18 +65,22 @@ function checkConstraint(shapeType: string, points: number[], box: Box | null = } if (shapeType === 'ellipse') { - const [rx, ry] = [points[2] - points[0], points[1] - points[3]]; - return rx * ry * Math.PI >= consts.AREA_THRESHOLD; + const [width, height] = [(points[2] - points[0]) * 2, (points[1] - points[3]) * 2]; + return width >= consts.SIZE_THRESHOLD && height > consts.SIZE_THRESHOLD; } if (shapeType === 'cuboid') { return points.length === 4 * 2 || points.length === 8 * 2 || - (points.length === 2 * 2 && (points[2] - points[0]) * (points[3] - points[1]) >= consts.AREA_THRESHOLD); + (points.length === 2 * 2 && + (points[2] - points[0]) >= consts.SIZE_THRESHOLD && + (points[3] - points[1]) >= consts.SIZE_THRESHOLD + ); } if (shapeType === 'skeleton') { const [xtl, ytl, xbr, ybr] = points; - return (xbr - xtl >= 1 || ybr - ytl >= 1); + const [width, height] = [xbr - xtl, ybr - ytl]; + return width >= consts.SIZE_THRESHOLD || height >= consts.SIZE_THRESHOLD; } return false; diff --git a/cvat-core/src/object-utils.ts b/cvat-core/src/object-utils.ts index 000d169de847..1bd2b3fdedb0 100644 --- a/cvat-core/src/object-utils.ts +++ b/cvat-core/src/object-utils.ts @@ -99,8 +99,9 @@ export function checkShapeArea(shapeType: ShapeType, points: number[]): boolean ymax = Math.max(ymax, points[i + 1]); } - if (shapeType === ShapeType.POLYLINE) { + if ([ShapeType.POLYLINE, ShapeType.SKELETON].includes(shapeType)) { // horizontal / vertical lines have one of dimensions equal to zero + // skeleton also may be a line in a corner case const length = Math.max(xmax - xmin, ymax - ymin); return length >= MIN_SHAPE_SIZE; }