Skip to content

Commit

Permalink
fix: make typesignature on to_align_offset more precise
Browse files Browse the repository at this point in the history
  • Loading branch information
erooke committed Nov 14, 2024
1 parent 0841d28 commit a87c279
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
28 changes: 17 additions & 11 deletions src/build123d/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
from OCP.TopLoc import TopLoc_Location
from OCP.TopoDS import TopoDS_Face, TopoDS_Shape, TopoDS_Vertex

from build123d.build_enums import Align, Intrinsic, Extrinsic
from build123d.build_enums import Align, Align2DType, Align3DType, Intrinsic, Extrinsic

# Create a build123d logger to distinguish these logs from application logs.
# If the user doesn't configure logging, all build123d logs will be discarded.
Expand Down Expand Up @@ -1021,7 +1021,7 @@ def is_inside(self, second_box: BoundBox) -> bool:
and second_box.max.Z < self.max.Z
)

def to_align_offset(self, align: Sequence[Align]) -> Vector:
def to_align_offset(self, align: Union[Align2DType, Align3DType]) -> Vector:
"""Amount to move object to achieve the desired alignment"""
return to_align_offset(self.min.to_tuple(), self.max.to_tuple(), align)

Expand Down Expand Up @@ -2529,22 +2529,28 @@ def intersect(self, *args, **kwargs):


def to_align_offset(
min_point: Sequence[float],
max_point: Sequence[float],
align: Sequence[Align],
center: Optional[Sequence[float]] = None,
min_point: VectorLike,
max_point: VectorLike,
align: Union[Align2DType, Align3DType],
center: Optional[VectorLike] = None,
) -> Vector:
"""Amount to move object to achieve the desired alignment"""
align_offset = []

if center is None:
center = [
(min_coord + max_coord) / 2
for min_coord, max_coord in zip(min_point, max_point)
]
center = (Vector(min_point) + Vector(max_point)) / 2

if align is None or align is Align.NONE:
return Vector(0, 0, 0)
if align is Align.MIN:
return Vector(min_point)

Check warning on line 2546 in src/build123d/geometry.py

View check run for this annotation

Codecov / codecov/patch

src/build123d/geometry.py#L2546

Added line #L2546 was not covered by tests
if align is Align.MAX:
return Vector(max_point)

Check warning on line 2548 in src/build123d/geometry.py

View check run for this annotation

Codecov / codecov/patch

src/build123d/geometry.py#L2548

Added line #L2548 was not covered by tests
if align is Align.CENTER:
return Vector(center)

Check warning on line 2550 in src/build123d/geometry.py

View check run for this annotation

Codecov / codecov/patch

src/build123d/geometry.py#L2550

Added line #L2550 was not covered by tests

for alignment, min_coord, max_coord, center_coord in zip(
align,
map(Align, align),
min_point,
max_point,
center,
Expand Down
6 changes: 1 addition & 5 deletions src/build123d/objects_sketch.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,11 +351,7 @@ def __init__(
mins = [pts_sorted[0][0].X, pts_sorted[1][0].Y]
maxs = [pts_sorted[0][-1].X, pts_sorted[1][-1].Y]

if align is not None:
align = tuplify(align, 2)
align_offset = to_align_offset(mins, maxs, align, center=(0, 0))
else:
align_offset = Vector(0, 0)
align_offset = to_align_offset(mins, maxs, align, center=(0, 0))
pts = [point + align_offset for point in pts]

face = Face(Wire.make_polygon(pts))
Expand Down

0 comments on commit a87c279

Please sign in to comment.