Skip to content

Commit

Permalink
Replace infinite coordinates for shapely operation
Browse files Browse the repository at this point in the history
Signed-off-by: Lucas Heitzmann Gabrielli <lucas@flexcompute.com>
  • Loading branch information
lucas-flexcompute authored and momchil-flex committed Oct 13, 2024
1 parent d427511 commit 3e38fb5
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 14 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]


## [2.7.5] - 2024-10-10

### Added
Expand All @@ -23,6 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Correct sign in objective function history depending on `Optimizer.maximize`.
- Fix to batch mode solver run that could create multiple copies of the same folder.
- Fixed ``ModeSolver.plot`` method when the simulation is not at the origin.
- Bug with infinite coordinates in `ClipOperation` not working with shapely.

## [2.7.4] - 2024-09-25

Expand Down
9 changes: 9 additions & 0 deletions tests/test_components/test_geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,15 @@ def test_intersections_plane(component):
assert len(component.intersections_plane(x=0.2)) > 0
assert len(component.intersections_plane(x=10000)) == 0

def test_intersections_plane_inf():
a = (
td.Cylinder(radius=3.2, center=(0.45, 9, 0), length=td.inf)
+ td.Box(center=(0, 0, 0), size=(0.9, 24, td.inf))
+ td.Box(center=(0, 0, 0), size=(7.3, 18, td.inf))
)
b = td.Cylinder(radius=2.9, center=(-0.45, 9, 0), length=td.inf)
c = a - b
assert len(c.intersections_plane(y=0)) == 1

def test_bounds_base():
assert all(a == b for a, b in zip(Planar.bounds.fget(POLYSLAB), POLYSLAB.bounds))
Expand Down
20 changes: 8 additions & 12 deletions tidy3d/components/geometry/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2857,12 +2857,10 @@ def intersections_tilted_plane(
For more details refer to
`Shapely's Documentation <https://shapely.readthedocs.io/en/stable/project.html>`_.
"""
geom_a = Geometry.evaluate_inf_shape(
shapely.unary_union(self.geometry_a.intersections_tilted_plane(normal, origin, to_2D))
)
geom_b = Geometry.evaluate_inf_shape(
shapely.unary_union(self.geometry_b.intersections_tilted_plane(normal, origin, to_2D))
)
a = self.geometry_a.intersections_tilted_plane(normal, origin, to_2D)
b = self.geometry_b.intersections_tilted_plane(normal, origin, to_2D)
geom_a = shapely.unary_union([Geometry.evaluate_inf_shape(g) for g in a])
geom_b = shapely.unary_union([Geometry.evaluate_inf_shape(g) for g in b])
return ClipOperation.to_polygon_list(self._shapely_operation(geom_a, geom_b))

def intersections_plane(
Expand All @@ -2886,12 +2884,10 @@ def intersections_plane(
For more details refer to
`Shapely's Documentaton <https://shapely.readthedocs.io/en/stable/project.html>`_.
"""
geom_a = Geometry.evaluate_inf_shape(
shapely.unary_union(self.geometry_a.intersections_plane(x, y, z))
)
geom_b = Geometry.evaluate_inf_shape(
shapely.unary_union(self.geometry_b.intersections_plane(x, y, z))
)
a = self.geometry_a.intersections_plane(x, y, z)
b = self.geometry_b.intersections_plane(x, y, z)
geom_a = shapely.unary_union([Geometry.evaluate_inf_shape(g) for g in a])
geom_b = shapely.unary_union([Geometry.evaluate_inf_shape(g) for g in b])
return ClipOperation.to_polygon_list(self._shapely_operation(geom_a, geom_b))

@cached_property
Expand Down
2 changes: 1 addition & 1 deletion tidy3d/components/geometry/polyslab.py
Original file line number Diff line number Diff line change
Expand Up @@ -1745,7 +1745,7 @@ def intersections_tilted_plane(
return [
shapely.unary_union(
[
shape
base.Geometry.evaluate_inf_shape(shape)
for polyslab in self.sub_polyslabs
for shape in polyslab.intersections_tilted_plane(normal, origin, to_2D)
]
Expand Down

0 comments on commit 3e38fb5

Please sign in to comment.