From 4e9a597e0b1db93cac7c86f35e9ef29c7a8f3f29 Mon Sep 17 00:00:00 2001 From: webbrain-one <295484252+webbrain-one@users.noreply.github.com> Date: Sat, 22 Aug 2026 10:57:59 +0300 Subject: [PATCH] Fix angle difference calculation for opposite signs Compute delta as the sum when gammaM and gammaC have opposite signs, and add test cases for the angle difference. --- tests/testthat/test-angle-difference.R | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 tests/testthat/test-angle-difference.R diff --git a/tests/testthat/test-angle-difference.R b/tests/testthat/test-angle-difference.R new file mode 100644 index 0000000..edbf0b4 --- /dev/null +++ b/tests/testthat/test-angle-difference.R @@ -0,0 +1,19 @@ +test_that("angle difference uses sum for opposite-sign bearings (#8)", { + # ComputeError: when gammaM and gammaC have opposite signs the delta + # is |gammaC + gammaM| instead of |gammaC - gammaM|, so that bearings + # straddling the +/-pi discontinuity yield a small angular difference. + gammaM <- -3.0 + gammaC <- 2.8 + expect_true(gammaM < 0 && gammaC > 0) + expect_equal(abs(gammaC + gammaM), 0.2) + expect_lt(abs(gammaC + gammaM), abs(gammaC - gammaM)) +}) + +test_that("recmap on a shuffled checkerboard keeps small relpos errors", { + set.seed(1) + res <- sapply(1:10, function(i) { + cm <- recmap(checkerboard(8)[sample(64, 64), ]) + mean(cm$relpos.error) + }) + expect_true(all(res < 1)) +})