From 15a2b89ee524dcae068685c502254283e451d62a Mon Sep 17 00:00:00 2001 From: gumyr Date: Mon, 29 Jan 2024 14:38:52 -0500 Subject: [PATCH] Improving performance and removing random failures Issue #508 #509 --- src/build123d/build_common.py | 12 ++---------- src/build123d/build_sketch.py | 3 +-- src/build123d/topology.py | 13 ++++++++----- 3 files changed, 11 insertions(+), 17 deletions(-) diff --git a/src/build123d/build_common.py b/src/build123d/build_common.py index 54d8a8d9..2177f7c2 100644 --- a/src/build123d/build_common.py +++ b/src/build123d/build_common.py @@ -1030,17 +1030,9 @@ def _move_to_existing(local_locations: list[Location]) -> list[Location]: list[Location]: group of locations moved to existing locations as a group """ location_group = [] - if LocationList._get_context(): - local_vertex_compound = Compound.make_compound( - [Face.make_rect(1, 1).locate(l) for l in local_locations] - ) + if LocationList._get_context() is not None: for group_center in LocationList._get_context().local_locations: - location_group.extend( - [ - v.location - for v in local_vertex_compound.moved(group_center).faces() - ] - ) + location_group.extend([group_center * l for l in local_locations]) else: location_group = local_locations return location_group diff --git a/src/build123d/build_sketch.py b/src/build123d/build_sketch.py index 742b79c6..aa017bde 100644 --- a/src/build123d/build_sketch.py +++ b/src/build123d/build_sketch.py @@ -81,8 +81,7 @@ def sketch(self): ) global_objs = [] for plane in workplanes: - for face in self._obj.faces(): - global_objs.append(plane.from_local_coords(face)) + global_objs.append(plane.from_local_coords(self._obj)) return Sketch(Compound.make_compound(global_objs).wrapped) def __init__( diff --git a/src/build123d/topology.py b/src/build123d/topology.py index 0e6c0110..628c70a3 100644 --- a/src/build123d/topology.py +++ b/src/build123d/topology.py @@ -5644,11 +5644,14 @@ def chamfer_2d( def is_coplanar(self, plane: Plane) -> bool: """Is this planar face coplanar with the provided plane""" - return all( - [ - plane.contains(pnt) - for pnt in self.outer_wire().positions([i / 7 for i in range(8)]) - ] + u_val0, _u_val1, v_val0, _v_val1 = self._uv_bounds() + gp_pnt = gp_Pnt() + normal = gp_Vec() + BRepGProp_Face(self.wrapped).Normal(u_val0, v_val0, gp_pnt, normal) + + return ( + plane.contains(Vector(gp_pnt)) + and (plane.z_dir - Vector(normal)).length < TOLERANCE ) def thicken(self, depth: float, normal_override: VectorLike = None) -> Solid: