Return the smallest possible angle between two compass bearings

absolute_angle(from, to)

Arguments

from

The start bearing, counted clockwise from North

to

The end bearing, counted clockwise from North

Value

The smallest possible angle between the two bearings as decimal degrees within [0..360[.

Examples

testthat::expect_equal(absolute_angle(NA, 10), NA)
testthat::expect_equal(absolute_angle(10, NA), NA)
testthat::expect_equal(absolute_angle(0, 20), 20)
testthat::expect_equal(absolute_angle(20, 0), -20)
testthat::expect_equal(absolute_angle(10, 0), -10)
testthat::expect_equal(absolute_angle(20, 60), 40)
testthat::expect_equal(absolute_angle(350, 10), 20)
testthat::expect_equal(absolute_angle(10, 350), -20)