Revert "attempt fix anytree O(n^2) scaling without side effects"

This reverts commit ce1f509340.
This commit is contained in:
jdegenstein 2025-11-22 11:30:06 -06:00
parent c4b23baeb8
commit 6773a8dea1
2 changed files with 0 additions and 93 deletions

View file

@ -189,31 +189,6 @@ class Compound(Mixin3D[TopoDS_Compound]):
"""The dimension of the shapes within the Compound - None if inconsistent"""
return topods_dim(self.wrapped)
def _update_geometry(self):
"""
Rebuild the internal TopoDS_Compound from the children.
This runs once per batch assignment.
"""
# Safety check: if no children, maybe handle as empty compound or return
if not self.children:
# Optional: Decide if an empty compound should be null or an empty TopoDS
return
# 1. OPTIMIZED LOGGING
if logger.isEnabledFor(logging.DEBUG):
count = len(self.children)
if count > 10:
logger.debug("Rebuilding Compound with %d children", count)
else:
kids = ",".join([child.label for child in self.children])
logger.debug("Rebuilding Compound with children: %s", kids)
# 2. GEOMETRY RECONSTRUCTION
# Note: Ensure _make_topods_compound_from_shapes is imported
self.wrapped = _make_topods_compound_from_shapes(
[c.wrapped for c in self.children]
)
@property
def volume(self) -> float:
"""volume - the volume of this Compound"""

View file

@ -294,9 +294,6 @@ class Shape(NodeMixin, Generic[TOPODS]):
self.label = label
self.color = color
# Flag to suppress expensive geometry rebuilds during batch operations
self._suppress_update = False
# parent must be set following children as post install accesses children
self.parent = parent
@ -324,71 +321,6 @@ class Shape(NodeMixin, Generic[TOPODS]):
def _dim(self) -> int | None:
"""Dimension of the object"""
@property
def children(self):
"""Override anytree children getter."""
return super().children
@children.setter
def children(self, values: Iterable[Shape]):
"""
Optimized children setter.
Bypasses anytree's O(n^2) validation (duplicate/loop checks) for massive speedups.
"""
self._suppress_update = True
try:
# 1. Standardize input to a LIST (Critical: AnyTree requires a mutable list internally)
new_children = list(values)
# 2. Access internal AnyTree storage (Name mangling required)
children_storage = "_NodeMixin__children"
parent_storage = "_NodeMixin__parent"
# 3. Detach existing children (Manual NodeMixin logic)
if hasattr(self, children_storage):
old_children = getattr(self, children_storage)
for child in old_children:
setattr(child, parent_storage, None)
# 4. Set new children LIST (Skipping set() validation)
setattr(self, children_storage, new_children)
# 5. Attach new children (Manual NodeMixin logic)
for child in new_children:
# Fast link to self
setattr(child, parent_storage, self)
finally:
self._suppress_update = False
# Trigger the geometry rebuild exactly once
self._update_geometry()
@children.deleter
def children(self):
"""
Delegate deletion to NodeMixin (equivalent to setting children = ()).
"""
self._suppress_update = True
try:
NodeMixin.children.__delete__(self)
finally:
self._suppress_update = False
self._update_geometry()
def _post_attach_children(self, children: Iterable[Shape]):
"""Called by anytree after a child is attached via `child.parent = self`."""
if self._suppress_update:
return
self._update_geometry()
def _update_geometry(self):
"""
Virtual method.
By default, Shapes (Solids, Faces, etc.) do NOT change their
geometry when children are added.
"""
pass
@property
def area(self) -> float:
"""area -the surface area of all faces in this Shape"""