Skip to content

Instantly share code, notes, and snippets.

@KaiserKatze
Created February 17, 2019 01:54
Show Gist options
  • Save KaiserKatze/bc292b616152e8fcb7b009dbeff93106 to your computer and use it in GitHub Desktop.
Save KaiserKatze/bc292b616152e8fcb7b009dbeff93106 to your computer and use it in GitHub Desktop.
Angle calculation
#!/usr/bin/env python
# -*- coding: utf-8 -*-
class Angle:
val = 0
def __init__(self, x, y, z):
self.val = ((x * 60) + y) * 60 + z
self.x = x
self.y = y
self.z = z
def __lt__(self, other):
return self.val < otehr.val
def __le__(self, other):
return self.val <= other.val
def __eq__(self, other):
return self.val == other.val
def __ne__(self, other):
return self.val != other.val
def __gt__(self, other):
return self.val > other.val
def __ge__(self, other):
return self.val >= other.val
def __bool__(self):
return self.val
def __str__(self):
return '{}°{}′{}″'.format(self.x, self.y, self.z)
def __neg__(self):
self.val = -self.val
self.x = -self.x
return self
def __pos__(self):
return self
def __abs__(self):
if self.val < 0:
self.val = -self.val
self.x = -self.x
return self
def __add__(self, other):
val = self.val + other.val
return Angle(0, 0, val).__onchange__()
def __sub__(self, other):
val = self.val - other.val
return Angle(0, 0, val).__onchange__()
def __iadd__(self, other):
self.val += other.val
return __onchange__(self)
def __isub__(self, other):
self.val -= other.val
return __onchange__(self)
def __onchange__(self):
self.x, self.y = divmod(self.val // 60, 60)
self.z = self.val % 60
return self
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment