Skip to content

Commit

Permalink
Fix incorrect prediction of displaced bounding boxes (#110)
Browse files Browse the repository at this point in the history
Resolves #105
  • Loading branch information
Argmaster committed Jan 1, 2024
1 parent 7eff247 commit 3f6029f
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<p align="center">
<img width="400" src="https://github.com/Argmaster/pygerber/assets/56170852/b7aeb3e1-cd59-4f5b-b078-c01272461367">
<img width="400" src="https://github.com/UniversityOfGdanskTeamPython/epseon_backend/assets/56170852/094eb29d-ad4d-420c-bf20-60eae2cadb0b" alt="" />
</p>

<h1 align="center"> PyGerber </h1>
Expand Down
12 changes: 9 additions & 3 deletions src/pygerber/backend/abstract/aperture_handle.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,18 @@ def get_bounding_box(self) -> BoundingBox:

@cached_property
def _bounding_box(self) -> BoundingBox:
bbox = BoundingBox.NULL
bbox: Optional[BoundingBox] = None

for aperture_draw in self.aperture_draws:
bbox += aperture_draw.get_bounding_box()
if bbox is not None:
bbox += aperture_draw.get_bounding_box()
else:
bbox = aperture_draw.get_bounding_box()

return bbox
if bbox is not None:
return bbox

return BoundingBox.NULL

def _get_coordinate_origin(self) -> Vector2D:
return self.bounding_box.get_min_vector()
Expand Down
12 changes: 9 additions & 3 deletions src/pygerber/backend/abstract/backend_cls.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,18 @@ def finalize_aperture_creation(self) -> None:
handle.finalize_aperture_creation()

def _get_draws_bounding_box(self, draws: List[DrawCommand]) -> BoundingBox:
bbox = BoundingBox.NULL
bbox: Optional[BoundingBox] = None

for draw in draws:
bbox += draw.get_bounding_box()
if bbox is not None:
bbox += draw.get_bounding_box()
else:
bbox = draw.get_bounding_box()

return bbox
if bbox is not None:
return bbox

return BoundingBox.NULL

def _get_coordinate_origin(self) -> Vector2D:
return self.bounding_box.get_min_vector()
Expand Down
14 changes: 10 additions & 4 deletions src/pygerber/backend/abstract/draw_commands/draw_region.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
from __future__ import annotations

from functools import cached_property
from typing import Optional

from pygerber.backend.abstract.backend_cls import Backend
from pygerber.backend.abstract.draw_commands.draw_command import DrawCommand
from pygerber.gerberx3.math.bounding_box import BoundingBox
from pygerber.gerberx3.math.offset import Offset
from pygerber.gerberx3.math.vector_2d import Vector2D
from pygerber.gerberx3.state_enums import Polarity

Expand All @@ -32,8 +32,14 @@ def get_bounding_box(self) -> BoundingBox:

@cached_property
def _bounding_box(self) -> BoundingBox:
box = BoundingBox.from_diameter(Offset.new(0.0))
box: Optional[BoundingBox] = None
for point in self.region_boundary_points:
box = box.include_point(point)
if box is not None:
box = box.include_point(point)
else:
box = BoundingBox.NULL + point

return box
if box is not None:
return box

return BoundingBox.NULL

0 comments on commit 3f6029f

Please sign in to comment.