Compare commits
5 commits
7799ec70ac
...
1392b07894
Author | SHA1 | Date | |
---|---|---|---|
Bruno BELANYI | 1392b07894 | ||
Bruno BELANYI | 4796157b65 | ||
Bruno BELANYI | 8ae274d5b2 | ||
Bruno BELANYI | 95658484f3 | ||
Bruno BELANYI | b821a20ba1 |
|
@ -72,6 +72,13 @@ class KdLeafNode[T]:
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.points = {}
|
self.points = {}
|
||||||
|
|
||||||
|
# Convenience constructor used when splitting a node
|
||||||
|
@classmethod
|
||||||
|
def from_items(cls, items: Iterable[tuple[Point, T]]) -> KdLeafNode[T]:
|
||||||
|
res = cls()
|
||||||
|
res.points.update(items)
|
||||||
|
return res
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Split node
|
#### Split node
|
||||||
|
@ -110,13 +117,6 @@ class KdNode[T]:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.inner = KdLeafNode()
|
self.inner = KdLeafNode()
|
||||||
|
|
||||||
# Convenience constructor used when splitting a node
|
|
||||||
@classmethod
|
|
||||||
def from_items(cls, items: Iterable[tuple[Point, T]]) -> KdNode[T]:
|
|
||||||
res = cls()
|
|
||||||
res.inner.points.update(items)
|
|
||||||
return res
|
|
||||||
|
|
||||||
class KdTree[T]:
|
class KdTree[T]:
|
||||||
_root: KdNode[T]
|
_root: KdNode[T]
|
||||||
|
|
||||||
|
@ -165,7 +165,7 @@ def split_leaf[T](node: KdLeafNode[T], axis: Axis) -> KdSplitNode[T]:
|
||||||
return KdSplitNode(
|
return KdSplitNode(
|
||||||
split_axis,
|
split_axis,
|
||||||
mid,
|
mid,
|
||||||
(KdNode.from_items(left), KdNode.from_items(right)),
|
(KdLeafNode.from_items(left), KdLeafNode.from_items(right)),
|
||||||
)
|
)
|
||||||
|
|
||||||
class KdTree[T]:
|
class KdTree[T]:
|
||||||
|
|
Loading…
Reference in a new issue