Пример #1
0
def test_polyface3d_to_from_dict_hole():
    """Test the to/from dict of Polyface3D objects with a hole."""
    bound_pts = [Point3D(0, 0), Point3D(3, 0), Point3D(3, 3), Point3D(0, 3)]
    hole_pts = [Point3D(1, 1), Point3D(2, 1), Point3D(2, 2), Point3D(1, 2)]
    face = Face3D(bound_pts, None, [hole_pts])
    polyface = Polyface3D.from_offset_face(face, 1)

    polyface_dict = polyface.to_dict()
    new_polyface = Polyface3D.from_dict(polyface_dict)

    assert len(new_polyface.vertices) == 16
    assert len(new_polyface.face_indices) == 10
    assert len(new_polyface.faces) == 10
    assert len(new_polyface.edge_indices) == 24
    assert len(new_polyface.edges) == 24
    assert len(new_polyface.naked_edges) == 0
    assert len(new_polyface.non_manifold_edges) == 0
    assert len(new_polyface.internal_edges) == 24
    assert new_polyface.area == pytest.approx(32, rel=1e-3)
    assert new_polyface.volume == pytest.approx(8, rel=1e-3)
    assert new_polyface.is_solid

    assert new_polyface.faces[0].normal.z == pytest.approx(-1, rel=1e-3)
    assert new_polyface.faces[-1].normal.z == pytest.approx(1, rel=1e-3)
    assert new_polyface.faces[0].has_holes
    assert new_polyface.faces[-1].has_holes
    for face in polyface.faces:
        assert not face.is_clockwise
def test_polyface3d_to_from_dict_with_overlap():
    """Test the to/from dict of Polyface3D objects with overlapping edges."""
    pts_1 = [Point3D(0, 0, 0), Point3D(0, 2, 0), Point3D(2, 2, 0), Point3D(2, 0, 0)]
    pts_2 = [Point3D(0, 0, 0), Point3D(0, 0, 2), Point3D(0, 2, 2), Point3D(0, 2, 0)]
    pts_3 = [Point3D(0, 0, 0), Point3D(2, 0, 0), Point3D(2, 0, 2), Point3D(0, 0, 2)]
    pts_4 = [Point3D(2, 2, 0), Point3D(0, 2, 0), Point3D(0, 2, 2), Point3D(2, 2, 2)]
    pts_5 = [Point3D(2, 2, 0), Point3D(2, 0, 0), Point3D(2, 0, 2), Point3D(2, 2, 2)]
    pts_6 = [Point3D(0, 0, 2), Point3D(0, 1, 2), Point3D(2, 1, 2), Point3D(2, 0, 2)]
    pts_7 = [Point3D(0, 1, 2), Point3D(0, 2, 2), Point3D(2, 2, 2), Point3D(2, 1, 2)]
    face_1 = Face3D(pts_1)
    face_2 = Face3D(pts_2)
    face_3 = Face3D(pts_3)
    face_4 = Face3D(pts_4)
    face_5 = Face3D(pts_5)
    face_6 = Face3D(pts_6)
    face_7 = Face3D(pts_7)
    polyface = Polyface3D.from_faces(
        [face_1, face_2, face_3, face_4, face_5, face_6, face_7], 0.01)
    new_polyface = polyface.merge_overlapping_edges(0.0001, 0.0001)
    assert new_polyface.is_solid
    assert len(new_polyface.naked_edges) == 0
    assert len(new_polyface.internal_edges) == 13

    polyface_dict = new_polyface.to_dict()
    dict_polyface = Polyface3D.from_dict(polyface_dict)
    assert isinstance(dict_polyface, Polyface3D)
    assert dict_polyface.to_dict() == polyface_dict
    assert dict_polyface.is_solid
    assert len(dict_polyface.naked_edges) == 0
    assert len(dict_polyface.internal_edges) == 13
Пример #3
0
def test_polyface3d_to_from_dict():
    """Test the to/from dict of Polyface3D objects."""
    polyface = Polyface3D.from_box(2, 4, 2)

    polyface_dict = polyface.to_dict()
    new_polyface = Polyface3D.from_dict(polyface_dict)
    assert isinstance(new_polyface, Polyface3D)
    assert new_polyface.to_dict() == polyface_dict

    assert len(new_polyface.vertices) == 8
    assert len(new_polyface.face_indices) == 6
    assert len(new_polyface.faces) == 6
    assert len(new_polyface.edge_indices) == 12
    assert len(new_polyface.edges) == 12
    assert len(new_polyface.naked_edges) == 0
    assert len(new_polyface.non_manifold_edges) == 0
    assert len(new_polyface.internal_edges) == 12
    assert new_polyface.area == 40
    assert new_polyface.volume == 16
    assert new_polyface.is_solid