Skip to content

Commit

Permalink
remove orphaned roads belonging to partially cropped junctions
Browse files Browse the repository at this point in the history
  • Loading branch information
benediktschwab committed Apr 30, 2024
1 parent d7ce4be commit 63d5410
Showing 1 changed file with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class OpendriveCropper(
return modifiedOpendriveModel.some() to report
}

// remove the roads according depending on the
// remove all roads for which the reference line lies in the crop polygon
val roadsFiltered = modifiedOpendriveModel.road.filter { currentRoad ->
currentRoad.planView.geometry.any { cropPolygon.contains(Vector2D(it.x, it.y)) }
}
Expand All @@ -65,12 +65,17 @@ class OpendriveCropper(
currentJunction
}
// remove all the junctions with no connections left
val filteredJunctions = modifiedOpendriveModel.junction.filter { it.connection.isNotEmpty() }
val junctionsFiltered = modifiedOpendriveModel.junction.filter { it.connection.isNotEmpty() }
report.numberOfJunctionsOriginally = modifiedOpendriveModel.junction.size
report.numberOfJunctionsRemaining = filteredJunctions.size
modifiedOpendriveModel.junction = filteredJunctions
report.numberOfJunctionsRemaining = junctionsFiltered.size
modifiedOpendriveModel.junction = junctionsFiltered
val remainingJunctionsIds = modifiedOpendriveModel.junction.map { it.id }

// remove roads belonging to a junction, which was removed
val remainingJunctionIds = junctionsFiltered.map { it.id }.toSet()
val roadsFilteredFiltered = roadsFiltered.filter { currentRoad -> currentRoad.getJunctionOption().fold({ true }, { remainingJunctionIds.contains(it) }) }
modifiedOpendriveModel.road = roadsFilteredFiltered

// adjust the links of each road
everyRoad.modify(modifiedOpendriveModel) { currentRoad ->

Expand Down

0 comments on commit 63d5410

Please sign in to comment.