@@ -941,6 +941,75 @@ def test_polyslab_intersection_inf_bounds():
941941 assert poly .intersections_plane (x = 0 )[0 ] == shapely .box (- 1 , - LARGE_NUMBER , 1 , 0 )
942942
943943
944+ def test_polyslab_intersection_with_coincident_plane ():
945+ """Test if intersection returns the correct shape when the plane is coincident with the side face."""
946+ poly = td .PolySlab (
947+ vertices = [[500.0 , - 7500.0 ], [500.0 , 7500.0 ], [- 500.0 , 7500.0 ], [- 500.0 , - 7500.0 ]],
948+ slab_bounds = [0 , 50 ],
949+ axis = 2 ,
950+ )
951+ # Each case should give one side face of the polyslab
952+ expected_x_face = shapely .box (- 7500 , 0 , 7500 , 50 ) # y-extent × z-extent
953+ expected_y_face = shapely .box (- 500 , 0 , 500 , 50 ) # x-extent × z-extent
954+
955+ assert poly .intersections_plane (x = - 500 ) == [expected_x_face ]
956+ assert poly .intersections_plane (x = 500 ) == [expected_x_face ]
957+ assert poly .intersections_plane (y = - 7500 ) == [expected_y_face ]
958+ assert poly .intersections_plane (y = 7500 ) == [expected_y_face ]
959+
960+
961+ def test_polyslab_intersection_rotated_square ():
962+ """Test PolySlab plane intersection with a rotated square (diamond shape)."""
963+ # Create a diamond by rotating a square 45 degrees
964+ size = 2.0
965+ angle = np .pi / 4
966+ base_vertices = np .array (
967+ [[- size / 2 , - size / 2 ], [size / 2 , - size / 2 ], [size / 2 , size / 2 ], [- size / 2 , size / 2 ]]
968+ )
969+ cos_a , sin_a = np .cos (angle ), np .sin (angle )
970+ rotation = np .array ([[cos_a , - sin_a ], [sin_a , cos_a ]])
971+ rotated = base_vertices @ rotation .T
972+ rotated = rotated - rotated .min (axis = 0 ) + 0.5 # shift to positive quadrant
973+ vertices = [tuple (v ) for v in rotated ]
974+
975+ polyslab = td .PolySlab (vertices = vertices , slab_bounds = (0 , 3 ), axis = 2 )
976+
977+ all_verts = np .array (vertices )
978+ left_tip_x = all_verts [:, 0 ].min ()
979+ bottom_tip_y = all_verts [:, 1 ].min ()
980+ x_center = (all_verts [:, 0 ].min () + all_verts [:, 0 ].max ()) / 2
981+
982+ # Test 1: Cut at z=1.5 (middle of slab) - should give full diamond
983+ cross_section = polyslab .intersections_plane (z = 1.5 )
984+ assert len (cross_section ) == 1
985+ assert np .isclose (cross_section [0 ].area , 4.0 )
986+
987+ # Test 2: Cut through center at x=x_center - should give rectangle
988+ cross_section = polyslab .intersections_plane (x = x_center )
989+ assert len (cross_section ) == 1
990+ assert cross_section [0 ].area > 0
991+
992+ # Test 3: Cut at left corner tip (tangent touch) - should give degenerate shape
993+ cross_section = polyslab .intersections_plane (x = left_tip_x )
994+ assert len (cross_section ) == 1
995+ assert np .isclose (cross_section [0 ].area , 0.0 )
996+
997+ # Test 4: Cut near left corner (slightly inside) - should give small shape
998+ cross_section = polyslab .intersections_plane (x = left_tip_x + 0.3 )
999+ assert len (cross_section ) == 1
1000+ assert cross_section [0 ].area > 0
1001+
1002+ # Test 5: Cut at bottom corner (tangent touch) - should give degenerate shape
1003+ cross_section = polyslab .intersections_plane (y = bottom_tip_y )
1004+ assert len (cross_section ) == 1
1005+ assert np .isclose (cross_section [0 ].area , 0.0 )
1006+
1007+ # Test 6: Cut at z=0 (bottom boundary) - should give full diamond
1008+ cross_section = polyslab .intersections_plane (z = 0 )
1009+ assert len (cross_section ) == 1
1010+ assert np .isclose (cross_section [0 ].area , 4.0 )
1011+
1012+
9441013def test_from_shapely ():
9451014 ring = shapely .LinearRing ([(- 16 , 9 ), (- 8 , 9 ), (- 12 , 2 )])
9461015 poly = shapely .Polygon ([(- 2 , 0 ), (- 10 , 0 ), (- 6 , 7 )])
0 commit comments