mirror of
https://github.com/enzet/map-machine.git
synced 2025-05-31 09:56:24 +02:00
Issue #45: add intersection class.
This commit is contained in:
parent
d254651292
commit
51fe4d0b34
1 changed files with 33 additions and 0 deletions
33
roentgen/road.py
Normal file
33
roentgen/road.py
Normal file
|
@ -0,0 +1,33 @@
|
|||
"""
|
||||
Road shape drawing.
|
||||
"""
|
||||
from typing import List
|
||||
|
||||
import numpy as np
|
||||
|
||||
from flinger import Flinger, angle
|
||||
from osm_reader import OSMNode
|
||||
|
||||
|
||||
class RoadPart:
|
||||
"""
|
||||
Line part of the road.
|
||||
"""
|
||||
def __init__(self, node_1: OSMNode, node_2: OSMNode, flinger: Flinger):
|
||||
self.point_1: np.array = flinger.fling(node_1.coordinates)
|
||||
self.point_2: np.array = flinger.fling(node_2.coordinates)
|
||||
|
||||
def get_angle(self) -> float:
|
||||
"""
|
||||
Get an angle between line and x axis.
|
||||
"""
|
||||
return angle(self.point_1, self.point_2)
|
||||
|
||||
|
||||
class Intersection:
|
||||
"""
|
||||
An intersection of the roads, that is described by its parts. All first
|
||||
points of the road parts should be the same.
|
||||
"""
|
||||
def __init__(self, parts: List[RoadPart]):
|
||||
self.parts: List[RoadPart] = sorted(parts, key=lambda x: x.get_angle())
|
Loading…
Add table
Add a link
Reference in a new issue