Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace infinite coordinates for shapely operation #2014

Merged
merged 1 commit into from
Oct 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -24,6 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- 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.
- Gradient calculation is orders of magnitude faster for large datasets and many structures by applying more efficient handling of field interpolation and passing to structures.
- Bug with infinite coordinates in `ClipOperation` not working with shapely.

## [2.7.4] - 2024-09-25

Expand Down
11 changes: 11 additions & 0 deletions tests/test_components/test_geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,17 @@ def test_intersections_plane(component):
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
Loading