Skip to content

Commit

Permalink
Updated creation constraints
Browse files Browse the repository at this point in the history
  • Loading branch information
bsekachev committed Feb 5, 2025
1 parent 8d6ad95 commit 204ea6d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
5 changes: 2 additions & 3 deletions cvat-canvas/src/typescript/consts.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// Copyright (C) 2019-2022 Intel Corporation
// Copyright (C) CVAT.ai Corporation
//
// SPDX-License-Identifier: MIT

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;
Expand Down Expand Up @@ -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,
Expand Down
23 changes: 14 additions & 9 deletions cvat-canvas/src/typescript/drawHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,36 +46,41 @@ 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') {
return points.length > 2 || (points.length === 2 && points[0] !== 0 && points[1] !== 0);
}

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;
Expand Down
3 changes: 2 additions & 1 deletion cvat-core/src/object-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 204ea6d

Please sign in to comment.