mirror of
https://github.com/enzet/map-machine.git
synced 2025-05-19 12:06:24 +02:00
Issue #84: make connections scale insensitive.
This commit is contained in:
parent
46d0f96303
commit
103fe5377d
3 changed files with 8 additions and 7 deletions
BIN
doc/lanes.png
BIN
doc/lanes.png
Binary file not shown.
Before Width: | Height: | Size: 195 KiB After Width: | Height: | Size: 196 KiB |
|
@ -496,6 +496,10 @@ class Connector:
|
|||
self.index_1: int = index_1
|
||||
self.index_2: int = index_2
|
||||
|
||||
length: float = abs(road_2.width - road_1.width) * scale
|
||||
road_1.line.shorten(index_1, length)
|
||||
road_2.line.shorten(index_2, length)
|
||||
|
||||
node: OSMNode = road_1.nodes[index_1]
|
||||
point: np.ndarray = flinger.fling(node.coordinates)
|
||||
|
||||
|
@ -560,11 +564,6 @@ class Roads:
|
|||
if road.layer not in layered_roads:
|
||||
layered_roads[road.layer] = []
|
||||
layered_roads[road.layer].append(road)
|
||||
for index in 0, -1:
|
||||
id_: int = road.nodes[index].id_
|
||||
if len(self.connections[id_]) != 2:
|
||||
continue
|
||||
road.line.shorten(index)
|
||||
|
||||
for id_ in self.connections:
|
||||
if len(self.connections[id_]) != 2:
|
||||
|
@ -572,6 +571,8 @@ class Roads:
|
|||
connected: list[tuple[Road, int]] = self.connections[id_]
|
||||
road_1, index_1 = connected[0]
|
||||
road_2, index_2 = connected[1]
|
||||
if road_1.width == road_2.width:
|
||||
continue
|
||||
connector: Connector = Connector(
|
||||
road_1, index_1, road_2, index_2, flinger, scale
|
||||
)
|
||||
|
|
|
@ -62,12 +62,12 @@ class Polyline:
|
|||
path: str = "M " + " L ".join(f"{x[0]},{x[1]}" for x in points)
|
||||
return path + (" Z" if np.allclose(points[0], points[-1]) else "")
|
||||
|
||||
def shorten(self, index: int) -> None:
|
||||
def shorten(self, index: int, length: float) -> None:
|
||||
"""Make shorten part specified with index."""
|
||||
index_2: int = 1 if index == 0 else -2
|
||||
diff: np.ndarray = self.points[index_2] - self.points[index]
|
||||
self.points[index] = (
|
||||
self.points[index] + diff / np.linalg.norm(diff) * 5
|
||||
self.points[index] + diff / np.linalg.norm(diff) * length
|
||||
)
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue