@@ -462,8 +462,8 @@ def _pop_bounds(
462
462
Packed as ``(zmin, zmax), ((xmin, ymin), (xmax, ymax))``.
463
463
"""
464
464
b_min , b_max = self .bounds
465
- zmin , (xmin , ymin ) = self .pop_axis (b_min , axis = axis , swap_axes = swap_axes )
466
- zmax , (xmax , ymax ) = self .pop_axis (b_max , axis = axis , swap_axes = swap_axes )
465
+ zmin , (xmin , ymin ) = self .pop_axis_and_swap (b_min , axis = axis , swap_axes = swap_axes )
466
+ zmax , (xmax , ymax ) = self .pop_axis_and_swap (b_max , axis = axis , swap_axes = swap_axes )
467
467
return (zmin , zmax ), ((xmin , ymin ), (xmax , ymax ))
468
468
469
469
@staticmethod
@@ -611,7 +611,7 @@ def _get_plot_labels(axis: Axis, swap_axes: bool = False) -> tuple[str, str]:
611
611
str, str
612
612
Labels of plot, packaged as ``(xlabel, ylabel)``.
613
613
"""
614
- _ , (xlabel , ylabel ) = Geometry .pop_axis ("xyz" , axis = axis , swap_axes = swap_axes )
614
+ _ , (xlabel , ylabel ) = Geometry .pop_axis_and_swap ("xyz" , axis = axis , swap_axes = swap_axes )
615
615
return xlabel , ylabel
616
616
617
617
def _get_plot_limits (
@@ -734,7 +734,6 @@ def evaluate_inf_shape(shape: Shapely) -> Shapely:
734
734
def pop_axis (
735
735
coord : tuple [Any , Any , Any ],
736
736
axis : int ,
737
- swap_axes : bool = False ,
738
737
) -> tuple [Any , tuple [Any , Any ]]:
739
738
"""Separates coordinate at ``axis`` index from coordinates on the plane tangent to ``axis``.
740
739
@@ -744,8 +743,7 @@ def pop_axis(
744
743
Tuple of three values in original coordinate system.
745
744
axis : int
746
745
Integer index into 'xyz' (0,1,2).
747
- swap_axes: bool = False
748
- Optional: Swap the order of the remaining two axes?
746
+
749
747
750
748
Returns
751
749
-------
@@ -756,16 +754,47 @@ def pop_axis(
756
754
"""
757
755
plane_vals = list (coord )
758
756
axis_val = plane_vals .pop (axis )
759
- if swap_axes :
760
- plane_vals = [plane_vals [1 ], plane_vals [0 ]]
761
757
return axis_val , tuple (plane_vals )
762
758
759
+ @staticmethod
760
+ def pop_axis_and_swap (
761
+ coord : tuple [Any , Any , Any ],
762
+ axis : int ,
763
+ swap_axes : bool = False ,
764
+ ) -> tuple [Any , tuple [Any , Any ]]:
765
+ """
766
+ pop_axis_and_swap() is identical to pop_axis(), except that accepts an
767
+ additional "swap_axes" argument which reverses the output orer. Examples:
768
+
769
+ pop_axis_and_swap(("x", "y", "z"), 1, swap_axes=False) -> "y", ("x", "z")
770
+ pop_axis_and_swap(("x", "y", "z"), 1, swap_axes=True) -> "y", ("z", "x")
771
+
772
+ Parameters
773
+ ----------
774
+ coord : Tuple[Any, Any, Any]
775
+ Tuple of three values in original coordinate system.
776
+ axis : int
777
+ Integer index into 'xyz' (0,1,2).
778
+ swap_axes: bool = False
779
+ Optional: Swap the order of the data from the two remaining axes in the output tuple?
780
+
781
+ Returns
782
+ -------
783
+ Any, Tuple[Any, Any]
784
+ The input coordinates are separated into the one along the axis provided
785
+ and the two on the planar coordinates,
786
+ like ``axis_coord, (planar_coord1, planar_coord2)``.
787
+ """
788
+ axis_val , plane_vals = Geometry .pop_axis (coord , axis )
789
+ if swap_axes :
790
+ return axis_val , (plane_vals [1 ], plane_vals [0 ])
791
+ return axis_val , plane_vals
792
+
763
793
@staticmethod
764
794
def unpop_axis (
765
795
ax_coord : Any ,
766
796
plane_coords : tuple [Any , Any ],
767
797
axis : int ,
768
- swap_axes : bool = False ,
769
798
) -> tuple [Any , Any , Any ]:
770
799
"""Combine coordinate along axis with coordinates on the plane tangent to the axis.
771
800
@@ -777,23 +806,55 @@ def unpop_axis(
777
806
Values along ordered planar directions.
778
807
axis : int
779
808
Integer index into 'xyz' (0,1,2).
780
- swap_axes: bool = False
781
- Optional: Swap the order of the entries in plane_coords[]?
782
- NOTE: If `axis, plane_coords = pop_axis(coords, axis, transpose)`,
783
- then, if you want to get back the original `coords`, you should use:
784
- `unpop_axis(ax_coord, plane_coords, axis, transpose)`
785
809
786
810
Returns
787
811
-------
788
812
Tuple[Any, Any, Any]
789
813
The three values in the xyz coordinate system.
790
814
"""
791
815
coords = list (plane_coords )
792
- if swap_axes :
793
- coords = [coords [1 ], coords [0 ]]
794
816
coords .insert (axis , ax_coord )
795
817
return tuple (coords )
796
818
819
+ @staticmethod
820
+ def unpop_axis_and_swap (
821
+ ax_coord : Any ,
822
+ plane_coords : tuple [Any , Any ],
823
+ axis : int ,
824
+ swap_axes : bool = False ,
825
+ ) -> tuple [Any , Any , Any ]:
826
+ """
827
+ unpop_axis_and_swap() is identical to unpop_axis(), except that accepts
828
+ an additional "swap_axes" argument which reverses the order of
829
+ plane_coords before sending them to unpop_axis(). For example:
830
+
831
+ unpop_axis_and_swap("y", ("x", "z"), 1, swap_axes=False) --> ("x", "y", "z")
832
+ unpop_axis_and_swap("y", ("x", "z"), 1, swap_axes=True) --> ("z", "y", "x")
833
+
834
+ This function is the inverse of pop_axis_and_swap(). For example:
835
+ unpop_axis_and_swap("y", ("z", "x"), 1, swap_axes=True) --> ("x", "y", "z")
836
+
837
+ Parameters
838
+ ----------
839
+ ax_coord : Any
840
+ Value along axis direction.
841
+ plane_coords : Tuple[Any, Any]
842
+ Values along ordered planar directions.
843
+ axis : int
844
+ Integer index into 'xyz' (0,1,2).
845
+ swap_axes: bool = False
846
+ Optional: Swap the order of the entries in plane_coords[]?
847
+
848
+ Returns
849
+ -------
850
+ Tuple[Any, Any, Any]
851
+ The three values in the xyz coordinate system.
852
+ """
853
+ coords = plane_coords
854
+ if swap_axes :
855
+ coords = (coords [1 ], coords [0 ])
856
+ return Geometry .unpop_axis (ax_coord , coords , axis )
857
+
797
858
@staticmethod
798
859
def parse_xyz_kwargs (** xyz ) -> tuple [Axis , float ]:
799
860
"""Turns x,y,z kwargs into index of the normal axis and position along that axis.
@@ -1813,7 +1874,7 @@ def _order_by_axis(
1813
1874
"""
1814
1875
vals = 3 * [plane_val ]
1815
1876
vals [self .axis ] = axis_val
1816
- _ , (val_x , val_y ) = self .pop_axis (vals , axis = axis , swap_axes = swap_axes )
1877
+ _ , (val_x , val_y ) = self .pop_axis_and_swap (vals , axis = axis , swap_axes = swap_axes )
1817
1878
return val_x , val_y
1818
1879
1819
1880
@cached_property
@@ -2107,8 +2168,8 @@ def intersections_plane(
2107
2168
axis , position = self .parse_xyz_kwargs (x = x , y = y , z = z )
2108
2169
if not self .intersects_axis_position (axis , position ):
2109
2170
return []
2110
- z0 , (x0 , y0 ) = self .pop_axis (self .center , axis = axis , swap_axes = swap_axes )
2111
- Lz , (Lx , Ly ) = self .pop_axis (self .size , axis = axis , swap_axes = swap_axes )
2171
+ z0 , (x0 , y0 ) = self .pop_axis_and_swap (self .center , axis = axis , swap_axes = swap_axes )
2172
+ Lz , (Lx , Ly ) = self .pop_axis_and_swap (self .size , axis = axis , swap_axes = swap_axes )
2112
2173
dz = np .abs (z0 - position )
2113
2174
if dz > Lz / 2 + fp_eps :
2114
2175
return []
@@ -2183,7 +2244,7 @@ def intersections_with(self, other, swap_axes: bool = False):
2183
2244
shapes_plane = other .intersections_plane (** xyz_kwargs , swap_axes = swap_axes )
2184
2245
2185
2246
# intersect all shapes with the input self
2186
- bs_min , bs_max = (self .pop_axis (bounds , axis = normal_ind , swap_axes = swap_axes )[1 ] for bounds in self .bounds )
2247
+ bs_min , bs_max = (self .pop_axis_and_swap (bounds , axis = normal_ind , swap_axes = swap_axes )[1 ] for bounds in self .bounds )
2187
2248
2188
2249
shapely_box = self .make_shapely_box (bs_min [0 ], bs_min [1 ], bs_max [0 ], bs_max [1 ])
2189
2250
shapely_box = Geometry .evaluate_inf_shape (shapely_box )
@@ -2285,7 +2346,7 @@ def _plot_arrow(
2285
2346
"""
2286
2347
2287
2348
plot_axis , _ = self .parse_xyz_kwargs (x = x , y = y , z = z )
2288
- _ , (dx , dy ) = self .pop_axis (direction , axis = plot_axis , swap_axes = swap_axes )
2349
+ _ , (dx , dy ) = self .pop_axis_and_swap (direction , axis = plot_axis , swap_axes = swap_axes )
2289
2350
2290
2351
# conditions to check to determine whether to plot arrow, taking into account the
2291
2352
# possibility of a custom arrow base
@@ -2297,12 +2358,12 @@ def _plot_arrow(
2297
2358
)
2298
2359
center = arrow_base
2299
2360
2300
- _ , (dx , dy ) = self .pop_axis (direction , axis = plot_axis , swap_axes = swap_axes )
2361
+ _ , (dx , dy ) = self .pop_axis_and_swap (direction , axis = plot_axis , swap_axes = swap_axes )
2301
2362
components_in_plane = any (not np .isclose (component , 0 ) for component in (dx , dy ))
2302
2363
2303
2364
# plot if arrow in plotting plane and some non-zero component can be displayed.
2304
2365
if arrow_intersecting_plane and components_in_plane :
2305
- _ , (x0 , y0 ) = self .pop_axis (center , axis = plot_axis , swap_axes = swap_axes )
2366
+ _ , (x0 , y0 ) = self .pop_axis_and_swap (center , axis = plot_axis , swap_axes = swap_axes )
2306
2367
2307
2368
# Reasonable value for temporary arrow size. The correct size and direction
2308
2369
# have to be calculated after all transforms have been set. That is why we
0 commit comments