Skip to content

Commit

Permalink
ktlinting
Browse files Browse the repository at this point in the history
  • Loading branch information
benediktschwab committed May 9, 2024
1 parent 280729c commit bea2573
Show file tree
Hide file tree
Showing 397 changed files with 6,969 additions and 4,806 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import org.jetbrains.dokka.gradle.DokkaMultiModuleTask
if (!JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_17)) {
throw GradleException(
"This build requires Java ${JavaVersion.VERSION_17}, " +
"but version ${JavaVersion.current()} is currently in use."
"but version ${JavaVersion.current()} is currently in use.",
)
}

Expand Down
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/Plugins.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

object PluginVersions {
const val shadowjar = "8.1.1"
const val ktlint = "11.6.1"
const val ktlint = "12.1.1"
const val xjc = "1.6"
const val versionChecker = "0.51.0"
const val dokka = "1.9.20"
Expand Down
9 changes: 5 additions & 4 deletions rtron-cli/src/main/kotlin/io/rtron/cli/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ class MainCommand : CliktCommand(name = "rtron") {
*
* @param args arguments of the cli
*/
fun main(args: Array<String>) = MainCommand()
.versionOption("1.3.1")
.subcommands(SubcommandValidateOpendrive(), SubcommandOpendriveToCitygml())
.main(args)
fun main(args: Array<String>) =
MainCommand()
.versionOption("1.3.1")
.subcommands(SubcommandValidateOpendrive(), SubcommandOpendriveToCitygml())
.main(args)
114 changes: 68 additions & 46 deletions rtron-cli/src/main/kotlin/io/rtron/cli/SubcommandOpendriveToCitygml.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,88 +40,110 @@ import io.rtron.transformer.converter.roadspaces2citygml.Roadspaces2CitygmlParam
import io.rtron.transformer.evaluator.opendrive.OpendriveEvaluatorParameters
import io.rtron.transformer.modifiers.opendrive.offset.adder.OpendriveOffsetAdderParameters

class SubcommandOpendriveToCitygml : CliktCommand(name = "opendrive-to-citygml", help = "Transform OpenDRIVE datasets to CityGML.", printHelpOnEmptyArgs = true) {

class SubcommandOpendriveToCitygml : CliktCommand(
name = "opendrive-to-citygml",
help = "Transform OpenDRIVE datasets to CityGML.",
printHelpOnEmptyArgs = true,
) {
// Properties and Initializers
private val parametersPath by option(
help = "Path to a YAML file containing the parameters of the process."
help = "Path to a YAML file containing the parameters of the process.",
).path(mustExist = true)

private val inputPath by argument(
help = "Path to the directory containing OpenDRIVE datasets"
help = "Path to the directory containing OpenDRIVE datasets",
).path(mustExist = true)
private val outputPath by argument(
help = "Path to the output directory into which the transformed CityGML models are written"
help = "Path to the output directory into which the transformed CityGML models are written",
).path()

private val skipRoadShapeRemoval by option(help = "skip the removal of the road shape, if a lateral lane offset exists (not compliant to standard)").flag()
private val skipRoadShapeRemoval by option(
help = "skip the removal of the road shape, if a lateral lane offset exists (not compliant to standard)",
).flag()

private val convertToCitygml2 by option(help = "convert to CityGML 2.0 (otherwise CityGML 3.0)").flag()

private val tolerance by option(help = "allowed tolerance when comparing double values").double()
.default(Opendrive2RoadspacesParameters.DEFAULT_NUMBER_TOLERANCE)
private val planViewGeometryDistanceTolerance by option(help = "allowed distance tolerance between two geometry elements in the plan view").double()
private val planViewGeometryDistanceTolerance by option(
help = "allowed distance tolerance between two geometry elements in the plan view",
).double()
.default(OpendriveEvaluatorParameters.DEFAULT_PLAN_VIEW_GEOMETRY_DISTANCE_TOLERANCE)
private val planViewGeometryDistanceWarningTolerance by option(help = "warning distance tolerance between two geometry elements in the plan view").double()
private val planViewGeometryDistanceWarningTolerance by option(
help = "warning distance tolerance between two geometry elements in the plan view",
).double()
.default(OpendriveEvaluatorParameters.DEFAULT_PLAN_VIEW_GEOMETRY_DISTANCE_WARNING_TOLERANCE)
private val planViewGeometryAngleTolerance by option(help = "allowed angle tolerance between two geometry elements in the plan view").double()
private val planViewGeometryAngleTolerance by option(
help = "allowed angle tolerance between two geometry elements in the plan view",
).double()
.default(OpendriveEvaluatorParameters.DEFAULT_PLAN_VIEW_GEOMETRY_ANGLE_TOLERANCE)
private val planViewGeometryAngleWarningTolerance by option(help = "warning angle tolerance between two geometry elements in the plan view").double()
private val planViewGeometryAngleWarningTolerance by option(
help = "warning angle tolerance between two geometry elements in the plan view",
).double()
.default(OpendriveEvaluatorParameters.DEFAULT_PLAN_VIEW_GEOMETRY_ANGLE_WARNING_TOLERANCE)
private val crsEpsg by option(help = "EPSG code of the coordinate reference system used in the OpenDRIVE datasets").int()
.default(Opendrive2RoadspacesParameters.DEFAULT_CRS_EPSG)
private val addOffset by option(help = "offset values by which the model is translated along the x, y, and z axis").double().triple()
.default(Triple(OpendriveOffsetAdderParameters.DEFAULT_OFFSET_X, OpendriveOffsetAdderParameters.DEFAULT_OFFSET_Y, OpendriveOffsetAdderParameters.DEFAULT_OFFSET_Z))
.default(
Triple(
OpendriveOffsetAdderParameters.DEFAULT_OFFSET_X,
OpendriveOffsetAdderParameters.DEFAULT_OFFSET_Y,
OpendriveOffsetAdderParameters.DEFAULT_OFFSET_Z,
),
)
private val cropPolygon by option(help = "2D polygon outline for cropping the OpenDRIVE dataset").double().pair().multiple()
private val removeRoadObjectOfType by option(help = "Remove road object of a specific type").enum<EObjectType>().multiple().unique()

private val discretizationStepSize by option(help = "distance between each discretization step for curves and surfaces").double()
.default(Roadspaces2CitygmlParameters.DEFAULT_DISCRETIZATION_STEP_SIZE)
private val sweepDiscretizationStepSize by option(help = "distance between each discretization step for solid geometries of ParametricSweep3D").double()
private val sweepDiscretizationStepSize by option(
help = "distance between each discretization step for solid geometries of ParametricSweep3D",
).double()
.default(Roadspaces2CitygmlParameters.DEFAULT_SWEEP_DISCRETIZATION_STEP_SIZE)
private val circleSlices by option(help = "number of discretization points for a circle or cylinder").int()
.default(Roadspaces2CitygmlParameters.DEFAULT_CIRCLE_SLICES)
private val generateRandomGeometryIds by option(help = "true, if random ids shall be generated for the gml geometries").flag()
private val transformAdditionalRoadLines by option(help = "if true, additional road lines, such as the reference line, lane boundaries, etc., are also transformed").flag()
private val transformAdditionalRoadLines by option(
help = "if true, additional road lines, such as the reference line, lane boundaries, etc., are also transformed",
).flag()

private val compressionFormat: CompressionFormat by option(help = "compress the output files with the respective compression format").enum<CompressionFormat>()
private val compressionFormat: CompressionFormat by option(
help = "compress the output files with the respective compression format",
).enum<CompressionFormat>()
.default(CompressionFormat.NONE)

// Methods

override fun run() {
val parameters = parametersPath.toOption().fold({
OpendriveToCitygmlParameters(
convertToCitygml2 = convertToCitygml2,

skipRoadShapeRemoval = skipRoadShapeRemoval,

tolerance = tolerance,
planViewGeometryDistanceTolerance = planViewGeometryDistanceTolerance,
planViewGeometryDistanceWarningTolerance = planViewGeometryDistanceWarningTolerance,
planViewGeometryAngleTolerance = planViewGeometryAngleTolerance,
planViewGeometryAngleWarningTolerance = planViewGeometryAngleWarningTolerance,
crsEpsg = crsEpsg,
offsetX = addOffset.first,
offsetY = addOffset.second,
offsetZ = addOffset.third,
cropPolygonX = cropPolygon.map { it.first },
cropPolygonY = cropPolygon.map { it.second },
removeRoadObjectsOfTypes = removeRoadObjectOfType,

discretizationStepSize = discretizationStepSize,
sweepDiscretizationStepSize = sweepDiscretizationStepSize,
circleSlices = circleSlices,
generateRandomGeometryIds = generateRandomGeometryIds,
transformAdditionalRoadLines = transformAdditionalRoadLines,

compressionFormat = compressionFormat
)
}, { parametersFilePath ->
val parametersText = parametersFilePath.toFile().readText()

Yaml.default.decodeFromString(OpendriveToCitygmlParameters.serializer(), parametersText)
})
val parameters =
parametersPath.toOption().fold({
OpendriveToCitygmlParameters(
convertToCitygml2 = convertToCitygml2,
skipRoadShapeRemoval = skipRoadShapeRemoval,
tolerance = tolerance,
planViewGeometryDistanceTolerance = planViewGeometryDistanceTolerance,
planViewGeometryDistanceWarningTolerance = planViewGeometryDistanceWarningTolerance,
planViewGeometryAngleTolerance = planViewGeometryAngleTolerance,
planViewGeometryAngleWarningTolerance = planViewGeometryAngleWarningTolerance,
crsEpsg = crsEpsg,
offsetX = addOffset.first,
offsetY = addOffset.second,
offsetZ = addOffset.third,
cropPolygonX = cropPolygon.map { it.first },
cropPolygonY = cropPolygon.map { it.second },
removeRoadObjectsOfTypes = removeRoadObjectOfType,
discretizationStepSize = discretizationStepSize,
sweepDiscretizationStepSize = sweepDiscretizationStepSize,
circleSlices = circleSlices,
generateRandomGeometryIds = generateRandomGeometryIds,
transformAdditionalRoadLines = transformAdditionalRoadLines,
compressionFormat = compressionFormat,
)
}, { parametersFilePath ->
val parametersText = parametersFilePath.toFile().readText()

Yaml.default.decodeFromString(OpendriveToCitygmlParameters.serializer(), parametersText)
})

val processor = OpendriveToCitygmlProcessor(parameters)
processor.process(inputPath, outputPath)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,29 +33,40 @@ import io.rtron.transformer.converter.opendrive2roadspaces.Opendrive2RoadspacesP
import io.rtron.transformer.converter.roadspaces2citygml.Roadspaces2CitygmlParameters
import io.rtron.transformer.evaluator.opendrive.OpendriveEvaluatorParameters

class SubcommandValidateOpendrive : CliktCommand(name = "validate-opendrive", help = "Validate OpenDRIVE datasets.", printHelpOnEmptyArgs = true) {

class SubcommandValidateOpendrive : CliktCommand(
name = "validate-opendrive",
help = "Validate OpenDRIVE datasets.",
printHelpOnEmptyArgs = true,
) {
// Properties and Initializers
private val parametersPath by option(
help = "Path to a YAML file containing the parameters of the process."
help = "Path to a YAML file containing the parameters of the process.",
).path(mustExist = true)

private val inputPath by argument(
help = "Path to the directory containing OpenDRIVE datasets"
help = "Path to the directory containing OpenDRIVE datasets",
).path(mustExist = true)
private val outputPath by argument(
help = "Path to the output directory into which the reports are written"
help = "Path to the output directory into which the reports are written",
).path()

private val tolerance by option(help = "allowed tolerance when comparing double values").double()
.default(Opendrive2RoadspacesParameters.DEFAULT_NUMBER_TOLERANCE)
private val planViewGeometryDistanceTolerance by option(help = "allowed distance tolerance between two geometry elements in the plan view").double()
private val planViewGeometryDistanceTolerance by option(
help = "allowed distance tolerance between two geometry elements in the plan view",
).double()
.default(OpendriveEvaluatorParameters.DEFAULT_PLAN_VIEW_GEOMETRY_DISTANCE_TOLERANCE)
private val planViewGeometryDistanceWarningTolerance by option(help = "warning distance tolerance between two geometry elements in the plan view").double()
private val planViewGeometryDistanceWarningTolerance by option(
help = "warning distance tolerance between two geometry elements in the plan view",
).double()
.default(OpendriveEvaluatorParameters.DEFAULT_PLAN_VIEW_GEOMETRY_DISTANCE_WARNING_TOLERANCE)
private val planViewGeometryAngleTolerance by option(help = "allowed angle tolerance between two geometry elements in the plan view").double()
private val planViewGeometryAngleTolerance by option(
help = "allowed angle tolerance between two geometry elements in the plan view",
).double()
.default(OpendriveEvaluatorParameters.DEFAULT_PLAN_VIEW_GEOMETRY_ANGLE_TOLERANCE)
private val planViewGeometryAngleWarningTolerance by option(help = "warning angle tolerance between two geometry elements in the plan view").double()
private val planViewGeometryAngleWarningTolerance by option(
help = "warning angle tolerance between two geometry elements in the plan view",
).double()
.default(OpendriveEvaluatorParameters.DEFAULT_PLAN_VIEW_GEOMETRY_ANGLE_WARNING_TOLERANCE)

private val discretizationStepSize by option(help = "distance between each discretization step for curves and surfaces").double()
Expand All @@ -64,29 +75,31 @@ class SubcommandValidateOpendrive : CliktCommand(name = "validate-opendrive", he
private val skipOpendriveExport by option(help = "skip the export of the adjusted OpenDRIVE dataset").flag()
private val skipCitygmlExport by option(help = "skip the export of the CityGML dataset for visual inspection purposes").flag()

private val compressionFormat: CompressionFormat by option(help = "compress the output files with the respective compression format").enum<CompressionFormat>()
private val compressionFormat: CompressionFormat by option(
help = "compress the output files with the respective compression format",
).enum<CompressionFormat>()
.default(CompressionFormat.NONE)

// Methods
override fun run() {
val parameters = parametersPath.toOption().fold({
ValidateOpendriveParameters(
tolerance = tolerance,
planViewGeometryDistanceTolerance = planViewGeometryDistanceTolerance,
planViewGeometryDistanceWarningTolerance = planViewGeometryDistanceWarningTolerance,
planViewGeometryAngleTolerance = planViewGeometryAngleTolerance,
planViewGeometryAngleWarningTolerance = planViewGeometryAngleWarningTolerance,
discretizationStepSize = discretizationStepSize,
writeOpendriveFile = !skipOpendriveExport,
writeCitygml2File = !skipCitygmlExport,

compressionFormat = compressionFormat
)
}, { parametersFilePath ->
val parametersText = parametersFilePath.toFile().readText()
val parameters =
parametersPath.toOption().fold({
ValidateOpendriveParameters(
tolerance = tolerance,
planViewGeometryDistanceTolerance = planViewGeometryDistanceTolerance,
planViewGeometryDistanceWarningTolerance = planViewGeometryDistanceWarningTolerance,
planViewGeometryAngleTolerance = planViewGeometryAngleTolerance,
planViewGeometryAngleWarningTolerance = planViewGeometryAngleWarningTolerance,
discretizationStepSize = discretizationStepSize,
writeOpendriveFile = !skipOpendriveExport,
writeCitygml2File = !skipCitygmlExport,
compressionFormat = compressionFormat,
)
}, { parametersFilePath ->
val parametersText = parametersFilePath.toFile().readText()

Yaml.default.decodeFromString(ValidateOpendriveParameters.serializer(), parametersText)
})
Yaml.default.decodeFromString(ValidateOpendriveParameters.serializer(), parametersText)
})

val processor = ValidateOpendriveProcessor(parameters)
processor.process(inputPath, outputPath)
Expand Down
3 changes: 2 additions & 1 deletion rtron-io/src/main/kotlin/io/rtron/io/csv/CSVPrinter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,21 @@ import org.apache.commons.csv.CSVPrinter as CMCSVPrinter
* @param header header of the csv file
*/
class CSVPrinter(filePath: Path, header: List<String>) : Flushable {

// Properties and Initializers
init {
filePath.parent.createDirectories()
}

private val writer = Files.newBufferedWriter(filePath)
private val csvPrinter: CMCSVPrinter

init {
val csvFormat = Builder.create().setHeader(*header.toTypedArray()).build()
csvPrinter = CMCSVPrinter(writer, csvFormat)
}

// Methods

/**
* Prints the given [values] as a single record.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ package io.rtron.io.files
enum class CompressedFileExtension(val extension: String, val extensionWithDot: String) {
ZIP("zip", ".zip"),
GZ("gz", ".gz"),
ZST("zst", ".zst")
ZST("zst", ".zst"),
}
3 changes: 1 addition & 2 deletions rtron-io/src/main/kotlin/io/rtron/io/files/PathExtensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ fun Path.getFileSizeToDisplay(): String = FileUtils.byteCountToDisplaySize(this.
* @param maxDepth maximal depth to be traversed
* @return sequence of [Path]
*/
fun Path.walk(maxDepth: Int = Int.MAX_VALUE): Sequence<Path> =
Files.walk(this, maxDepth).asSequence().map { it }
fun Path.walk(maxDepth: Int = Int.MAX_VALUE): Sequence<Path> = Files.walk(this, maxDepth).asSequence().map { it }

/**
* Constructs a new InputStream of this file either directly or compressed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package io.rtron.io.issues

class ContextIssueList<out V>(
val value: V,
val issueList: DefaultIssueList
val issueList: DefaultIssueList,
) {
// Properties and Initializers

Expand Down
14 changes: 7 additions & 7 deletions rtron-io/src/main/kotlin/io/rtron/io/issues/DefaultIssue.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ data class DefaultIssue(
val location: String,
val incidentSeverity: Severity,
val wasFixed: Boolean,
val infoValues: Map<String, Double> = emptyMap()
val infoValues: Map<String, Double> = emptyMap(),
) {

// Properties and Initializers
val issueSeverity: Severity = when (Pair(incidentSeverity, wasFixed)) {
Pair(Severity.FATAL_ERROR, true) -> Severity.ERROR
Pair(Severity.ERROR, true) -> Severity.WARNING
else -> incidentSeverity
}
val issueSeverity: Severity =
when (Pair(incidentSeverity, wasFixed)) {
Pair(Severity.FATAL_ERROR, true) -> Severity.ERROR
Pair(Severity.ERROR, true) -> Severity.WARNING
else -> incidentSeverity
}

companion object
}
Loading

0 comments on commit bea2573

Please sign in to comment.