Skip to content

Commit

Permalink
Fix weather wind direction computation
Browse files Browse the repository at this point in the history
  • Loading branch information
sghpjuikit committed Jan 24, 2025
1 parent 6f3fab0 commit 09709bc
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/player/main/sp/it/pl/ui/nodeinfo/WeatherInfo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -893,7 +893,7 @@ class WeatherInfo: HBox(15.0) {
/** @return cardinal direction of the [deg] value, e.g.: SE */
fun toCD(): String = when ((deg+180)%360.0) {
in 337.5..360.0 -> "N"
in 0.5.. 22.5 -> "N"
in 0.0.. 22.5 -> "N"
in 22.5.. 67.5 -> "NE"
in 67.5..112.5 -> "E"
in 112.5..157.5 -> "SE"
Expand Down
24 changes: 24 additions & 0 deletions src/player/test/sp/it/pl/ui/nodeinfo/WeatherInfoTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package sp.it.pl.ui.nodeinfo

import io.kotest.core.spec.style.FreeSpec
import io.kotest.matchers.shouldBe
import sp.it.pl.ui.nodeinfo.WeatherInfo.Companion.Types.WindDir
import sp.it.pl.ui.objects.tree.Name.Companion.treeOfPaths

class WeatherInfoTest: FreeSpec({

WindDir::toCD.name {
WindDir(0.0).toCD() shouldBe "S"
WindDir(18.0).toCD() shouldBe "S"
WindDir(45.0).toCD() shouldBe "SW"
WindDir(90.0).toCD() shouldBe "W"
WindDir(135.0).toCD() shouldBe "NW"
WindDir(180.0).toCD() shouldBe "N"
WindDir(225.0).toCD() shouldBe "NE"
WindDir(270.0).toCD() shouldBe "E"
WindDir(315.0).toCD() shouldBe "SE"
WindDir(360.0).toCD() shouldBe "S" // bounds
WindDir(400.0).toCD() shouldBe "SW" // Out of bounds
}

})

0 comments on commit 09709bc

Please sign in to comment.