Ensure skew is always in [-90, 90] (#319)

This commit is contained in:
Matt
2021-11-21 19:50:15 -05:00
committed by GitHub
parent a5cc0808c4
commit ffe34f00fe
2 changed files with 5 additions and 1 deletions

View File

@@ -42,6 +42,10 @@ public class TargetCalculations {
if (isLandscape && minAreaRect.size.width < minAreaRect.size.height) angle += 90;
else if (!isLandscape && minAreaRect.size.height < minAreaRect.size.width) angle += 90;
// Ensure skew is bounded on [-90, 90]
while (angle > 90) angle -= 180;
while (angle < -90) angle += 180;
return angle;
}

View File

@@ -103,7 +103,7 @@ public class TargetCalculationsTest {
public void testSkewCalculation() {
// Setup
var isLandscape = true;
var rect = new RotatedRect(new Point(), new Size(10, 5), -10);
var rect = new RotatedRect(new Point(), new Size(10, 5), 170);
// Compute min area rect
var points = new Point[4];