Skip to content

Commit 4c775af

Browse files
authored
Add bearing conversion docs example (#312)
1 parent e3a48ef commit 4c775af

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

docs/units/index.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ converting between scalars, lengths, and areas as needed.
6363

6464
`Bearing` represents an absolute geographic heading (e.g., North, East), while `Rotation` represents
6565
a relative angular displacement. In Kotlin, bearings can be rotated using operators, and the
66-
difference between two bearings is a rotation.
66+
difference between two bearings is a rotation. To convert a `Bearing` to a numeric angle, first
67+
choose a reference direction and range, such as `0..360` degrees clockwise from north or `-180..180`
68+
degrees relative to north.
6769

6870
=== "Kotlin"
6971

units/src/commonTest/kotlin/org/maplibre/spatialk/units/KotlinDocsTest.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ class KotlinDocsTest {
3737
val turnedRight: Bearing = heading + 90.degrees
3838
val turnedLeft: Bearing = heading - 45.degrees
3939
val diff: Rotation = turnedRight - turnedLeft
40+
41+
val bearing: Bearing = Bearing.Northwest
42+
val clockwiseFromNorth: Double = (bearing - Bearing.North).inDegrees
43+
val signedFromNorth: Double = Bearing.North.smallestRotationTo(bearing).inDegrees
4044
// --8<-- [end:bearings]
4145
}
4246

0 commit comments

Comments
 (0)