-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #393 from lunit-io/feature/VIEWER-135-add-onChange
VIEWER-135 / add onChange prop to AnnotationOverlay
- Loading branch information
Showing
20 changed files
with
414 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
...ight-viewer/src/Annotation/components/AnnotationOverlay/utils/getIsComplexPolygon.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { getIsComplexPolygon } from './getIsComplexPolygon' | ||
import { ID1_POLYGON, ID2_POLYGON, COMPLEX_POLYGON } from '../../../../mocks/polygons' | ||
|
||
describe('getIsComplexPolygon:', () => { | ||
it('the id 1 contour polygon shouldn`t be complex', () => { | ||
expect(getIsComplexPolygon(ID1_POLYGON.points)).toBeFalsy() | ||
}) | ||
it('the id 2 contour polygon shouldn`t be complex', () => { | ||
expect(getIsComplexPolygon(ID2_POLYGON.points)).toBeFalsy() | ||
}) | ||
it('the polygon should be complex', () => { | ||
expect(getIsComplexPolygon(COMPLEX_POLYGON.points)).toBeTruthy() | ||
}) | ||
}) |
32 changes: 32 additions & 0 deletions
32
libs/insight-viewer/src/Annotation/components/AnnotationOverlay/utils/getIsComplexPolygon.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* eslint-disable no-plusplus */ | ||
|
||
import { getIsIntersection } from './getIsIntersection' | ||
import { Point } from '../../../types' | ||
|
||
/** | ||
* Check if polygon is a complex polygon with intersection | ||
* @param polygon Array<[number, number]> | ||
*/ | ||
export function getIsComplexPolygon(polygon: Point[]): boolean { | ||
// Adds an initial point as an endpoint to create a closed polygon | ||
const closedPolygon: Point[] = [...polygon, polygon[0]] | ||
const max = closedPolygon.length | ||
|
||
let i = -1 | ||
while (++i < max - 2) { | ||
// Since there is no need to search before the current point i, | ||
// it searches from the point after i | ||
let n = i + 2 | ||
while (++n < max - 1) { | ||
// Check if line a -> b and line c -> d intersect | ||
// i becomes point a and i + 1 becomes point b | ||
// i + 2 becomes c, i + 3 becomes d | ||
// i + 1 -> i + 2 is in contact with i -> i + 1 and cannot intersect, so we exclude it | ||
if (getIsIntersection(closedPolygon[i], closedPolygon[i + 1], closedPolygon[n], closedPolygon[n + 1])) { | ||
return true | ||
} | ||
} | ||
} | ||
|
||
return false | ||
} |
34 changes: 34 additions & 0 deletions
34
...nsight-viewer/src/Annotation/components/AnnotationOverlay/utils/getIsIntersection.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { Point } from '../../../../types' | ||
import { getIsIntersection } from './getIsIntersection' | ||
|
||
describe('getIsIntersection:', () => { | ||
/* | ||
* a is line 1 start point | ||
* b is line 1 end point | ||
* c is line 2 start point | ||
* d is line 2 end point | ||
* | ||
* ab is line 1, cd is line 2 | ||
*/ | ||
|
||
it('ab and cd should be intersect', () => { | ||
const [a, b, c, d]: Point[] = [ | ||
[0, 0], | ||
[10, 10], | ||
[10, 0], | ||
[0, 10], | ||
] | ||
|
||
expect(getIsIntersection(a, b, c, d)).toBeTruthy() | ||
}) | ||
it('ab and cd shouldn`t be intersect', () => { | ||
const [a, b, c, d]: Point[] = [ | ||
[0, 0], | ||
[10, 0], | ||
[0, 10], | ||
[10, 10], | ||
] | ||
|
||
expect(getIsIntersection(a, b, c, d)).toBeFalsy() | ||
}) | ||
}) |
Oops, something went wrong.