Example #1
0
def test_radius_getter_setter(square_points, r):
    """Test getting and setting the radius."""
    square_points = square_points[:, :2]
    convexspheropolygon = ConvexSpheropolygon(square_points, r)
    assert convexspheropolygon.radius == r
    convexspheropolygon.radius = r + 1
    assert convexspheropolygon.radius == r + 1
Example #2
0
def test_reordering(square_points, unit_rounded_square):
    """Test that vertices can be reordered appropriately."""
    npt.assert_equal(unit_rounded_square.vertices, square_points)

    unit_rounded_square.reorder_verts(True)
    # We need the roll because the algorithm attempts to minimize unexpected
    # vertex shuffling by keeping the original 0 vertex in place.
    reordered_points = np.roll(np.flip(square_points, axis=0), shift=1, axis=0)
    npt.assert_equal(unit_rounded_square.vertices, reordered_points)

    # Original vertices are clockwise, so they'll be flipped on construction if
    # we specify the normal.
    new_square = ConvexSpheropolygon(square_points, 1, normal=[0, 0, 1])
    npt.assert_equal(new_square.vertices, reordered_points)

    new_square.reorder_verts(True)
    npt.assert_equal(new_square.vertices, square_points)
Example #3
0
    def testfun(random_quat):
        assume(not np.all(random_quat == 0))
        random_quat = rowan.normalize(random_quat)
        rotated_points = rowan.rotate(random_quat, square_points)
        r = 1
        poly = ConvexSpheropolygon(rotated_points, radius=r)

        hull = ConvexHull(square_points[:, :2])

        cap_area = np.pi * r * r
        edge_area = np.sum(np.linalg.norm(square_points -
                                          np.roll(square_points, 1, 0),
                                          axis=1),
                           axis=0)
        sphero_area = cap_area + edge_area
        assert np.isclose(poly.signed_area, hull.volume + sphero_area)

        poly.reorder_verts(clockwise=True)
        assert np.isclose(poly.signed_area, -hull.volume - sphero_area)
Example #4
0
def test_convex_area(points):
    """Check the areas of various convex sets."""
    hull = ConvexHull(points)
    verts = points[hull.vertices]
    r = 1
    poly = ConvexSpheropolygon(verts, radius=r)

    cap_area = np.pi * r * r
    edge_area = np.sum(np.linalg.norm(verts - np.roll(verts, 1, 0), axis=1), axis=0)
    assert np.isclose(hull.volume + edge_area + cap_area, poly.area)
Example #5
0
def test_identical_points(ones):
    """Ensure that running with identical points produces an error."""
    with pytest.raises(ValueError):
        ConvexSpheropolygon(ones, 1)
Example #6
0
def test_duplicate_points(square_points):
    """Ensure that running with any duplicate points produces a warning."""
    square_points = np.vstack((square_points, square_points[[0]]))
    with pytest.raises(ValueError):
        ConvexSpheropolygon(square_points, 1)
Example #7
0
def test_invalid_radius_setter(square_points, r):
    """Test setting invalid radius values."""
    square_points = square_points[:, :2]
    spheropolygon = ConvexSpheropolygon(square_points, 1)
    with pytest.raises(ValueError):
        spheropolygon.radius = r
Example #8
0
def test_invalid_radius_constructor(square_points, r):
    """Test invalid radius values in constructor."""
    square_points = square_points[:, :2]
    with pytest.raises(ValueError):
        ConvexSpheropolygon(square_points, r)
Example #9
0
def test_2d_verts(square_points):
    """Try creating object with 2D vertices."""
    square_points = square_points[:, :2]
    ConvexSpheropolygon(square_points, 1)
Example #10
0
def unit_rounded_square():
    return ConvexSpheropolygon(get_square_points(), 1)
Example #11
0
def test_reordering_convex(points):
    """Test that vertices can be reordered appropriately."""
    hull = ConvexHull(points)
    verts = points[hull.vertices]
    poly = ConvexSpheropolygon(verts, radius=1)
    assert np.all(poly.vertices[:, :2] == verts)
Example #12
0
def test_nonplanar(square_points):
    """Ensure that nonplanar vertices raise an error."""
    with pytest.raises(ValueError):
        square_points[0, 2] += 1
        ConvexSpheropolygon(square_points, 1)
Example #13
0
 def testfun(r):
     square_points_2d = square_points[:, :2]
     spheropolygon = ConvexSpheropolygon(square_points_2d, 1)
     with pytest.raises(ValueError):
         spheropolygon.radius = r
Example #14
0
 def testfun(r):
     square_points_2d = square_points[:, :2]
     with pytest.raises(ValueError):
         ConvexSpheropolygon(square_points_2d, r)
Example #15
0
 def testfun(r):
     square_points_2d = square_points[:, :2]
     convexspheropolygon = ConvexSpheropolygon(square_points_2d, r)
     assert convexspheropolygon.radius == r
     convexspheropolygon.radius = r + 1
     assert convexspheropolygon.radius == r + 1
Example #16
0
 def testfun(rounding_radius, vertex_shift):
     theta = np.linspace(0, 2 * np.pi, 10000)
     shape = ConvexSpheropolygon(verts + np.asarray(vertex_shift), rounding_radius)
     distance = shape.distance_to_surface(theta)
     assert_distance_to_surface_2d(shape, theta, distance)