mirror of
https://github.com/enzet/map-machine.git
synced 2025-05-25 23:16:23 +02:00
Rename Röntgen to Map Machine.
This commit is contained in:
parent
38c4e00de3
commit
2bd89a6539
57 changed files with 252 additions and 236 deletions
38
map_machine/util.py
Normal file
38
map_machine/util.py
Normal file
|
@ -0,0 +1,38 @@
|
|||
"""
|
||||
Utility file.
|
||||
"""
|
||||
from dataclasses import dataclass
|
||||
from typing import Any
|
||||
|
||||
__author__ = "Sergey Vartanov"
|
||||
__email__ = "me@enzet.ru"
|
||||
|
||||
|
||||
@dataclass
|
||||
class MinMax:
|
||||
"""
|
||||
Minimum and maximum.
|
||||
"""
|
||||
|
||||
min_: Any = None
|
||||
max_: Any = None
|
||||
|
||||
def update(self, value: Any) -> None:
|
||||
"""Update minimum and maximum with new value."""
|
||||
self.min_ = value if not self.min_ or value < self.min_ else self.min_
|
||||
self.max_ = value if not self.max_ or value > self.max_ else self.max_
|
||||
|
||||
def delta(self) -> Any:
|
||||
"""Difference between maximum and minimum."""
|
||||
return self.max_ - self.min_
|
||||
|
||||
def center(self) -> Any:
|
||||
"""Get middle point between minimum and maximum."""
|
||||
return (self.min_ + self.max_) / 2
|
||||
|
||||
def is_empty(self) -> bool:
|
||||
"""Check if interval is empty."""
|
||||
return self.min_ == self.max_
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f"{self.min_}:{self.max_}"
|
Loading…
Add table
Add a link
Reference in a new issue