mirror of
https://github.com/enzet/map-machine.git
synced 2025-06-14 16:51:51 +02:00
Move Segment to vector.
This commit is contained in:
parent
67c2d98917
commit
0f9a4798f2
3 changed files with 21 additions and 21 deletions
|
@ -10,9 +10,9 @@ from svgwrite.container import Group
|
||||||
from svgwrite.path import Path
|
from svgwrite.path import Path
|
||||||
|
|
||||||
from map_machine.drawing import PathCommands
|
from map_machine.drawing import PathCommands
|
||||||
from map_machine.feature.direction import Segment
|
|
||||||
from map_machine.figure import Figure
|
from map_machine.figure import Figure
|
||||||
from map_machine.geometry.flinger import Flinger
|
from map_machine.geometry.flinger import Flinger
|
||||||
|
from map_machine.geometry.vector import Segment
|
||||||
from map_machine.osm.osm_reader import OSMNode
|
from map_machine.osm.osm_reader import OSMNode
|
||||||
from map_machine.scheme import Scheme, LineStyle
|
from map_machine.scheme import Scheme, LineStyle
|
||||||
|
|
||||||
|
|
|
@ -232,23 +232,3 @@ class DirectionSector(Tagged):
|
||||||
fill=gradient.get_funciri(),
|
fill=gradient.get_funciri(),
|
||||||
)
|
)
|
||||||
svg.add(path_element)
|
svg.add(path_element)
|
||||||
|
|
||||||
|
|
||||||
class Segment:
|
|
||||||
"""Closed line segment."""
|
|
||||||
|
|
||||||
def __init__(self, point_1: np.ndarray, point_2: np.ndarray) -> None:
|
|
||||||
self.point_1: np.ndarray = point_1
|
|
||||||
self.point_2: np.ndarray = point_2
|
|
||||||
|
|
||||||
difference: np.ndarray = point_2 - point_1
|
|
||||||
vector: np.ndarray = difference / np.linalg.norm(difference)
|
|
||||||
self.angle: float = (
|
|
||||||
np.arccos(np.dot(vector, np.array((0.0, 1.0)))) / np.pi
|
|
||||||
)
|
|
||||||
|
|
||||||
def __lt__(self, other: "Segment") -> bool:
|
|
||||||
return (
|
|
||||||
((self.point_1 + self.point_2) / 2.0)[1]
|
|
||||||
< ((other.point_1 + other.point_2) / 2.0)[1]
|
|
||||||
) # fmt: skip
|
|
||||||
|
|
|
@ -115,3 +115,23 @@ class Line:
|
||||||
|
|
||||||
def __repr__(self) -> str:
|
def __repr__(self) -> str:
|
||||||
return f"{self.a} * x + {self.b} * y + {self.c} == 0"
|
return f"{self.a} * x + {self.b} * y + {self.c} == 0"
|
||||||
|
|
||||||
|
|
||||||
|
class Segment:
|
||||||
|
"""Closed line segment."""
|
||||||
|
|
||||||
|
def __init__(self, point_1: np.ndarray, point_2: np.ndarray) -> None:
|
||||||
|
self.point_1: np.ndarray = point_1
|
||||||
|
self.point_2: np.ndarray = point_2
|
||||||
|
|
||||||
|
difference: np.ndarray = point_2 - point_1
|
||||||
|
vector: np.ndarray = difference / np.linalg.norm(difference)
|
||||||
|
self.angle: float = (
|
||||||
|
np.arccos(np.dot(vector, np.array((0.0, 1.0)))) / np.pi
|
||||||
|
)
|
||||||
|
|
||||||
|
def __lt__(self, other: "Segment") -> bool:
|
||||||
|
return (
|
||||||
|
((self.point_1 + self.point_2) / 2.0)[1]
|
||||||
|
< ((other.point_1 + other.point_2) / 2.0)[1]
|
||||||
|
) # fmt: skip
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue