Skip to content

Commit

Permalink
consider boundaries correct when trying to split the polygons
Browse files Browse the repository at this point in the history
  • Loading branch information
danielfeismann committed May 15, 2024
1 parent 8ccbdf6 commit 8319add
Showing 1 changed file with 32 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,23 +138,53 @@ object BoundaryFactory {

}

/** Split node sequences of polygons into parts. If the sequence can't be
* split because it represents only one polygon, the sequence is returned
* with the first node added at the end to close the polygon.
*
* @param seq
* Sequence to split
* @tparam A
* type of sequence
* @return
* Indexed map with the split sequences
*/

private def splitByKey[A](seq: Seq[A]): Map[Int, Seq[A]] = {
seq
val result = seq
.foldLeft((Map.empty[Int, Seq[A]], Map.empty[A, Int], 0)) {
case ((acc, indexes, splitIdx), elem) =>
indexes.get(elem) match {
case Some(prevIdx) =>
// Element has been seen before
val newSeq = seq.slice(prevIdx, splitIdx + 1)
(
acc + (acc.size + 1 -> newSeq),
indexes + (elem -> splitIdx),
splitIdx + 1
)
case None =>
(acc, indexes + (elem -> splitIdx), splitIdx + 1)
// Element has not been seen before
(
acc,
indexes + (elem -> splitIdx),
splitIdx + 1
)
}
}
._1

// If the result map is empty, return the whole sequence with the first element appended at the end
// (to close the polygon)
if (result.isEmpty) {
seq.headOption match {
case Some(firstElem) => Map(1 -> (seq :+ firstElem))
case None =>
Map(1 -> seq)
}
} else {
result
}
}

private def addWayNodesToPolygonSequence(

Check failure on line 190 in src/main/scala/edu/ie3/osmogrid/lv/region_coordinator/BoundaryFactory.scala

View check run for this annotation

SonarQubeGithubPRChecks / OSMoGrid Sonarqube Results

src/main/scala/edu/ie3/osmogrid/lv/region_coordinator/BoundaryFactory.scala#L190

Refactor this method to reduce its Cognitive Complexity from 27 to the 15 allowed.
Expand Down

0 comments on commit 8319add

Please sign in to comment.