Fix code style and documentation.

This commit is contained in:
Sergey Vartanov 2022-07-03 21:45:30 +03:00
parent 93710220c2
commit 1a719fca2a
3 changed files with 25 additions and 12 deletions

View file

@ -28,22 +28,22 @@ EXTRACTOR: ShapeExtractor = ShapeExtractor(
class Collection: class Collection:
"""Icon collection.""" """Icon collection."""
# Core tags # Core tags.
tags: Tags tags: Tags
# Tag key to be used in rows # Tag key to be used in rows.
row_key: Optional[str] = None row_key: Optional[str] = None
# List of tag values to be used in rows # List of tag values to be used in rows.
row_values: list[str] = field(default_factory=list) row_values: list[str] = field(default_factory=list)
# Tag key to be used in columns # Tag key to be used in columns.
column_key: Optional[str] = None column_key: Optional[str] = None
# List of tag values to be used in columns # List of tag values to be used in columns.
column_values: list[str] = field(default_factory=list) column_values: list[str] = field(default_factory=list)
# List of tags to be used in rows # List of tags to be used in rows.
row_tags: list[Tags] = field(default_factory=list) row_tags: list[Tags] = field(default_factory=list)
@classmethod @classmethod

View file

@ -49,6 +49,8 @@ class Flinger:
equator_length: float, equator_length: float,
) -> None: ) -> None:
""" """
Initialize flinger with geo boundary box and zoom level.
:param geo_boundaries: minimum and maximum latitude and longitude :param geo_boundaries: minimum and maximum latitude and longitude
:param zoom_level: zoom level in OpenStreetMap terminology :param zoom_level: zoom level in OpenStreetMap terminology
:param equator_length: celestial body equator length in meters :param equator_length: celestial body equator length in meters

View file

@ -1,4 +1,6 @@
"""Vector utility.""" """Vector utility."""
from typing import Optional
import numpy as np import numpy as np
__author__ = "Sergey Vartanov" __author__ = "Sergey Vartanov"
@ -9,8 +11,9 @@ from shapely.geometry import LineString
def compute_angle(vector: np.ndarray) -> float: def compute_angle(vector: np.ndarray) -> float:
""" """
For the given vector compute an angle between it and (1, 0) vector. The For the given vector compute an angle between it and (1, 0) vector.
result is in [0, 2π].
The result is in [0, 2π].
""" """
if vector[0] == 0.0: if vector[0] == 0.0:
if vector[1] > 0.0: if vector[1] > 0.0:
@ -47,6 +50,7 @@ class Polyline:
def get_path(self, parallel_offset: float = 0.0) -> str: def get_path(self, parallel_offset: float = 0.0) -> str:
"""Construct SVG path commands.""" """Construct SVG path commands."""
points: list[np.ndarray] points: list[np.ndarray]
if np.allclose(parallel_offset, 0.0): if np.allclose(parallel_offset, 0.0):
points = self.points points = self.points
else: else:
@ -132,14 +136,22 @@ class Segment:
np.arccos(np.dot(vector, np.array((0.0, 1.0)))) / np.pi np.arccos(np.dot(vector, np.array((0.0, 1.0)))) / np.pi
) )
def __repr__(self): def __repr__(self) -> str:
"""Get simple string representation."""
return f"{self.point_1} -- {self.point_2}" return f"{self.point_1} -- {self.point_2}"
def __lt__(self, other: "Segment") -> bool: def __lt__(self, other: "Segment") -> bool:
"""Compare central y coordinates of segments."""
return self.y < other.y return self.y < other.y
def intersection(self, other: "Segment"): def intersection(self, other: "Segment") -> Optional[list[float]]:
divisor = (self.point_1[0] - self.point_2[0]) * ( """
Find and intersection point between two segments.
:return: `None` if segments don't intersect, [x, y] coordinates of
the resulting point otherwise.
"""
divisor: float = (self.point_1[0] - self.point_2[0]) * (
other.point_1[1] - other.point_2[1] other.point_1[1] - other.point_2[1]
) - (self.point_1[1] - self.point_2[1]) * ( ) - (self.point_1[1] - self.point_2[1]) * (
other.point_1[0] - other.point_2[0] other.point_1[0] - other.point_2[0]
@ -162,7 +174,6 @@ class Segment:
) / divisor ) / divisor
if 0 <= t <= 1 and 0 <= u <= 1: if 0 <= t <= 1 and 0 <= u <= 1:
print(t)
return [ return [
self.point_1[0] + t * (self.point_2[0] - self.point_1[0]), self.point_1[0] + t * (self.point_2[0] - self.point_1[0]),
self.point_1[1] + t * (self.point_2[1] - self.point_1[1]), self.point_1[1] + t * (self.point_2[1] - self.point_1[1]),