aboutsummaryrefslogtreecommitdiff
path: root/thcolor/angles.py
diff options
context:
space:
mode:
Diffstat (limited to 'thcolor/angles.py')
-rw-r--r--thcolor/angles.py16
1 files changed, 7 insertions, 9 deletions
diff --git a/thcolor/angles.py b/thcolor/angles.py
index 02e9711..3f0ca06 100644
--- a/thcolor/angles.py
+++ b/thcolor/angles.py
@@ -8,6 +8,8 @@
from math import pi as _pi
from typing import Any as _Any, Optional as _Optional
+from .utils import round_half_up as _round_half_up
+
__all__ = [
'Angle', 'DegreesAngle', 'GradiansAngle', 'RadiansAngle', 'TurnsAngle',
]
@@ -166,7 +168,7 @@ class DegreesAngle(Angle):
def __str__(self):
x = self._value
- return f'{int(x) if x == int(x) else x}deg'
+ return f'{_round_half_up(x, 4)}deg'
@property
def degrees(self) -> float:
@@ -198,7 +200,7 @@ class GradiansAngle(Angle):
def __str__(self):
x = self._value
- return f'{int(x) if x == int(x) else x}grad'
+ return f'{_round_half_up(x, 4)}grad'
@property
def gradians(self) -> float:
@@ -234,12 +236,8 @@ class RadiansAngle(Angle):
return f'{int(x) if x == int(x) else x}rad'
def __repr__(self):
- r = self.radians / _pi
- ir = int(r)
- if r == ir:
- r = ir
-
- return f"{self.__class__.__name__}(radians = {f'{r}π' if r else '0'})"
+ r = _round_half_up(self.radians / _pi, 4)
+ return f"{self.__class__.__name__}(radians={f'{r}π' if r else '0'})"
@property
def radians(self) -> float:
@@ -271,7 +269,7 @@ class TurnsAngle(Angle):
def __str__(self):
x = self._value
- return f'{int(x) if x == int(x) else x}turn'
+ return f'{_round_half_up(x, 4)}turn'
@property
def turns(self) -> float: