Ejemplo n.º 1
0
def test_square_by_radius():
    corners = list(ngon(4, radius=1))
    assert len(corners) == 4
    assert is_close_points(corners[0], (1, 0, 0))
    assert is_close_points(corners[1], (0, 1, 0))
    assert is_close_points(corners[2], (-1, 0, 0))
    assert is_close_points(corners[3], (0, -1, 0))
Ejemplo n.º 2
0
def test_spline_interpolation():
    vertices = [(0., 0.), (1., 2.), (3., 1.), (5., 3.)]
    result = spline_interpolation(vertices, method='uniform', subdivide=4)
    assert len(result) == 13  # (len-1) * subdivide + 1
    assert is_close_points((0, 0, 0), result[0]), 'expected start point'
    assert is_close_points((5, 3, 0), result[-1]), 'expected end point'
    assert is_close_points((1, 2, 0), result[4]), 'expected 2. fit point'
    assert is_close_points((3, 1, 0), result[8]), 'expected 3. fit point'
Ejemplo n.º 3
0
def test_spatial_arc_from_3p():
    start_point_wcs = Vector(0, 1, 0)
    end_point_wcs = Vector(1, 0, 0)
    def_point_wcs = Vector(0, 0, 1)

    ucs = UCS.from_x_axis_and_point_in_xy(origin=def_point_wcs,
                                          axis=end_point_wcs - def_point_wcs,
                                          point=start_point_wcs)
    start_point_ucs = ucs.from_wcs(start_point_wcs)
    end_point_ucs = ucs.from_wcs(end_point_wcs)
    def_point_ucs = Vector(0, 0)

    arc = ConstructionArc.from_3p(start_point_ucs, end_point_ucs,
                                  def_point_ucs)
    dwg = ezdxf.new('R12')
    msp = dwg.modelspace()

    dxf_arc = arc.add_to_layout(msp, ucs)
    assert dxf_arc.dxftype() == 'ARC'
    assert isclose(dxf_arc.dxf.radius, 0.81649658, abs_tol=1e-9)
    assert isclose(dxf_arc.dxf.start_angle, -30)  # ???
    assert isclose(dxf_arc.dxf.end_angle, -150)  # ???
    assert is_close_points(dxf_arc.dxf.extrusion,
                           (0.57735027, 0.57735027, 0.57735027),
                           abs_tol=1e-9)
Ejemplo n.º 4
0
def close_polygon(vertices: Iterable['Vertex']) -> List['Vertex']:
    """
    Returns list of vertices, where vertices[0] == vertices[-1].

    """
    vertices = list(vertices)
    if not is_close_points(vertices[0], vertices[-1]):
        vertices.append(vertices[0])
    return vertices
Ejemplo n.º 5
0
def test_heptagon_by_edge_length():
    corners = list(ngon(7, length=10))
    assert len(corners) == 7
    assert is_close_points(corners[0], (11.523824354812433, 0, 0))
    assert is_close_points(corners[1],
                           (7.184986963636852, 9.009688679024192, 0))
    assert is_close_points(corners[2],
                           (-2.564292158181384, 11.234898018587335, 0))
    assert is_close_points(corners[3], (-10.382606982861683, 5, 0))
    assert is_close_points(corners[4], (-10.382606982861683, -5, 0))
    assert is_close_points(corners[5],
                           (-2.564292158181387, -11.234898018587335, 0))
    assert is_close_points(corners[6],
                           (7.18498696363685, -9.009688679024192, 0))
Ejemplo n.º 6
0
def test_rotate():
    p = [(1, 0, 3), (0, 1, 6)]
    r = list(rotate(p, 90, deg=True))
    assert is_close_points(r[0], (0, 1, 3))
    assert is_close_points(r[1], (-1, 0, 6))
Ejemplo n.º 7
0
def test_scale():
    p = [(1, 2, 3), (4, 5, 6)]
    r = list(scale(p, (3, 2, 1)))
    assert is_close_points(r[0], (3, 4, 3))
    assert is_close_points(r[1], (12, 10, 6))
Ejemplo n.º 8
0
def test_translate():
    p = [(1, 2, 3), (4, 5, 6)]
    r = list(translate(p, (3, 2, 1)))
    assert is_close_points(r[0], (4, 4, 4))
    assert is_close_points(r[1], (7, 7, 7))