From ff25fd3fd8df4f63322f9e8b2be0eda9a5b6426b Mon Sep 17 00:00:00 2001 From: Lucas Heitzmann Gabrielli Date: Fri, 11 Oct 2024 08:49:39 -0300 Subject: [PATCH] Replace infinite coordinates for shapely operation Signed-off-by: Lucas Heitzmann Gabrielli --- CHANGELOG.md | 2 ++ docs/faq | 2 +- tests/test_components/test_geometry.py | 11 +++++++++++ tidy3d/components/geometry/base.py | 20 ++++++++------------ tidy3d/components/geometry/polyslab.py | 2 +- 5 files changed, 23 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 16fafa42d1..40ec69a3dd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 @@ -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 diff --git a/docs/faq b/docs/faq index 802f861885..1a74c4b7cb 160000 --- a/docs/faq +++ b/docs/faq @@ -1 +1 @@ -Subproject commit 802f8618852493bbb70e437d02ef6a33594ca6bd +Subproject commit 1a74c4b7cb1a1721fb0490e4510c0e30f0d03ac3 diff --git a/tests/test_components/test_geometry.py b/tests/test_components/test_geometry.py index f99d5a0ac2..294e3c6ad9 100644 --- a/tests/test_components/test_geometry.py +++ b/tests/test_components/test_geometry.py @@ -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)) diff --git a/tidy3d/components/geometry/base.py b/tidy3d/components/geometry/base.py index cd2fff7b3f..45a6453cbe 100644 --- a/tidy3d/components/geometry/base.py +++ b/tidy3d/components/geometry/base.py @@ -2857,12 +2857,10 @@ def intersections_tilted_plane( For more details refer to `Shapely's Documentation `_. """ - 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( @@ -2886,12 +2884,10 @@ def intersections_plane( For more details refer to `Shapely's Documentaton `_. """ - 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 diff --git a/tidy3d/components/geometry/polyslab.py b/tidy3d/components/geometry/polyslab.py index ee23cb9730..c085faca0c 100644 --- a/tidy3d/components/geometry/polyslab.py +++ b/tidy3d/components/geometry/polyslab.py @@ -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) ]