Coordinate order - not sure which comparison is the "correct" one
This commit is contained in:
parent
1e33dd6210
commit
7656e90984
@ -144,6 +144,35 @@ class Coordinate:
|
|||||||
else:
|
else:
|
||||||
return Coordinate(self.x - other.x, self.y - other.y, self.z - other.z)
|
return Coordinate(self.x - other.x, self.y - other.y, self.z - other.z)
|
||||||
|
|
||||||
|
"""
|
||||||
|
def __eq__(self, other):
|
||||||
|
return self.x == other.x and self.y == other.y and self.z == other.z
|
||||||
|
|
||||||
|
def __gt__(self, other):
|
||||||
|
if self.z is None:
|
||||||
|
return self.x > other.x and self.y > other.y
|
||||||
|
else:
|
||||||
|
return self.x > other.x and self.y > other.y and self.z > other.z
|
||||||
|
|
||||||
|
def __ge__(self, other):
|
||||||
|
if self.z is None:
|
||||||
|
return self.x >= other.x and self.y >= other.y
|
||||||
|
else:
|
||||||
|
return self.x >= other.x and self.y >= other.y and self.z >= other.z
|
||||||
|
|
||||||
|
def __lt__(self, other):
|
||||||
|
if self.z is None:
|
||||||
|
return self.x < other.x and self.y < other.y
|
||||||
|
else:
|
||||||
|
return self.x < other.x and self.y < other.y and self.z < other.z
|
||||||
|
|
||||||
|
def __le__(self, other):
|
||||||
|
if self.z is None:
|
||||||
|
return self.x <= other.x and self.y <= other.y
|
||||||
|
else:
|
||||||
|
return self.x <= other.x and self.y <= other.y and self.z <= other.z
|
||||||
|
"""
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def generate(from_x: int, to_x: int, from_y: int, to_y: int,
|
def generate(from_x: int, to_x: int, from_y: int, to_y: int,
|
||||||
from_z: int = None, to_z: int = None) -> List[Coordinate]:
|
from_z: int = None, to_z: int = None) -> List[Coordinate]:
|
||||||
|
|||||||
39
tools/trees.py
Normal file
39
tools/trees.py
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
from typing import Any, Union
|
||||||
|
|
||||||
|
|
||||||
|
class BinaryTreeNode:
|
||||||
|
data: Any
|
||||||
|
left: Union['BinaryTreeNode', None]
|
||||||
|
right: Union['BinaryTreeNode', None]
|
||||||
|
|
||||||
|
def __init__(self, data: Any):
|
||||||
|
self.data = data
|
||||||
|
self.left = None
|
||||||
|
self.right = None
|
||||||
|
|
||||||
|
def traverse_inorder(self):
|
||||||
|
if self.left:
|
||||||
|
self.left.traverse_inorder()
|
||||||
|
|
||||||
|
yield self.data
|
||||||
|
|
||||||
|
if self.right:
|
||||||
|
self.right.traverse_inorder()
|
||||||
|
|
||||||
|
def traverse_preorder(self):
|
||||||
|
yield self.data
|
||||||
|
|
||||||
|
if self.left:
|
||||||
|
self.left.traverse_preorder()
|
||||||
|
|
||||||
|
if self.right:
|
||||||
|
self.right.traverse_preorder()
|
||||||
|
|
||||||
|
def traverse_postorder(self):
|
||||||
|
if self.left:
|
||||||
|
self.left.traverse_preorder()
|
||||||
|
|
||||||
|
if self.right:
|
||||||
|
self.right.traverse_postorder()
|
||||||
|
|
||||||
|
yield self.data
|
||||||
Loading…
Reference in New Issue
Block a user