예제 #1
0
def test_tangents():
    e = ConstructionEllipse(center=(3, 3),
                            major_axis=(2, 0),
                            ratio=0.5,
                            start_param=0,
                            end_param=math.pi * 1.5)
    params = list(e.params(7))
    result = [(0.0, 1.0, 0.0), (-0.894427190999916, 0.447213595499958, 0.0),
              (-1.0, 3.061616997868383e-17, 0.0),
              (-0.894427190999916, -0.4472135954999579, 0.0),
              (-2.4492935982947064e-16, -1.0, 0.0),
              (0.8944271909999159, -0.44721359549995804, 0.0), (1.0, 0.0, 0.0)]
    for v, r in zip(e.tangents(params), result):
        assert v.isclose(r)
def test_vertices():
    e = ConstructionEllipse(center=(3, 3), major_axis=(2, 0), ratio=0.5, start_param=0, end_param=math.pi * 1.5)
    params = list(e.params(7))
    result = [
        (5.0, 3.0, 0.0),
        (4.414213562373095, 3.7071067811865475, 0.0),
        (3.0, 4.0, 0.0),
        (1.585786437626905, 3.7071067811865475, 0.0),
        (1.0, 3.0, 0.0),
        (1.5857864376269046, 2.2928932188134525, 0.0),
        (3.0, 2.0, 0.0),
    ]
    for v, r in zip(e.vertices(params), result):
        assert v.isclose(r)

    v1, v2 = e.vertices([0, math.tau])
    assert v1 == v2
예제 #3
0
        def to_line_edges(edge):
            # Start- and end params are always stored in counter clockwise order!
            ellipse = ConstructionEllipse(
                center=edge.center,
                major_axis=edge.major_axis,
                ratio=edge.ratio,
                start_param=edge.start_param,
                end_param=edge.end_param,
            )
            segment_count = max(
                int(float(num) * ellipse.param_span / math.tau), 3
            )
            params = ellipse.params(segment_count + 1)

            # Reverse path if necessary!
            if not edge.ccw:
                params = reversed(list(params))
            vertices = list(ellipse.vertices(params))
            for v1, v2 in zip(vertices[:-1], vertices[1:]):
                line = LineEdge()
                line.start = v1.vec2
                line.end = v2.vec2
                yield line
예제 #4
0
def test_params():
    count = 9
    e = ConstructionEllipse(start_param=math.pi / 2, end_param=-math.pi / 2)
    params = list(e.params(count))
    expected = list(linspace(math.pi / 2, math.pi / 2.0 * 3.0, count))
    assert params == expected