Skip to content

Commit 6c65db5

Browse files
committed
added minimal changes to primitives.py
1 parent 41cf6cc commit 6c65db5

File tree

1 file changed

+26
-11
lines changed

1 file changed

+26
-11
lines changed

tidy3d/components/geometry/primitives.py

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ def intersections_plane(
128128
Position of plane in x direction, only one of x,y,z can be specified to define plane.
129129
z : float = None
130130
Position of plane in x direction, only one of x,y,z can be specified to define plane.
131+
transpose : bool = False
132+
Optional: Swap the coordinates in the plane normal to the axis before creating each shape?
131133
132134
Returns
133135
-------
@@ -471,13 +473,15 @@ def _do_intersections_tilted_plane(
471473
path, _ = section.to_planar(to_2D=to_2D)
472474
return path.polygons_full
473475

474-
def _intersections_normal(self, z: float):
476+
def _intersections_normal(self, z: float, transpose: bool = False):
475477
"""Find shapely geometries intersecting cylindrical geometry with axis normal to slab.
476478
477479
Parameters
478480
----------
479481
z : float
480482
Position along the axis normal to slab
483+
transpose : bool = False
484+
Optional: Swap the x and y coordinates?
481485
482486
Returns
483487
-------
@@ -495,10 +499,10 @@ def _intersections_normal(self, z: float):
495499
if radius_offset <= 0:
496500
return []
497501

498-
_, (x0, y0) = self.pop_axis(static_self.center, axis=self.axis)
502+
_, (x0, y0) = self.pop_axis(static_self.center, axis=self.axi, transpose=transpose)
499503
return [shapely.Point(x0, y0).buffer(radius_offset, quad_segs=_N_SHAPELY_QUAD_SEGS)]
500504

501-
def _intersections_side(self, position, axis):
505+
def _intersections_side(self, position, axis, transpose: bool = False):
502506
"""Find shapely geometries intersecting cylindrical geometry with axis orthogonal to length.
503507
When ``sidewall_angle`` is nonzero, so that it's in fact a conical frustum or cone, the
504508
cross section can contain hyperbolic curves. This is currently approximated by a polygon
@@ -510,6 +514,8 @@ def _intersections_side(self, position, axis):
510514
Position along axis direction.
511515
axis : int
512516
Integer index into 'xyz' (0, 1, 2).
517+
transpose : bool = False
518+
Optional: Swap the coordinates in the plane orthogonal to the axis?
513519
514520
Returns
515521
-------
@@ -534,8 +540,8 @@ def _intersections_side(self, position, axis):
534540
# the vertices on the max side of top/bottom
535541
# The two vertices are present in all scenarios.
536542
vertices_max = [
537-
self._local_to_global_side_cross_section([-intersect_half_length_max, 0], axis),
538-
self._local_to_global_side_cross_section([intersect_half_length_max, 0], axis),
543+
self._local_to_global_side_cross_section([-intersect_half_length_max, 0], axis, transpose=transpose),
544+
self._local_to_global_side_cross_section([intersect_half_length_max, 0], axis, transpose=transpose),
539545
]
540546

541547
# Extending to a cone, the maximal height of the cone
@@ -559,7 +565,7 @@ def _intersections_side(self, position, axis):
559565
)
560566
for i in range(_N_SAMPLE_CURVE_SHAPELY):
561567
vertices_frustum_right.append(
562-
self._local_to_global_side_cross_section([x_list[i], y_list[i]], axis)
568+
self._local_to_global_side_cross_section([x_list[i], y_list[i]], axis, transpose=transpose)
563569
)
564570
vertices_frustum_left.append(
565571
self._local_to_global_side_cross_section(
@@ -568,6 +574,7 @@ def _intersections_side(self, position, axis):
568574
y_list[_N_SAMPLE_CURVE_SHAPELY - i - 1],
569575
],
570576
axis,
577+
transpose=transpose,
571578
)
572579
)
573580

@@ -578,17 +585,17 @@ def _intersections_side(self, position, axis):
578585
if intersect_half_length_min > 0:
579586
vertices_min.append(
580587
self._local_to_global_side_cross_section(
581-
[intersect_half_length_min, self.finite_length_axis], axis
588+
[intersect_half_length_min, self.finite_length_axis], axis, transpose=transpose
582589
)
583590
)
584591
vertices_min.append(
585592
self._local_to_global_side_cross_section(
586-
[-intersect_half_length_min, self.finite_length_axis], axis
593+
[-intersect_half_length_min, self.finite_length_axis], axis, transpose=transpose
587594
)
588595
)
589596
## early termination
590597
else:
591-
vertices_min.append(self._local_to_global_side_cross_section([0, height_max], axis))
598+
vertices_min.append(self._local_to_global_side_cross_section([0, height_max], axis, transpose=transpose))
592599

593600
return [
594601
shapely.Polygon(
@@ -735,7 +742,12 @@ def _radius_z(self, z: float):
735742

736743
return radius_middle - (z - self.center_axis) * self._tanq
737744

738-
def _local_to_global_side_cross_section(self, coords: list[float], axis: int) -> list[float]:
745+
def _local_to_global_side_cross_section(
746+
self,
747+
coords: list[float],
748+
axis: int,
749+
transpose: bool = False,
750+
) -> list[float]:
739751
"""Map a point (x,y) from local to global coordinate system in the
740752
side cross section.
741753
@@ -750,6 +762,8 @@ def _local_to_global_side_cross_section(self, coords: list[float], axis: int) ->
750762
Integer index into 'xyz' (0, 1, 2).
751763
coords : List[float, float]
752764
The value in the planar coordinate.
765+
transpose : bool = False
766+
Optional: Swap the coordinates in the plane before converting them?
753767
754768
Returns
755769
-------
@@ -767,6 +781,7 @@ def _local_to_global_side_cross_section(self, coords: list[float], axis: int) ->
767781
plane_val=coords[0],
768782
axis_val=axis_sign * (-self.finite_length_axis / 2 + coords[1]),
769783
axis=axis,
784+
transpose=transpose,
770785
)
771-
_, (x_center, y_center) = self.pop_axis(self.center, axis=axis)
786+
_, (x_center, y_center) = self.pop_axis(self.center, axis=axis, transpose=transpose)
772787
return [x_center + lx_offset, y_center + ly_offset]

0 commit comments

Comments
 (0)