示例#1
0
def test_line_collection_extend(lines):
    lc = LineCollection([(3, 3j)])
    lc.extend(lines)
    assert len(lc) == 3
    assert np.all(lc[0] == np.array([3, 3j]))
    assert np.all(lc[1] == np.array([0, 1 + 1j]))
    assert np.all(lc[2] == np.array([2 + 2j, 3 + 3j, 4 + 4j]))
示例#2
0
def test_find_nearest_within_reverse():
    lines = [[10, 0], [20, 10.1]]
    idx = LineIndex(LineCollection(lines))
    ridx = LineIndex(LineCollection(lines), reverse=True)

    assert idx.find_nearest_within(0.1, 0.5)[0] is None
    assert ridx.find_nearest_within(0.1, 0.5) == (0, True)
    assert ridx.find_nearest_within(10.01, 0.5) == (0, False)
    assert ridx.find_nearest_within(10.09, 0.5) == (1, True)
示例#3
0
def test_vector_data_lid_iteration():
    lc = LineCollection([(0, 1 + 1j)])
    vd = VectorData()
    vd.add(lc, 1)

    for lc in vd.layers_from_ids([1, 2, 3, 4]):
        lc.append([3, 3 + 3j])

    assert vd.count() == 1
    assert len(vd.layers[1]) == 2
示例#4
0
def test_pop_front():
    lines = [random_line(5), random_line(3), random_line(7)]
    lc = LineCollection(lines)
    idx = LineIndex(lc)

    assert np.all(idx.pop_front() == lines[0])
    assert np.all(idx.pop_front() == lines[1])
    assert np.all(idx.pop_front() == lines[2])
    assert len(idx) == 0
示例#5
0
def test_find_nearest_within():
    lines = [[1 + 1j, 10], [1.2 + 1j, 10], [1.3 + 1j, 10]]
    idx = LineIndex(LineCollection(lines))

    assert idx.find_nearest_within(1.05 + 1j, 0.01)[0] is None
    assert idx.find_nearest_within(1.05 + 1j, 0.051) == (0, False)
    assert idx.find_nearest_within(1.05 + 1j, 0.16) == (0, False)
    idx.pop(0)
    assert idx.find_nearest_within(1.05 + 1j, 0.16) == (1, False)
    assert idx.find_nearest_within(1.05 + 1j, 0.051)[0] is None
示例#6
0
def test_pop():
    lines = [random_line(5), random_line(3), random_line(7)]
    lc = LineCollection(lines)
    idx = LineIndex(lc)

    assert np.all(idx.pop(2) == lines[2])
    assert idx.pop(2) is None
    assert np.all(idx.pop(0) == lines[0])
    assert idx.pop(0) is None
    assert np.all(idx.pop(1) == lines[1])
    assert len(idx) == 0
示例#7
0
def test_vector_data_bounds():
    vd = VectorData()
    vd.add(LineCollection([(-10, 10), (0, 0)]), 1)
    vd.add(LineCollection([(0, 0), (-10j, 10j)]), 2)
    assert vd.bounds() == (-10, -10, 10, 10)
示例#8
0
def test_line_collection_pen_up_length():
    lc = LineCollection([(0, 10), (10 + 10j, 500 + 500j, 10j), (0, -40)])
    assert lc.pen_up_length()[0] == 20.0
示例#9
0
def test_line_collection_empty_bounds():
    lc = LineCollection()
    assert lc.bounds() is None
示例#10
0
def test_line_collection_bounds():
    lc = LineCollection([(-10, 10), (-10j, 10j)])
    assert lc.bounds() == (-10, -10, 10, 10)
示例#11
0
def test_line_collection_append(line):
    lc = LineCollection()
    lc.append(line)
    assert len(lc) == 1
    assert np.all(lc[0] == np.array([4 + 3j, 5, 10 + 10j, 5j]))
示例#12
0
def test_line_collection_creation(lines):
    lc = LineCollection(lines)
    assert len(lc) == 2
    assert np.all(lc[0] == np.array([0, 1 + 1j]))
    assert np.all(lc[1] == np.array([2 + 2j, 3 + 3j, 4 + 4j]))
示例#13
0
import pytest
import numpy as np
from shapely.geometry import MultiLineString, LineString

from vpype.model import LineCollection, VectorData

LINE_COLLECTION_INIT = [
    LineCollection([[0, 1 + 1j], [2 + 2j, 3 + 3j, 4 + 4j]]),
    [[0, 1 + 1j], [2 + 2j, 3 + 3j, 4 + 4j]],
    ([0, 1 + 1j], [2 + 2j, 3 + 3j, 4 + 4j]),
    ((0, 1 + 1j), (2 + 2j, 3 + 3j, 4 + 4j)),
    np.array([[0, 1 + 1j], [2 + 2j, 3 + 3j, 4 + 4j]]),
    MultiLineString([[(0, 0), (1, 1)], [(2, 2), (3, 3), (4, 4)]]),
]


@pytest.mark.parametrize("lines", LINE_COLLECTION_INIT)
def test_line_collection_creation(lines):
    lc = LineCollection(lines)
    assert len(lc) == 2
    assert np.all(lc[0] == np.array([0, 1 + 1j]))
    assert np.all(lc[1] == np.array([2 + 2j, 3 + 3j, 4 + 4j]))


@pytest.mark.parametrize("lines", LINE_COLLECTION_INIT)
def test_line_collection_extend(lines):
    lc = LineCollection([(3, 3j)])
    lc.extend(lines)
    assert len(lc) == 3
    assert np.all(lc[0] == np.array([3, 3j]))
    assert np.all(lc[1] == np.array([0, 1 + 1j]))