Merge branch 'RED-10426' into 'master'

RED-10426: sort annotations according to visual alignment.

See merge request redactmanager/red-ui!490
This commit is contained in:
Dan Percic 2024-11-08 16:08:09 +01:00
commit 3d31728194

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;
}