diff --git a/apps/red-ui/src/app/modules/file-preview/utils/sort-by-page-rotation.utils.ts b/apps/red-ui/src/app/modules/file-preview/utils/sort-by-page-rotation.utils.ts index 4ccce0755..6a18812ac 100644 --- a/apps/red-ui/src/app/modules/file-preview/utils/sort-by-page-rotation.utils.ts +++ b/apps/red-ui/src/app/modules/file-preview/utils/sort-by-page-rotation.utils.ts @@ -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; }