def test_maximal_centered_bounded_circle(convex_square): circle = convex_square.maximal_centered_bounded_circle assert np.all(circle.center == convex_square.center) assert circle.radius == 0.5 with pytest.deprecated_call(): assert sphere_isclose(convex_square.incircle_from_center, circle)
def test_minimal_bounding_circle_radius_regular_polygon(poly): rmax = np.max(np.linalg.norm(poly.vertices, axis=-1)) circle = poly.minimal_bounding_circle assert np.isclose(rmax, circle.radius) assert np.allclose(circle.center, 0) with pytest.deprecated_call(): assert sphere_isclose(circle, poly.bounding_circle)
def test_bounding_sphere_platonic(poly): # Ensure polyhedron is centered, then compute distances. poly.center = [0, 0, 0] r2 = np.sum(poly.vertices**2, axis=1) bounding_sphere = poly.minimal_bounding_sphere assert np.allclose(r2, bounding_sphere.radius**2, rtol=1e-4) with pytest.deprecated_call(): assert sphere_isclose(bounding_sphere, poly.bounding_sphere)
def testfun(center, points, shape_index): poly = shapes[shape_index] poly.center = center sphere = poly.minimal_centered_bounding_sphere scaled_points = points * sphere.radius + sphere.center points_outside = np.logical_not(sphere.is_inside(scaled_points)) # Verify that all points outside the circumsphere are also outside the # polyhedron. assert not np.any( np.logical_and(points_outside, poly.is_inside(scaled_points))) with pytest.deprecated_call(): assert sphere_isclose(sphere, poly.circumsphere_from_center)
def test_insphere(poly): # The insphere should be centered for platonic solids. poly_insphere = poly.insphere assert sphere_isclose(poly_insphere, poly.maximal_centered_bounded_sphere, atol=1e-4) # The insphere of a platonic solid should be rotation invariant. @settings(deadline=300) @given(Random3DRotationStrategy) def check_rotation_invariance(quat): rotated_poly = ConvexPolyhedron(rowan.rotate(quat, poly.vertices)) assert sphere_isclose(poly_insphere, rotated_poly.insphere, atol=1e-4) check_rotation_invariance()
def test_incircle(poly): # The incircle should be centered for regular polygons. assert sphere_isclose(poly.incircle, poly.maximal_centered_bounded_circle) def check_rotation_invariance(quat): rotated_poly = ConvexPolygon(rowan.rotate(quat, poly.vertices)) assert sphere_isclose(poly.incircle, rotated_poly.incircle) # The incircle of a regular polygon should be rotation invariant. given(Random2DRotationStrategy)(check_rotation_invariance)() # The calculation should also be robust to out-of-plane rotations. Note # that currently this test relies on the fact that circles are not # orientable, otherwise they would need to be rotated back into the plane # for the comparison. given(Random3DRotationStrategy)(check_rotation_invariance)()
def test_maximal_centered_bounded_sphere_convex_hulls(points, test_points): hull = ConvexHull(points) poly = ConvexPolyhedron(points[hull.vertices]) try: insphere = poly.maximal_centered_bounded_sphere except ValueError as e: # Ignore cases where triangulation fails, we're not interested in # trying to get polytri to work for nearly degenerate cases. if str(e) == "Triangulation failed": assume(False) assert poly.is_inside(insphere.center) test_points *= insphere.radius * 3 points_in_sphere = insphere.is_inside(test_points) points_in_poly = poly.is_inside(test_points) assert np.all(points_in_sphere <= points_in_poly) assert insphere.volume < poly.volume with pytest.deprecated_call(): assert sphere_isclose(insphere, poly.insphere_from_center)
def test_maximal_centered_bounded_circle(r, center): circ = Circle(r, center) assert sphere_isclose(circ.maximal_centered_bounded_circle, circ)
def test_minimal_centered_bounding_circle(r, center): circ = Circle(r, center) assert sphere_isclose(circ.minimal_centered_bounding_circle, circ)
def test_maximal_centered_bounded_circle(a, b, center): ellipse = Ellipse(a, b, center) bounded_circle = ellipse.maximal_centered_bounded_circle assert sphere_isclose(bounded_circle, Circle(min(a, b), center))
def test_maximal_centered_bounded_sphere(a, b, c, center): ellipsoid = Ellipsoid(a, b, c, center) bounded_sphere = ellipsoid.maximal_centered_bounded_sphere sphere_isclose(bounded_sphere, Sphere(min(a, b, c), center))
def test_minimal_centered_bounding_circle(poly): assert sphere_isclose( poly.minimal_centered_bounding_circle, Circle(np.linalg.norm(poly.vertices, axis=-1).max()), )
def check_rotation_invariance(quat): rotated_poly = ConvexPolygon(rowan.rotate(quat, poly.vertices)) assert sphere_isclose(poly.incircle, rotated_poly.incircle)
def test_maximal_centered_bounded_sphere(r, center): sphere = Sphere(r, center) bounded_sphere = sphere.maximal_centered_bounded_sphere assert sphere_isclose(bounded_sphere, Sphere(r, center))
def test_minimal_centered_bounding_sphere(r, center): sphere = Sphere(r, center) bounding_sphere = sphere.minimal_centered_bounding_sphere assert sphere_isclose(bounding_sphere, Sphere(r, center))
def test_minimal_bounding_circle(a, b, center): ellipse = Ellipse(a, b, center) bounding_circle = ellipse.minimal_bounding_circle assert sphere_isclose(bounding_circle, Circle(max(a, b), center))
def check_rotation_invariance(quat): rotated_poly = ConvexPolyhedron(rowan.rotate(quat, poly.vertices)) assert sphere_isclose(poly_insphere, rotated_poly.insphere, atol=1e-4)
def test_minimal_centered_bounding_sphere(a, b, c, center): ellipsoid = Ellipsoid(a, b, c, center) bounding_sphere = ellipsoid.minimal_centered_bounding_sphere sphere_isclose(bounding_sphere, Sphere(max(a, b, c), center))