コード例 #1
0
def label_face(face, _attribute_, _font_, label_text, base_pts, labels, wire_frame):
    """Generate labels for a face or sub-face and add it to a list."""
    face_prop = get_attr_nested(face, _attribute_)

    # get a base plane and text height for the text label
    cent_pt = face.geometry.center  # base point for the text
    base_plane = Plane(face.normal, cent_pt)
    if base_plane.y.z < 0:  # base plane pointing downwards; rotate it
        base_plane = base_plane.rotate(base_plane.n, math.pi, base_plane.o)
    if _txt_height_ is None:  # auto-calculate default text height
        txt_len = len(face_prop) if len(face_prop) > 10 else 10
        largest_dim = max((face.geometry.max.x - face.geometry.min.x),
                           (face.geometry.max.y - face.geometry.min.y))
        txt_h = largest_dim / (txt_len * 2)
    else:
        txt_h = _txt_height_

    # move base plane origin a little to avoid overlaps of adjacent labels
    if base_plane.n.x != 0:
        m_vec = base_plane.y if base_plane.n.x < 0 else -base_plane.y
    else:
        m_vec = base_plane.y if base_plane.n.z < 0 else -base_plane.y
    base_plane = base_plane.move(m_vec * txt_h)

    # create the text label
    label = text_objects(face_prop, base_plane, txt_h, font=_font_,
                         horizontal_alignment=1, vertical_alignment=3)

    # append everything to the lists
    label_text.append(face_prop)
    base_pts.append(from_plane(base_plane))
    labels.append(label)
    wire_frame.extend(from_face3d_to_wireframe(face.geometry))
コード例 #2
0
def test_move():
    """Test the Plane move method."""
    pt = Point3D(2, 0, 2)
    vec = Vector3D(0, 2, 0)
    plane = Plane(vec, pt)

    vec_1 = Vector3D(2, 2, 2)
    new_plane = plane.move(vec_1)
    assert new_plane.o == Point3D(4, 2, 4)
    assert new_plane.n == Vector3D(0, 1, 0)
    assert new_plane.x == plane.x
    assert new_plane.y == plane.y
    assert new_plane.k == 2
コード例 #3
0
def test_linesegment3d_mutability():
    """Test the immutability of Plane objects."""
    pt = Point3D(2, 0, 0)
    vec = Vector3D(0, 2, 0)
    plane = Plane(vec, pt)

    assert isinstance(plane, Plane)
    with pytest.raises(AttributeError):
        plane.o.x = 3
    with pytest.raises(AttributeError):
        plane.n.x = 3
    with pytest.raises(AttributeError):
        plane.o = Point3D(0, 0, 0)
    with pytest.raises(AttributeError):
        plane.n = Vector3D(2, 2, 0)
    # ensure operations that yield new objects are ok
    plane_move = plane.move(Vector3D(-2, 0, 0))
    assert plane_move.o == Point3D(0, 0, 0)