Skip to content

Add Orientation Index stress test#1237

Merged
dr-jts merged 5 commits intolibgeos:mainfrom
dr-jts:add-orientation-stress-test
Feb 11, 2025
Merged

Add Orientation Index stress test#1237
dr-jts merged 5 commits intolibgeos:mainfrom
dr-jts:add-orientation-stress-test

Conversation

@dr-jts
Copy link
Copy Markdown
Contributor

@dr-jts dr-jts commented Feb 10, 2025

Adds an Orientation Index stress test, to test the consistency of the robust Orientation Index algorithm in CGAlgorithmsDD::orientationIndex.

This is a followup to the discussion on #1184.

Orientation Index computation consistency is tested by checking:

  • all 3 permutations of input points have same index
  • all 3 permutations of input points in reverse orientation have same index
  • orientation index and reverse index have opposite sign, or are collinear

Two ways of generating test cases are provided:

Decimated Diagonal

Sample output:

DD: 000 000      FP: 000 000         LINESTRING ( 2 0, 0 2 )  - POINT ( 0 2 )
DD: +++ ---      FP: ++0 0--  <!     LINESTRING ( 2 0, 0 2 )  - POINT ( 0.10000000000000000555 1.8999999999999999112 )
DD: --- +++      FP: --0 0++  <!     LINESTRING ( 2 0, 0 2 )  - POINT ( 0.2000000000000000111 1.8000000000000000444 )
DD: +++ ---      FP: +00 00-  <!     LINESTRING ( 2 0, 0 2 )  - POINT ( 0.2999999999999999889 1.6999999999999999556 )
DD: --- +++      FP: --0 0++  <!     LINESTRING ( 2 0, 0 2 )  - POINT ( 0.4000000000000000222 1.6000000000000000888 )
DD: 000 000      FP: 000 000         LINESTRING ( 2 0, 0 2 )  - POINT ( 0.5 1.5 )
DD: +++ ---      FP: ++0 0--  <!     LINESTRING ( 2 0, 0 2 )  - POINT ( 0.5999999999999999778 1.3999999999999999112 )
DD: 000 000      FP: 000 000         LINESTRING ( 2 0, 0 2 )  - POINT ( 0.69999999999999995559 1.3000000000000000444 )
DD: 000 000      FP: 000 000         LINESTRING ( 2 0, 0 2 )  - POINT ( 0.80000000000000004441 1.1999999999999999556 )
DD: --- +++      FP: --0 0++  <!     LINESTRING ( 2 0, 0 2 )  - POINT ( 0.9000000000000000222 1.1000000000000000888 )
DD: 000 000      FP: 000 000         LINESTRING ( 2 0, 0 2 )  - POINT ( 1 1 )
DD: --- +++      FP: 0-- ++0  <!     LINESTRING ( 2 0, 0 2 )  - POINT ( 1.1000000000000000888 0.9000000000000000222 )
DD: 000 000      FP: 000 000         LINESTRING ( 2 0, 0 2 )  - POINT ( 1.1999999999999999556 0.80000000000000004441 )
DD: 000 000      FP: 000 000         LINESTRING ( 2 0, 0 2 )  - POINT ( 1.3000000000000000444 0.69999999999999995559 )
DD: +++ ---      FP: 0++ --0  <!     LINESTRING ( 2 0, 0 2 )  - POINT ( 1.3999999999999999112 0.5999999999999999778 )
DD: 000 000      FP: 000 000         LINESTRING ( 2 0, 0 2 )  - POINT ( 1.5 0.5 )
DD: --- +++      FP: 0-- ++0  <!     LINESTRING ( 2 0, 0 2 )  - POINT ( 1.6000000000000000888 0.4000000000000000222 )
DD: +++ ---      FP: 00+ -00  <!     LINESTRING ( 2 0, 0 2 )  - POINT ( 1.6999999999999999556 0.2999999999999999889 )
DD: --- +++      FP: 0-- ++0  <!     LINESTRING ( 2 0, 0 2 )  - POINT ( 1.8000000000000000444 0.2000000000000000111 )
DD: +++ ---      FP: 0++ --0  <!     LINESTRING ( 2 0, 0 2 )  - POINT ( 1.8999999999999999112 0.10000000000000000555 )
DD: 000 000      FP: 000 000         LINESTRING ( 2 0, 0 2 )  - POINT ( 2 0 )

Random segment midpoint

Sample output showing the consistency of the DD implementation, and the inconsistency of the FP implementation:

DD: 000 000      FP: 000 000         LINESTRING (1.975 9.89878, 1.22214 8.63843) - POINT (1.59857 9.2686 )
DD: +++ ---      FP: +++ ---         LINESTRING (1.97316 7.86036, 0.54432 8.52318) - POINT (1.25874 8.19177 )
DD: --- +++      FP: --- +++         LINESTRING (7.46839 7.18772, 2.2134 1.76035) - POINT (4.84089 4.47403 )
DD: --- +++      FP: --0 0++  <!     LINESTRING (7.15706 5.00496, 0.299816 1.03827) - POINT (3.72844 3.02162 )
DD: --- +++      FP: --0 0++  <!     LINESTRING (1.81436 2.57266, 9.9449 4.61921) - POINT (5.87963 3.59593 )
DD: --- +++      FP: 0-- ++0  <!     LINESTRING (0.152498 5.41789, 7.46287 6.00798) - POINT (3.80769 5.71293 )

The tester counts the number of failures encountered for both orientation index implementations. For random segment midpoint test cases, the DD implementation is robust over 10M runs, while the FP implementation shows a high percentage of consistency failures:

Final: Num tests: 10000000  DD fail = 0 (0%)  FP fail = 2358352 (24%)

@dr-jts dr-jts added the Enhancement New feature or feature improvement. label Feb 11, 2025
@dr-jts dr-jts merged commit f67563f into libgeos:main Feb 11, 2025
@dr-jts dr-jts deleted the add-orientation-stress-test branch February 11, 2025 01:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Enhancement New feature or feature improvement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant