Skip to content

Commit ab83757

Browse files
fixed spacing bug in road mark building
1 parent 7967838 commit ab83757

File tree

1 file changed

+51
-48
lines changed
  • rtron-transformer/src/main/kotlin/io/rtron/transformer/converter/opendrive2roadspaces/roadspaces

1 file changed

+51
-48
lines changed

rtron-transformer/src/main/kotlin/io/rtron/transformer/converter/opendrive2roadspaces/roadspaces/RoadMarkingBuilder.kt

+51-48
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import arrow.core.None
2121
import arrow.core.Some
2222
import arrow.core.flattenOption
2323
import arrow.core.getOrElse
24+
import arrow.core.some
2425
import arrow.core.toNonEmptyListOrNone
2526
import io.rtron.io.issues.ContextIssueList
2627
import io.rtron.io.issues.DefaultIssue
@@ -228,6 +229,56 @@ class RoadMarkingBuilder(
228229
}
229230
}
230231

232+
private fun buildRoadMarkings(
233+
roadMarkingCurvePositionStart: Double,
234+
typeLines: NonEmptyList<RoadLanesLaneSectionLCRLaneRoadMarkTypeLine>,
235+
domain: Range<Double>,
236+
laneChange: LaneChange,
237+
generalAttributeList: AttributeList,
238+
): List<RoadMarking> {
239+
require(domain.hasUpperBound()) { "Domain must have an upper bound." }
240+
241+
return typeLines.withIndex()
242+
.flatMap { (currentIndex, currentTypeLine) ->
243+
val typeLineAttributes =
244+
attributes("${parameters.attributesPrefix}roadMarking_typeLine_") {
245+
attribute("index", currentIndex)
246+
attribute("width", currentTypeLine.width)
247+
}
248+
val currentTypeLineCurvePositionStart = roadMarkingCurvePositionStart + currentTypeLine.sOffset
249+
val lateralOffset =
250+
if (currentTypeLine.tOffset < parameters.numberTolerance) None else Some(currentTypeLine.tOffset)
251+
252+
val step = currentTypeLine.length + currentTypeLine.space
253+
(0..floor((domain.upperEndpointOrNull()!! - currentTypeLineCurvePositionStart) / step).toInt())
254+
.map { currentRegularIndex ->
255+
val start = currentTypeLineCurvePositionStart + currentRegularIndex * step
256+
val end =
257+
if (start + currentTypeLine.length < domain.upperEndpointOrNull()!!) {
258+
start + currentTypeLine.length
259+
} else {
260+
domain.upperEndpointOrNull()!!
261+
}
262+
if (end - start < parameters.numberTolerance) return@map None
263+
264+
val attributes =
265+
attributes("${parameters.attributesPrefix}roadMarking_typeLine_regular_") {
266+
attribute("index", currentIndex)
267+
attribute("curvePositionStart", start)
268+
attribute("curvePositionEnd", end)
269+
}
270+
271+
RoadMarking(
272+
Range.closed(start, end),
273+
currentTypeLine.width,
274+
lateralOffset,
275+
laneChange,
276+
generalAttributeList + typeLineAttributes + attributes,
277+
).some()
278+
}.flattenOption()
279+
}
280+
}
281+
231282
private fun buildRoadMarkings(
232283
roadMarkingCurvePositionStart: Double,
233284
explicitLines: NonEmptyList<RoadLanesLaneSectionLCRLaneRoadMarkExplicitLine>,
@@ -252,52 +303,4 @@ class RoadMarkingBuilder(
252303
)
253304
RoadMarking(currentEntryDomain, currentExplicitLine.width, lateralOffset, laneChange, generalAttributeList + attributes)
254305
}.toNonEmptyListOrNone().getOrElse { throw IllegalArgumentException("Explicit road markings must contain at least one entry.") }
255-
256-
private fun buildRoadMarkings(
257-
roadMarkingCurvePositionStart: Double,
258-
typeLines: NonEmptyList<RoadLanesLaneSectionLCRLaneRoadMarkTypeLine>,
259-
domain: Range<Double>,
260-
laneChange: LaneChange,
261-
generalAttributeList: AttributeList,
262-
): List<RoadMarking> {
263-
require(domain.hasUpperBound()) { "Domain must have an upper bound." }
264-
265-
return typeLines.withIndex().flatMap { (currentIndex, currentTypeLine) ->
266-
val typeLineAttributes =
267-
attributes("${parameters.attributesPrefix}roadMarking_typeLine_") {
268-
attribute("index", currentIndex)
269-
attribute("width", currentTypeLine.width)
270-
}
271-
val currentTypeLineCurvePositionStart = roadMarkingCurvePositionStart + currentTypeLine.sOffset
272-
val lateralOffset =
273-
if (currentTypeLine.tOffset < parameters.numberTolerance) None else Some(currentTypeLine.tOffset)
274-
275-
val step = currentTypeLine.length + currentTypeLine.space
276-
(0..floor((domain.upperEndpointOrNull()!! - currentTypeLineCurvePositionStart) / step).toInt())
277-
.map { currentRegularIndex ->
278-
val start = currentTypeLineCurvePositionStart + currentRegularIndex * step
279-
val end =
280-
if (start + currentTypeLine.length < domain.upperEndpointOrNull()!!) {
281-
start + currentTypeLine.length
282-
} else {
283-
domain.upperEndpointOrNull()!!
284-
}
285-
286-
val attributes =
287-
attributes("${parameters.attributesPrefix}roadMarking_typeLine_regular_") {
288-
attribute("index", currentIndex)
289-
attribute("curvePositionStart", start)
290-
attribute("curvePositionEnd", end)
291-
}
292-
293-
RoadMarking(
294-
Range.closed(start, end),
295-
currentTypeLine.width,
296-
lateralOffset,
297-
laneChange,
298-
generalAttributeList + typeLineAttributes + attributes,
299-
)
300-
}
301-
}
302-
}
303306
}

0 commit comments

Comments
 (0)