Skip to content

Commit

Permalink
#278 monitor route analysis - wip
Browse files Browse the repository at this point in the history
  • Loading branch information
vmarc committed Feb 7, 2024
1 parent 182904e commit 94a5ec2
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ class StructureElementAnalyzer(wayMembers: Seq[WayMember], traceEnabled: Boolean

private def lookRoundaboutAhead(currentWayMember: WayMember, endNodeId: Long, aheadLink: WayMemberLink): Unit = {
val connectingNodeIds1 = currentWayMember.way.nodes.map(_.id).dropRight(1)
val connectingNodeIds2 = connectableNodeIds(aheadLink.wayMember)
val connectingNodeIds2 = connectableNodeIdsUp(aheadLink.wayMember)
connection(connectingNodeIds1, connectingNodeIds2) match {
case None =>
aheadLink.next match {
Expand Down Expand Up @@ -579,6 +579,27 @@ class StructureElementAnalyzer(wayMembers: Seq[WayMember], traceEnabled: Boolean
}
}

private def connectableNodeIdsUp(wayMember: WayMember): Seq[Long] = {
if (isClosedLoop(wayMember)) {
wayMember.way.nodes.map(_.id).dropRight(1)
}
else {
if (wayMember.hasRoleForward) {
Seq(wayMember.way.nodes.last.id)
}
else if (wayMember.hasRoleBackward) {
Seq(wayMember.way.nodes.head.id)
}
else {
// bidirectional fragment
Seq(
wayMember.way.nodes.head.id,
wayMember.way.nodes.last.id
)
}
}
}

private def connection(nodeIds1: Seq[Long], nodeIds2: Seq[Long]): Option[Long] = {
nodeIds1.flatMap { nodeId1 =>
nodeIds2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ class StructureAnalyzerTest extends UnitTest {

test("case study 2") {
val relation = CaseStudy.load("/case-studies/monitor/5444896.xml")
val wayInfos = new ReferenceStructureAnalyzer().analyze(relation)
wayInfos.foreach(println)
// val wayInfos = new ReferenceStructureAnalyzer().analyze(relation)
// wayInfos.foreach(println)
// new StructureAnalyzer().analyze(relation)
val elementGroups = StructureElementAnalyzer.analyze(relation.members, traceEnabled = true)
val elementGroups = StructureElementAnalyzer.analyze(relation.members)
elementGroups.size should equal(1)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ class Structure_72_RoundaboutParts_Test extends UnitTest {
memberWay(18, "forward", 11, 7)
memberWay(19, "forward", 10, 11)
// continue:
memberWay(19, "", 10, 12)
memberWay(20, "", 10, 12)
}.build

test("reference") {
setup.reference(traceEnabled = true).shouldMatchTo(
setup.reference().shouldMatchTo(
Seq(
"1 p n ■ loop fp bp head tail d forward",
"2 p ■ n ■ loop fp ■ bp head ■ tail d forward",
Expand All @@ -37,14 +37,14 @@ class Structure_72_RoundaboutParts_Test extends UnitTest {
"6 p ■ n ■ loop fp ■ bp head ■ tail d forward",
"7 p ■ n ■ loop fp ■ bp head tail d forward",
"8 p ■ n ■ loop fp bp ■ head tail d backward",
"9 p ■ n ■ loop fp bp head tail d forward",
"10 p ■ n loop fp bp head tail d backward"
"9 p ■ n ■ loop fp bp head tail d backward",
"10 p ■ n loop fp bp head tail d forward"
)
)
}

test("elements") {
setup.elementGroups(traceEnabled = true).shouldMatchTo(
setup.elementGroups().shouldMatchTo(
Seq(
Seq(
"1>2",
Expand Down

0 comments on commit 94a5ec2

Please sign in to comment.