10
10
import pydantic .v1 as pydantic
11
11
import shapely
12
12
from autograd .tracer import getval , isbox
13
- from matplotlib import path
14
13
15
14
from ...constants import LARGE_NUMBER , MICROMETER , fp_eps
16
15
from ...exceptions import SetupError , ValidationError
@@ -478,6 +477,11 @@ def inside(
478
477
with the same shape which is ``True`` for every point in zip(x, y, z) that is inside the
479
478
volume of the :class:`Geometry`, and ``False`` otherwise.
480
479
480
+ Note
481
+ ----
482
+ For slanted sidewalls, this function only works if x, y, and z are arrays produced by a
483
+ ``meshgrid call``, i.e. 3D arrays and each is constant along one axis.
484
+
481
485
Parameters
482
486
----------
483
487
x : np.ndarray[float]
@@ -523,13 +527,9 @@ def inside(
523
527
524
528
# vertical sidewall
525
529
if math .isclose (self .sidewall_angle , 0 ):
526
- # face_polygon = self.make_shapely_polygon(self.reference_polygon)
527
- # fun_contain = contains_pointwise(face_polygon)
528
- # contains_vectorized = np.vectorize(fun_contain, signature="(n)->()")
529
- poly_path = path .Path (self .reference_polygon )
530
- contains_vectorized = poly_path .contains_points
531
- points_stacked = np .stack ((xs_slab , ys_slab ), axis = 1 )
532
- inside_polygon_slab = contains_vectorized (points_stacked )
530
+ face_polygon = shapely .Polygon (self .reference_polygon )
531
+ shapely .prepare (face_polygon )
532
+ inside_polygon_slab = shapely .contains_xy (face_polygon , x = xs_slab , y = ys_slab )
533
533
inside_polygon [inside_height ] = inside_polygon_slab
534
534
# slanted sidewall, offsetting vertices at each z
535
535
else :
@@ -550,15 +550,11 @@ def _move_axis_reverse(arr):
550
550
vertices_z = self ._shift_vertices (
551
551
self .middle_polygon , _move_axis (dist )[0 , 0 , z_i ]
552
552
)[0 ]
553
- # face_polygon = self.make_shapely_polygon(vertices_z)
554
- # fun_contain = contains_pointwise(face_polygon)
555
- # contains_vectorized = np.vectorize(fun_contain, signature="(n)->()")
556
- poly_path = path .Path (vertices_z )
557
- contains_vectorized = poly_path .contains_points
558
- points_stacked = np .stack (
559
- (x_axis [:, :, 0 ].flatten (), y_axis [:, :, 0 ].flatten ()), axis = 1
560
- )
561
- inside_polygon_slab = contains_vectorized (points_stacked )
553
+ face_polygon = shapely .Polygon (vertices_z )
554
+ shapely .prepare (face_polygon )
555
+ xs = x_axis [:, :, 0 ].flatten ()
556
+ ys = y_axis [:, :, 0 ].flatten ()
557
+ inside_polygon_slab = shapely .contains_xy (face_polygon , x = xs , y = ys )
562
558
inside_polygon_axis [:, :, z_i ] = inside_polygon_slab .reshape (x_axis .shape [:2 ])
563
559
inside_polygon = _move_axis_reverse (inside_polygon_axis )
564
560
else :
0 commit comments