Skip to content

Commit 7b92220

Browse files
Gregory Robertsgroberts-flex
authored andcommitted
fix[frontend]: fix computation of finite axis length for PolySlab
1 parent 35ab0f2 commit 7b92220

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2323

2424
### Fixed
2525
- Fixed issue with `CustomMedium` gradients where other frequencies would wrongly contribute to the gradient.
26+
- Fixed bug when computing `PolySlab` bounds in plotting functions.
2627

2728
## [2.8.3] - 2025-04-24
2829

tests/test_components/test_geometry.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,37 @@ def test_polyslab_bounds():
307307
td.PolySlab(vertices=((0, 0), (1, 0), (1, 1)), slab_bounds=(0.5, -0.5), axis=2)
308308

309309

310+
@pytest.mark.parametrize("axis", (0, 1, 2))
311+
def test_polyslab_inf_to_finite_bounds(axis):
312+
"""Test that finite_length_axis for PolySlab first clips at LARGE_NUMBER and then computes the length."""
313+
axis_bound = 20
314+
ps_low_inf = td.PolySlab(
315+
axis=axis,
316+
slab_bounds=[-td.inf, axis_bound],
317+
vertices=[[0, 0], [2.5, 1], [2, 3], [0.5, 4], [-1.5, 2.5]],
318+
)
319+
ps_high_inf = td.PolySlab(
320+
axis=axis,
321+
slab_bounds=[-axis_bound, td.inf],
322+
vertices=[[0, 0], [2.5, 1], [2, 3], [0.5, 4], [-1.5, 2.5]],
323+
)
324+
ps_inf = td.PolySlab(
325+
axis=axis,
326+
slab_bounds=[-td.inf, td.inf],
327+
vertices=[[0, 0], [2.5, 1], [2, 3], [0.5, 4], [-1.5, 2.5]],
328+
)
329+
330+
assert ps_low_inf.finite_length_axis == (
331+
LARGE_NUMBER + axis_bound
332+
), "Unexpected finite length for polyslab axis with -inf bound"
333+
assert ps_high_inf.finite_length_axis == (
334+
LARGE_NUMBER + axis_bound
335+
), "Unexpected finite length for polyslab axis with inf bound"
336+
assert (
337+
ps_inf.finite_length_axis == 2 * LARGE_NUMBER
338+
), "Unexpected finite length for polyslab axis with two inf bounds"
339+
340+
310341
def test_validate_polyslab_vertices_valid():
311342
with pytest.raises(pydantic.ValidationError):
312343
POLYSLAB.copy(update=dict(vertices=(1, 2, 3)))

tidy3d/components/geometry/polyslab.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,16 @@ def length_axis(self) -> float:
388388
zmin, zmax = self.slab_bounds
389389
return zmax - zmin
390390

391+
@property
392+
def finite_length_axis(self) -> float:
393+
"""Gets the length of the PolySlab along the out of plane dimension.
394+
First clips the slab bounds to LARGE_NUMBER and then returns difference.
395+
"""
396+
zmin, zmax = self.slab_bounds
397+
zmin = max(zmin, -LARGE_NUMBER)
398+
zmax = min(zmax, LARGE_NUMBER)
399+
return zmax - zmin
400+
391401
@cached_property
392402
def reference_polygon(self) -> np.ndarray:
393403
"""The polygon at the reference plane.

0 commit comments

Comments
 (0)