construct BlockPos from tuple

This commit is contained in:
əlemi 2021-12-10 23:11:19 +01:00
parent d21a37c28b
commit fea68999dd

View file

@ -1,6 +1,7 @@
from math import sqrt from math import sqrt
from enum import Enum from enum import Enum
from dataclasses import dataclass from dataclasses import dataclass
from typing import Tuple
@dataclass # TODO use the one from types @dataclass # TODO use the one from types
class BlockPos: class BlockPos:
@ -8,6 +9,10 @@ class BlockPos:
y : float y : float
z : float z : float
@classmethod
def from_tuple(cls, t:Tuple[int, int, int]):
return cls(x=t[0], y=t[1], z=t[2])
def distance(self, p:'BlockPos'): def distance(self, p:'BlockPos'):
return sqrt( return sqrt(
( self.x - p.x ) ** 2 + ( self.x - p.x ) ** 2 +