Move Segment to vector.

This commit is contained in:
Sergey Vartanov 2021-12-14 08:25:50 +03:00
parent 67c2d98917
commit 0f9a4798f2
3 changed files with 21 additions and 21 deletions

View file

@ -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

View file

@ -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

View file

@ -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