Skip to content

Commit 7f3d264

Browse files
committed
updated the unit tests after removing the "transpose" argument from "intersections_plane()" and reverted the format of some of the function calls to reduce the number of changed lines
1 parent d5963bb commit 7f3d264

File tree

5 files changed

+35
-101
lines changed

5 files changed

+35
-101
lines changed

tests/test_components/test_geometry.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -207,11 +207,11 @@ def test_array_to_vertices():
207207
assert np.all(np.array(vertices) == np.array(vertices2))
208208

209209

210-
@pytest.mark.parametrize("component, transpose", zip(GEO_TYPES, [True, False]))
211-
def test_intersections_plane(component, transpose):
212-
assert len(component.intersections_plane(z=0.2, transpose=transpose)) > 0
213-
assert len(component.intersections_plane(x=0.2, transpose=transpose)) > 0
214-
assert len(component.intersections_plane(x=10000, transpose=transpose)) == 0
210+
@pytest.mark.parametrize("component", GEO_TYPES)
211+
def test_intersections_plane(component):
212+
assert len(component.intersections_plane(z=0.2)) > 0
213+
assert len(component.intersections_plane(x=0.2)) > 0
214+
assert len(component.intersections_plane(x=10000)) == 0
215215

216216

217217
def test_intersections_plane_inf():
@@ -780,25 +780,24 @@ def test_pop_axis():
780780
assert Ly == _Ly
781781

782782

783-
@pytest.mark.parametrize("transpose", [True, False])
784-
def test_2b_box_intersections(transpose):
783+
def test_2b_box_intersections():
785784
plane = td.Box(size=(1, 4, 0))
786785
box1 = td.Box(size=(1, 1, 1))
787786
box2 = td.Box(size=(1, 1, 1), center=(3, 0, 0))
788787

789-
result = plane.intersections_with(box1, transpose=transpose)
788+
result = plane.intersections_with(box1)
790789
assert len(result) == 1
791790
assert result[0].geom_type == "Polygon"
792-
assert len(plane.intersections_with(box2, transpose=transpose)) == 0
791+
assert len(plane.intersections_with(box2)) == 0
793792

794793
with pytest.raises(ValidationError):
795-
_ = box1.intersections_with(box2, transpose=transpose)
794+
_ = box1.intersections_with(box2)
796795

797-
assert len(box1.intersections_2dbox(plane, transpose=transpose)) == 1
798-
assert len(box2.intersections_2dbox(plane, transpose=transpose)) == 0
796+
assert len(box1.intersections_2dbox(plane)) == 1
797+
assert len(box2.intersections_2dbox(plane)) == 0
799798

800799
with pytest.raises(ValidationError):
801-
_ = box2.intersections_2dbox(box1, transpose=transpose)
800+
_ = box2.intersections_2dbox(box1)
802801

803802

804803
def test_polyslab_merge():
@@ -975,11 +974,11 @@ def test_custom_surface_geometry(transpose, tmp_path):
975974

976975
# test intersections
977976
assert shapely.equals(
978-
geom.intersections_plane(x=0, transpose=transpose),
977+
geom.intersections_plane(x=0),
979978
shapely.Polygon([[0, 0], [0, 1], [1, 0]]),
980979
)
981980
assert shapely.equals(
982-
geom.intersections_plane(z=0.5, transpose=transpose),
981+
geom.intersections_plane(z=0.5),
983982
shapely.Polygon([[0, 0], [0, 0.5], [0.5, 0]]),
984983
)
985984

tidy3d/components/geometry/base.py

Lines changed: 14 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -218,10 +218,7 @@ def inside_meshgrid(
218218

219219
@abstractmethod
220220
def intersections_tilted_plane(
221-
self,
222-
normal: Coordinate,
223-
origin: Coordinate,
224-
to_2D: MatrixReal4x4,
221+
self, normal: Coordinate, origin: Coordinate, to_2D: MatrixReal4x4
225222
) -> list[Shapely]:
226223
"""Return a list of shapely geometries at the plane specified by normal and origin.
227224
@@ -243,10 +240,7 @@ def intersections_tilted_plane(
243240
"""
244241

245242
def intersections_plane(
246-
self,
247-
x: Optional[float] = None,
248-
y: Optional[float] = None,
249-
z: Optional[float] = None,
243+
self, x: Optional[float] = None, y: Optional[float] = None, z: Optional[float] = None
250244
) -> list[Shapely]:
251245
"""Returns list of shapely geometries at plane specified by one non-None value of x,y,z.
252246
@@ -774,10 +768,7 @@ def evaluate_inf_shape(shape: Shapely) -> Shapely:
774768
return shape
775769

776770
@staticmethod
777-
def pop_axis(
778-
coord: tuple[Any, Any, Any],
779-
axis: int,
780-
) -> tuple[Any, tuple[Any, Any]]:
771+
def pop_axis(coord: tuple[Any, Any, Any], axis: int) -> tuple[Any, tuple[Any, Any]]:
781772
"""Separates coordinate at ``axis`` index from coordinates on the plane tangent to ``axis``.
782773
783774
Parameters
@@ -799,11 +790,7 @@ def pop_axis(
799790
return axis_val, tuple(plane_vals)
800791

801792
@staticmethod
802-
def unpop_axis(
803-
ax_coord: Any,
804-
plane_coords: tuple[Any, Any],
805-
axis: int,
806-
) -> tuple[Any, Any, Any]:
793+
def unpop_axis(ax_coord: Any, plane_coords: tuple[Any, Any], axis: int) -> tuple[Any, Any, Any]:
807794
"""Combine coordinate along axis with coordinates on the plane tangent to the axis.
808795
809796
Parameters
@@ -1602,10 +1589,7 @@ class SimplePlaneIntersection(Geometry, ABC):
16021589
"""A geometry where intersections with an axis aligned plane may be computed efficiently."""
16031590

16041591
def intersections_tilted_plane(
1605-
self,
1606-
normal: Coordinate,
1607-
origin: Coordinate,
1608-
to_2D: MatrixReal4x4,
1592+
self, normal: Coordinate, origin: Coordinate, to_2D: MatrixReal4x4
16091593
) -> list[Shapely]:
16101594
"""Return a list of shapely geometries at the plane specified by normal and origin.
16111595
Checks special cases before relying on the complete computation.
@@ -1651,11 +1635,7 @@ def transform(p_array):
16511635

16521636
@abstractmethod
16531637
def _do_intersections_tilted_plane(
1654-
self,
1655-
normal: Coordinate,
1656-
origin: Coordinate,
1657-
to_2D: MatrixReal4x4,
1658-
transpose: bool = False,
1638+
self, normal: Coordinate, origin: Coordinate, to_2D: MatrixReal4x4
16591639
) -> list[Shapely]:
16601640
"""Return a list of shapely geometries at the plane specified by normal and origin.
16611641
@@ -1735,10 +1715,7 @@ def finite_length_axis(self) -> float:
17351715
return min(self.length_axis, LARGE_NUMBER)
17361716

17371717
def intersections_plane(
1738-
self,
1739-
x: Optional[float] = None,
1740-
y: Optional[float] = None,
1741-
z: Optional[float] = None,
1718+
self, x: Optional[float] = None, y: Optional[float] = None, z: Optional[float] = None
17421719
):
17431720
"""Returns shapely geometry at plane specified by one non None value of x,y,z.
17441721
@@ -2055,10 +2032,7 @@ def surfaces_with_exclusion(cls, size: Size, center: Coordinate, **kwargs):
20552032

20562033
@verify_packages_import(["trimesh"])
20572034
def _do_intersections_tilted_plane(
2058-
self,
2059-
normal: Coordinate,
2060-
origin: Coordinate,
2061-
to_2D: MatrixReal4x4,
2035+
self, normal: Coordinate, origin: Coordinate, to_2D: MatrixReal4x4
20622036
) -> list[Shapely]:
20632037
"""Return a list of shapely geometries at the plane specified by normal and origin.
20642038
@@ -2109,10 +2083,7 @@ def _do_intersections_tilted_plane(
21092083
return path.polygons_full
21102084

21112085
def intersections_plane(
2112-
self,
2113-
x: Optional[float] = None,
2114-
y: Optional[float] = None,
2115-
z: Optional[float] = None,
2086+
self, x: Optional[float] = None, y: Optional[float] = None, z: Optional[float] = None
21162087
):
21172088
"""Returns shapely geometry at plane specified by one non None value of x,y,z.
21182089
@@ -2698,10 +2669,7 @@ def bounds(self) -> Bound:
26982669
return (tuple(vertices.min(axis=1)), tuple(vertices.max(axis=1)))
26992670

27002671
def intersections_tilted_plane(
2701-
self,
2702-
normal: Coordinate,
2703-
origin: Coordinate,
2704-
to_2D: MatrixReal4x4,
2672+
self, normal: Coordinate, origin: Coordinate, to_2D: MatrixReal4x4
27052673
) -> list[Shapely]:
27062674
"""Return a list of shapely geometries at the plane specified by normal and origin.
27072675
@@ -3010,10 +2978,7 @@ def _bit_operation(self) -> Callable[[Any, Any], Any]:
30102978
return result
30112979

30122980
def intersections_tilted_plane(
3013-
self,
3014-
normal: Coordinate,
3015-
origin: Coordinate,
3016-
to_2D: MatrixReal4x4,
2981+
self, normal: Coordinate, origin: Coordinate, to_2D: MatrixReal4x4
30172982
) -> list[Shapely]:
30182983
"""Return a list of shapely geometries at the plane specified by normal and origin.
30192984
@@ -3043,10 +3008,7 @@ def intersections_tilted_plane(
30433008
)
30443009

30453010
def intersections_plane(
3046-
self,
3047-
x: Optional[float] = None,
3048-
y: Optional[float] = None,
3049-
z: Optional[float] = None,
3011+
self, x: Optional[float] = None, y: Optional[float] = None, z: Optional[float] = None
30503012
) -> list[Shapely]:
30513013
"""Returns list of shapely geometries at plane specified by one non-None value of x,y,z.
30523014
@@ -3230,10 +3192,7 @@ def bounds(self) -> Bound:
32303192
)
32313193

32323194
def intersections_tilted_plane(
3233-
self,
3234-
normal: Coordinate,
3235-
origin: Coordinate,
3236-
to_2D: MatrixReal4x4,
3195+
self, normal: Coordinate, origin: Coordinate, to_2D: MatrixReal4x4
32373196
) -> list[Shapely]:
32383197
"""Return a list of shapely geometries at the plane specified by normal and origin.
32393198
@@ -3260,10 +3219,7 @@ def intersections_tilted_plane(
32603219
]
32613220

32623221
def intersections_plane(
3263-
self,
3264-
x: Optional[float] = None,
3265-
y: Optional[float] = None,
3266-
z: Optional[float] = None,
3222+
self, x: Optional[float] = None, y: Optional[float] = None, z: Optional[float] = None
32673223
) -> list[Shapely]:
32683224
"""Returns list of shapely geometries at plane specified by one non-None value of x,y,z.
32693225

tidy3d/components/geometry/mesh.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -527,10 +527,7 @@ def bounds(self) -> Bound:
527527
return self.trimesh.bounds
528528

529529
def intersections_tilted_plane(
530-
self,
531-
normal: Coordinate,
532-
origin: Coordinate,
533-
to_2D: MatrixReal4x4,
530+
self, normal: Coordinate, origin: Coordinate, to_2D: MatrixReal4x4
534531
) -> list[Shapely]:
535532
"""Return a list of shapely geometries at the plane specified by normal and origin.
536533
@@ -557,10 +554,7 @@ def intersections_tilted_plane(
557554
return path.polygons_full
558555

559556
def intersections_plane(
560-
self,
561-
x: Optional[float] = None,
562-
y: Optional[float] = None,
563-
z: Optional[float] = None,
557+
self, x: Optional[float] = None, y: Optional[float] = None, z: Optional[float] = None
564558
) -> list[Shapely]:
565559
"""Returns list of shapely geometries at plane specified by one non-None value of x,y,z.
566560

tidy3d/components/geometry/polyslab.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -583,10 +583,7 @@ def _move_axis_reverse(arr):
583583

584584
@verify_packages_import(["trimesh"])
585585
def _do_intersections_tilted_plane(
586-
self,
587-
normal: Coordinate,
588-
origin: Coordinate,
589-
to_2D: MatrixReal4x4,
586+
self, normal: Coordinate, origin: Coordinate, to_2D: MatrixReal4x4
590587
) -> list[Shapely]:
591588
"""Return a list of shapely geometries at the plane specified by normal and origin.
592589
@@ -2355,10 +2352,7 @@ def _dilation_value_at_reference_to_coord(self, dilation: float) -> float:
23552352
return z_coord
23562353

23572354
def intersections_tilted_plane(
2358-
self,
2359-
normal: Coordinate,
2360-
origin: Coordinate,
2361-
to_2D: MatrixReal4x4,
2355+
self, normal: Coordinate, origin: Coordinate, to_2D: MatrixReal4x4
23622356
) -> list[Shapely]:
23632357
"""Return a list of shapely geometries at the plane specified by normal and origin.
23642358

tidy3d/components/geometry/primitives.py

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,7 @@ def inside(
6969
return (dist_x**2 + dist_y**2 + dist_z**2) <= (self.radius**2)
7070

7171
def intersections_tilted_plane(
72-
self,
73-
normal: Coordinate,
74-
origin: Coordinate,
75-
to_2D: MatrixReal4x4,
72+
self, normal: Coordinate, origin: Coordinate, to_2D: MatrixReal4x4
7673
) -> list[Shapely]:
7774
"""Return a list of shapely geometries at the plane specified by normal and origin.
7875
@@ -113,10 +110,7 @@ def intersections_tilted_plane(
113110
return [shapely.Polygon(vertices[:, :2])]
114111

115112
def intersections_plane(
116-
self,
117-
x: Optional[float] = None,
118-
y: Optional[float] = None,
119-
z: Optional[float] = None,
113+
self, x: Optional[float] = None, y: Optional[float] = None, z: Optional[float] = None
120114
):
121115
"""Returns shapely geometry at plane specified by one non None value of x,y,z.
122116
@@ -382,10 +376,7 @@ def _update_from_bounds(self, bounds: tuple[float, float], axis: Axis) -> Cylind
382376

383377
@verify_packages_import(["trimesh"])
384378
def _do_intersections_tilted_plane(
385-
self,
386-
normal: Coordinate,
387-
origin: Coordinate,
388-
to_2D: MatrixReal4x4,
379+
self, normal: Coordinate, origin: Coordinate, to_2D: MatrixReal4x4
389380
) -> list[Shapely]:
390381
"""Return a list of shapely geometries at the plane specified by normal and origin.
391382

0 commit comments

Comments
 (0)