@@ -87,9 +87,8 @@ class PolySlab(base.Planar):
87
87
)
88
88
89
89
@staticmethod
90
- def make_shapely_polygon (vertices : ArrayLike ) -> shapely .Polygon :
90
+ def make_shapely_polygon (vertices : ArrayLike , transpose : bool = False ) -> shapely .Polygon :
91
91
"""Make a shapely polygon from some vertices, first ensures they are untraced."""
92
- vertices = get_static (vertices )
93
92
return shapely .Polygon (vertices )
94
93
95
94
@pydantic .validator ("slab_bounds" , always = True )
@@ -629,13 +628,15 @@ def _do_intersections_tilted_plane(
629
628
path , _ = section .to_planar (to_2D = to_2D )
630
629
return path .polygons_full
631
630
632
- def _intersections_normal (self , z : float ):
631
+ def _intersections_normal (self , z : float , transpose : bool = False ):
633
632
"""Find shapely geometries intersecting planar geometry with axis normal to slab.
634
633
635
634
Parameters
636
635
----------
637
636
z : float
638
637
Position along the axis normal to slab.
638
+ transpose : bool = False
639
+ Optional: Swap the planar (XY) coordinates?
639
640
640
641
Returns
641
642
-------
@@ -644,16 +645,22 @@ def _intersections_normal(self, z: float):
644
645
For more details refer to
645
646
`Shapely's Documentation <https://shapely.readthedocs.io/en/stable/project.html>`_.
646
647
"""
648
+ print (f"PolySlab._intersections_normal({ transpose = } )" ) # DEBUG
647
649
if math .isclose (self .sidewall_angle , 0 ):
648
- return [self .make_shapely_polygon (self .reference_polygon )]
649
-
650
+ vertices = self .reference_polygon
651
+ if transpose :
652
+ vertices = vertices [:, (1 , 0 )] # swap column 0 (x coords) with column 1 (y coords)
653
+ return [self .make_shapely_polygon (vertices , transpose = transpose )]
650
654
z0 = self .center_axis
651
655
z_local = z - z0 # distance to the middle
652
656
dist = - z_local * self ._tanq
653
657
vertices_z = self ._shift_vertices (self .middle_polygon , dist )[0 ]
654
- return [self .make_shapely_polygon (vertices_z )]
658
+ vertices = vertices_z
659
+ if transpose :
660
+ vertices = vertices [:, (1 , 0 )] # swap column 0 (x coords) with column 1 (y coords)
661
+ return [self .make_shapely_polygon (vertices , transpose = transpose )]
655
662
656
- def _intersections_side (self , position , axis ) -> list :
663
+ def _intersections_side (self , position , axis , transpose : bool = False ) -> list :
657
664
"""Find shapely geometries intersecting planar geometry with axis orthogonal to slab.
658
665
659
666
For slanted polyslab, the procedure is as follows,
@@ -678,6 +685,8 @@ def _intersections_side(self, position, axis) -> list:
678
685
Position along ``axis``.
679
686
axis : int
680
687
Integer index into 'xyz' (0,1,2).
688
+ transpose : bool = False
689
+ Optional: Swap the coordinates in the plane orthogonal to the axis?
681
690
682
691
Returns
683
692
-------
@@ -686,12 +695,14 @@ def _intersections_side(self, position, axis) -> list:
686
695
For more details refer to
687
696
`Shapely's Documentation <https://shapely.readthedocs.io/en/stable/project.html>`_.
688
697
"""
698
+ print (f"PolySlab._intersections_side({ transpose = } )" ) # DEBUG
689
699
690
700
# find out all z_i where the plane will intersect the vertex
691
701
z0 = self .center_axis
692
702
z_base = z0 - self .finite_length_axis / 2
693
703
694
704
axis_ordered = self ._order_axis (axis )
705
+
695
706
height_list = self ._find_intersecting_height (position , axis_ordered )
696
707
polys = []
697
708
@@ -723,8 +734,8 @@ def _intersections_side(self, position, axis) -> list:
723
734
for y_index in range (len (ints_y ) // 2 ):
724
735
y_min = ints_y [2 * y_index ]
725
736
y_max = ints_y [2 * y_index + 1 ]
726
- minx , miny = self ._order_by_axis (plane_val = y_min , axis_val = z_min , axis = axis )
727
- maxx , maxy = self ._order_by_axis (plane_val = y_max , axis_val = z_max , axis = axis )
737
+ minx , miny = self ._order_by_axis (plane_val = y_min , axis_val = z_min , axis = axis , transpose = transpose )
738
+ maxx , maxy = self ._order_by_axis (plane_val = y_max , axis_val = z_max , axis = axis , transpose = transpose )
728
739
729
740
if math .isclose (self .sidewall_angle , 0 ):
730
741
polys .append (self .make_shapely_box (minx , miny , maxx , maxy ))
@@ -738,13 +749,13 @@ def _intersections_side(self, position, axis) -> list:
738
749
dy_min = h_length * np .tan (angle_min )
739
750
dy_max = h_length * np .tan (angle_max )
740
751
741
- x1 , y1 = self ._order_by_axis (plane_val = y_min , axis_val = z_min , axis = axis )
742
- x2 , y2 = self ._order_by_axis (plane_val = y_max , axis_val = z_min , axis = axis )
752
+ x1 , y1 = self ._order_by_axis (plane_val = y_min , axis_val = z_min , axis = axis , transpose = transpose )
753
+ x2 , y2 = self ._order_by_axis (plane_val = y_max , axis_val = z_min , axis = axis , transpose = transpose )
743
754
x3 , y3 = self ._order_by_axis (
744
- plane_val = y_max - dy_max , axis_val = z_max , axis = axis
755
+ plane_val = y_max - dy_max , axis_val = z_max , axis = axis , transpose = transpose
745
756
)
746
757
x4 , y4 = self ._order_by_axis (
747
- plane_val = y_min + dy_min , axis_val = z_max , axis = axis
758
+ plane_val = y_min + dy_min , axis_val = z_max , axis = axis , transpose = transpose
748
759
)
749
760
vertices = ((x1 , y1 ), (x2 , y2 ), (x3 , y3 ), (x4 , y4 ))
750
761
polys .append (self .make_shapely_polygon (vertices ).buffer (0 ))
@@ -984,11 +995,16 @@ def _find_intersecting_ys_angle_slant(
984
995
return ints_y_sort , ints_angle_sort
985
996
986
997
@cached_property
987
- def bounds (self ) -> Bound :
998
+ def bounds (self , transpose : bool = False ) -> Bound :
988
999
"""Returns bounding box min and max coordinates. The dilation and slant angle are not
989
1000
taken into account exactly for speed. Instead, the polygon may be slightly smaller than
990
1001
the returned bounds, but it should always be fully contained.
991
1002
1003
+ Parameters
1004
+ -------
1005
+ transpose : bool = False
1006
+ Optional: Swap the planar axes? (the axes perpendicular to self.axis)
1007
+
992
1008
Returns
993
1009
-------
994
1010
Tuple[float, float, float], Tuple[float, float float]
@@ -1021,8 +1037,8 @@ def bounds(self) -> Bound:
1021
1037
zmin , zmax = self .slab_bounds
1022
1038
1023
1039
# rearrange axes
1024
- coords_min = self .unpop_axis (zmin , (xmin , ymin ), axis = self .axis )
1025
- coords_max = self .unpop_axis (zmax , (xmax , ymax ), axis = self .axis )
1040
+ coords_min = self .unpop_axis (zmin , (xmin , ymin ), axis = self .axis , transpose = transpose )
1041
+ coords_max = self .unpop_axis (zmax , (xmax , ymax ), axis = self .axis , transpose = transpose )
1026
1042
return (tuple (coords_min ), tuple (coords_max ))
1027
1043
1028
1044
def _extrusion_length_to_offset_distance (self , extrusion : float ) -> float :
0 commit comments