Skip to content

Commit

Permalink
move Direction class to Oneway.kt
Browse files Browse the repository at this point in the history
  • Loading branch information
westnordost committed Oct 14, 2024
1 parent b48bb09 commit 9be6620
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 21 deletions.
21 changes: 20 additions & 1 deletion app/src/main/java/de/westnordost/streetcomplete/osm/Oneway.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package de.westnordost.streetcomplete.osm

import de.westnordost.streetcomplete.osm.cycleway.Direction
import kotlinx.serialization.Serializable

fun isForwardOneway(tags: Map<String, String>): Boolean =
tags["oneway"] == "yes"
Expand All @@ -25,3 +25,22 @@ fun isNotOnewayForCyclists(tags: Map<String, String>, isLeftHandTraffic: Boolean
fun isInContraflowOfOneway(tags: Map<String, String>, direction: Direction): Boolean =
isForwardOneway(tags) && direction == Direction.BACKWARD
|| isReversedOneway(tags) && direction == Direction.FORWARD

@Serializable
enum class Direction {
FORWARD,
BACKWARD,
BOTH;

fun reverse(): Direction = when (this) {
FORWARD -> BACKWARD
BACKWARD -> FORWARD
BOTH -> BOTH
}

companion object {
/** Return the default direction of a oneway if nothing is specified */
fun getDefault(isRightSide: Boolean, isLeftHandTraffic: Boolean): Direction =
if (isRightSide xor isLeftHandTraffic) FORWARD else BACKWARD
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package de.westnordost.streetcomplete.osm.cycleway

import de.westnordost.streetcomplete.data.meta.CountryInfo
import de.westnordost.streetcomplete.osm.Direction
import de.westnordost.streetcomplete.osm.cycleway.Cycleway.*
import de.westnordost.streetcomplete.osm.cycleway.Direction.*
import de.westnordost.streetcomplete.osm.Direction.*
import de.westnordost.streetcomplete.osm.isForwardOneway
import de.westnordost.streetcomplete.osm.isInContraflowOfOneway
import de.westnordost.streetcomplete.osm.isNotOnewayForCyclists
Expand Down Expand Up @@ -66,19 +67,6 @@ fun CyclewayAndDirection.isSelectable(countryInfo: CountryInfo): Boolean =
// only allow dual track, dual lanes and "dual" sidewalk (not dual pictograms or something)
(direction != BOTH || cycleway in listOf(TRACK, UNSPECIFIED_LANE, EXCLUSIVE_LANE, SIDEWALK_EXPLICIT))

@Serializable
enum class Direction {
FORWARD,
BACKWARD,
BOTH;

fun reverse(): Direction = when (this) {
FORWARD -> BACKWARD
BACKWARD -> FORWARD
BOTH -> BOTH
}
}

@Serializable
enum class Cycleway {
/** a.k.a. cycle lane with continuous markings, dedicated lane or simply (proper) lane. Usually
Expand Down Expand Up @@ -219,10 +207,6 @@ fun getSelectableCycleways(
return cycleways.map { CyclewayAndDirection(it, dir) } + dualCycleways
}

/** Return the default direction of a cycleway if nothing is specified */
fun Direction.Companion.getDefault(isRightSide: Boolean, isLeftHandTraffic: Boolean): Direction =
if (isRightSide xor isLeftHandTraffic) FORWARD else BACKWARD

val CyclewayAndDirection.estimatedWidth: Float get() = when (cycleway) {
EXCLUSIVE_LANE -> 1.5f
ADVISORY_LANE -> 1f
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@ import android.view.View
import androidx.appcompat.app.AlertDialog
import de.westnordost.streetcomplete.R
import de.westnordost.streetcomplete.data.elementfilter.toElementFilterExpression
import de.westnordost.streetcomplete.osm.Direction
import de.westnordost.streetcomplete.osm.cycleway.Cycleway
import de.westnordost.streetcomplete.osm.cycleway.CyclewayAndDirection
import de.westnordost.streetcomplete.osm.cycleway.Direction
import de.westnordost.streetcomplete.osm.cycleway.LeftAndRightCycleway
import de.westnordost.streetcomplete.osm.cycleway.asDialogItem
import de.westnordost.streetcomplete.osm.cycleway.asStreetSideItem
import de.westnordost.streetcomplete.osm.cycleway.getDefault
import de.westnordost.streetcomplete.osm.cycleway.getSelectableCycleways
import de.westnordost.streetcomplete.osm.cycleway.parseCyclewaySides
import de.westnordost.streetcomplete.osm.cycleway.selectableOrNullValues
Expand Down Expand Up @@ -124,6 +123,7 @@ class AddCyclewayForm : AStreetSideSelectForm<CyclewayAndDirection, LeftAndRight
private val likelyNoBicycleContraflow = """
ways with oneway:bicycle != no and (
oneway ~ yes|-1 and highway ~ primary|primary_link|secondary|secondary_link|tertiary|tertiary_link|unclassified
or dual_carriageway = yes
or junction ~ roundabout|circular
)
""".toElementFilterExpression()
Expand Down

0 comments on commit 9be6620

Please sign in to comment.