The function finds the point/points at which two line segments intersect each other. It has a high complexity, probably because there are many different geometry cases to take into account.
Refactoring
The are some simple refactoring that could be done with code repitition that don't reduce the complexity, which can be found here: commit: refactor plan. I then did a larger refactor, where I separated two larger cases from the main function: the case where the line sigments are colinear (on top of each other) and when there is a single unique intersection point. The complexity is reduced to 3 by doing this. It can be seen as being "too much", but personally I feel like the logic becomes more clear in this way. The final refactoring result can be found in commit: refactoring.
Tests
For the four tests, I decided to test some of the complex cases that were previously not dealt with. I tested the cases were
All points are on a single point
The line segments don't intersect
One line is a single point, the other line is a segment
Description
The function finds the point/points at which two line segments intersect each other. It has a high complexity, probably because there are many different geometry cases to take into account.
Refactoring
The are some simple refactoring that could be done with code repitition that don't reduce the complexity, which can be found here: commit: refactor plan. I then did a larger refactor, where I separated two larger cases from the main function: the case where the line sigments are colinear (on top of each other) and when there is a single unique intersection point. The complexity is reduced to 3 by doing this. It can be seen as being "too much", but personally I feel like the logic becomes more clear in this way. The final refactoring result can be found in commit: refactoring.
Tests
For the four tests, I decided to test some of the complex cases that were previously not dealt with. I tested the cases were
See commit: tests for the tests.
Data from Lizard tool:
./src/main/java/com/williamfiset/algorithms/geometry/LineSegmentLineSegmentIntersection.java
Data JaCoCo: