RED-10426: sort annotations according to visual alignment.

This commit is contained in:
Nicoleta Panaghiu 2024-11-08 17:01:41 +02:00
parent c7f7ba28b6
commit c2b27765d3

View File

@ -1,6 +1,12 @@
import { AnnotationWrapper } from '@models/file/annotation.wrapper';
export const sortTopLeftToBottomRight = (a1: AnnotationWrapper, a2: AnnotationWrapper): number => {
const A = a1.y;
const B = a1.y - a1.height;
const median = (A + B) / 2;
if (median > a2.y - a2.height && median < a2.y) {
return a1.x < a2.x ? -1 : 1;
}
if (a1.y > a2.y) {
return -1;
}
@ -11,6 +17,12 @@ export const sortTopLeftToBottomRight = (a1: AnnotationWrapper, a2: AnnotationWr
};
export const sortBottomLeftToTopRight = (a1: AnnotationWrapper, a2: AnnotationWrapper): number => {
const A = a1.x;
const B = a1.x + a1.width;
const median = (A + B) / 2;
if (median < a2.x + a2.width && median > a2.x) {
return a1.y < a2.y ? -1 : 1;
}
if (a1.x < a2.x) {
return -1;
}
@ -21,6 +33,12 @@ export const sortBottomLeftToTopRight = (a1: AnnotationWrapper, a2: AnnotationWr
};
export const sortBottomRightToTopLeft = (a1: AnnotationWrapper, a2: AnnotationWrapper): number => {
const A = a1.y;
const B = a1.y + a1.height;
const median = (A + B) / 2;
if (median < a2.y + a2.height && median > a2.y) {
return a1.x > a2.x ? -1 : 1;
}
if (a1.y < a2.y) {
return -1;
}
@ -31,6 +49,12 @@ export const sortBottomRightToTopLeft = (a1: AnnotationWrapper, a2: AnnotationWr
};
export const sortTopRightToBottomLeft = (a1: AnnotationWrapper, a2: AnnotationWrapper): number => {
const A = a1.x;
const B = a1.x - a1.width;
const median = (A + B) / 2;
if (median > a2.x - a2.width && median < a2.x) {
return a1.y > a2.y ? -1 : 1;
}
if (a1.x > a2.x) {
return -1;
}