示例#1
0
def test_from_points():
    """Tests creating the instance of 'Curve' class from points
    """
    points = [
        Point([1, 5, 9]),
        Point([2, 6, 10]),
        Point([3, 7, 11]),
        Point([4, 8, 12]),
    ]

    points_array = np.array(points)
    curve = Curve(points_array, axis=0)

    assert curve.size == 4
    assert curve.ndim == 3
    assert curve.data == pytest.approx(points_array)
示例#2
0
def test_construct(data, ndim, dtype):
    """Tests creating the instance of 'Curve' class
    """
    point = Point(data, dtype=dtype)

    assert len(point) == ndim
    assert point.ndim == ndim
    assert point.dtype == dtype
示例#3
0
def test_intersect_curves_almost():
    curve1 = curves.helix(t_start=-np.pi, t_stop=np.pi * 3, p_count=100)
    curve2 = curves.helix(t_start=-np.pi,
                          t_stop=np.pi * 3,
                          a=-1,
                          b=-1,
                          p_count=100)

    intersections = curve1.intersect(curve2, method='almost', dist_tol=0.01)

    assert len(intersections) == 2

    expected_intersect_points = [
        Point([-0.9986155794073, -0.0000159984365, -1.5708163062868]),
        Point([0.9986155794073, 0.0000159984365, 1.5708163062868]),
    ]

    for intersection, expected_point in zip(intersections,
                                            expected_intersect_points):
        assert intersection.intersect_point == expected_point
示例#4
0
def test_equal_segments():
    segment1 = Segment(Point([1, 1]), Point([2, 2]))
    segment2 = Segment(Point([1, 1]), Point([2, 2]))
    segment3 = Segment(Point([2, 2]), Point([1, 1]))

    assert segment1 == segment2
    assert segment1 != segment3
示例#5
0
def test_insert_point():
    curve = Curve([(1, 2, 3, 4), (5, 6, 7, 8)])
    point = Point([10, 20])

    curve1 = curve.insert(1, point)
    assert curve1 == Curve([(1, 10, 2, 3, 4), (5, 20, 6, 7, 8)])
示例#6
0
def test_getitem_point(index, expected_data):
    curve = Curve([(1, 2, 3, 4), (5, 6, 7, 8)])
    assert curve[index] == Point(expected_data)
示例#7
0
def test_segment_point(t, expected_point):
    segment = Segment(Point([1, 1]), Point([2, 2]))
    assert segment.point(t) == expected_point
示例#8
0
def test_to_curve():
    segment = Segment(Point([1, 1]), Point([2, 2]))
    assert segment.to_curve() == Curve([(1, 2), (1, 2)])
示例#9
0
# -*- coding: utf-8 -*-

import pytest
import numpy as np

from skcurve import Point, Segment, Curve, GeometryAlgorithmsWarning, IntersectionType


@pytest.mark.parametrize('p1, p2, ndim', [
    (Point([1, 1]), Point([2, 2]), 2),
    (Point([1, 1, 1]), Point([2, 2, 2]), 3),
])
def test_create_segment(p1, p2, ndim):
    segment = Segment(p1, p2)
    assert segment.ndim == ndim
    assert segment.p1 == p1
    assert segment.p2 == p2


def test_equal_segments():
    segment1 = Segment(Point([1, 1]), Point([2, 2]))
    segment2 = Segment(Point([1, 1]), Point([2, 2]))
    segment3 = Segment(Point([2, 2]), Point([1, 1]))

    assert segment1 == segment2
    assert segment1 != segment3


def test_singular():
    segment = Segment(Point([1, 1]), Point([1, 1]))
    assert segment.singular
示例#10
0
def test_dot_product():
    p1 = Point([3, 7])
    p2 = Point([-1, 4])

    assert p1 @ p2 == pytest.approx(25)
    assert p2 @ p1 == pytest.approx(25)
示例#11
0
def test_get_item(index, expected_data):
    point = Point([1, 2, 3, 4])
    assert point[index] == expected_data
示例#12
0
def test_ne(point_data):
    p1 = Point([1, 2, 3, 4])
    p2 = Point(point_data)
    assert p1 != p2
示例#13
0
def test_eq_integer():
    p1 = Point([1, 2], dtype=int)
    p2 = Point([1, 2], dtype=int)
    assert p1 == p2
示例#14
0
def test_eq():
    p1 = Point([1, 2])
    p2 = Point([1, 2])
    assert p1 == p2
示例#15
0
@pytest.mark.parametrize('point_data', [
    [1, 2, 3],
    [2, 3, 4, 5],
])
def test_ne(point_data):
    p1 = Point([1, 2, 3, 4])
    p2 = Point(point_data)
    assert p1 != p2


@pytest.mark.parametrize('index, expected_data', [
    (0, 1),
    (1, 2),
    (-1, 4),
    (-2, 3),
    (slice(0, 2), Point([1, 2])),
    ([1, 3], Point([2, 4])),
])
def test_get_item(index, expected_data):
    point = Point([1, 2, 3, 4])
    assert point[index] == expected_data


def test_dot_product():
    p1 = Point([3, 7])
    p2 = Point([-1, 4])

    assert p1 @ p2 == pytest.approx(25)
    assert p2 @ p1 == pytest.approx(25)

示例#16
0
def test_append_point():
    curve = Curve([(1, 2, 3, 4), (5, 6, 7, 8)])
    point = Point([10, 20])

    curve1 = curve.append(point)
    assert curve1 == Curve([(1, 2, 3, 4, 10), (5, 6, 7, 8, 20)])
示例#17
0
def test_distance():
    p1 = Point([3, 7])
    p2 = Point([-1, 4])

    assert p1.distance(p2) == pytest.approx(5.0)
    assert p1.distance(p2, metric='sqeuclidean', w=1.5) == pytest.approx(37.5)
示例#18
0
    [[1, 2], [5, 6]],
    [[2], [6]],
    [[2, 3], [6, 7]],
    [[1, 2, 3], [5, 6, 7]],
    [[2, 3, 4], [6, 7, 8]],
    [[3, 4], [7, 8]],
    [[1, 2, 3, 4], [5, 6, 7, 8]],
])
def test_contains_curve(curve_data):
    curve = Curve([(1, 2, 3, 4), (5, 6, 7, 8)])
    assert Curve(curve_data) in curve


@pytest.mark.parametrize('data', [
    10,
    Point([10, 20]),
    Curve([[10, 20], [30, 40]]),
])
def test_not_contains(data):
    curve = Curve([(1, 2, 3, 4), (5, 6, 7, 8)])
    assert data not in curve


@pytest.mark.parametrize('point_data, start, stop, expected_index', [
    ([1, 5], None, None, 0),
    ([3, 7], 1, None, 2),
    ([2, 6], None, None, 1),
    ([2, 6], 2, None, 4),
    ([4, 8], None, 4, 3),
])
def test_index(point_data, start, stop, expected_index):
示例#19
0
def test_angle_nan():
    segment1 = Segment(Point([1, 1]), Point([1, 2]))
    segment2 = Segment(Point([0, 0]), Point([0, 0]))

    with pytest.warns(GeometryAlgorithmsWarning):
        assert np.isnan(segment1.angle(segment2))
示例#20
0
def test_contains_point(point_data):
    curve = Curve([(1, 2, 3, 4), (5, 6, 7, 8)])
    assert Point(point_data) in curve
示例#21
0
def test_singular():
    segment = Segment(Point([1, 1]), Point([1, 1]))
    assert segment.singular
示例#22
0
def test_index(point_data, start, stop, expected_index):
    curve = Curve([(1, 2, 3, 4, 2), (5, 6, 7, 8, 6)])
    assert curve.index(Point(point_data), start, stop) == expected_index
示例#23
0
def test_reverse():
    segment = Segment(Point([1, 1]), Point([2, 2]))
    assert segment.reverse() == Segment(Point([2, 2]), Point([1, 1]))
示例#24
0
def test_count(point_data, expected_count):
    curve = Curve([(1, 2, 3, 4, 2, 3, 2), (5, 6, 7, 8, 6, 7, 6)])
    assert curve.count(Point(point_data)) == expected_count
示例#25
0
def test_segment_t_3d(point, expected_t):
    segment = Segment(Point([1, 1, 1]), Point([2, 2, 2]))
    assert segment.t(point) == pytest.approx(expected_t)
示例#26
0
import numpy as np

from skcurve import Point, Segment, Curve, CurveSegment, curves

skip = functools.partial(pytest.param, marks=pytest.mark.skip)


@pytest.mark.parametrize(
    'segment1, segment2, intersect_point',
    [
        # ----------------------
        # 2D

        # intersected
        (Segment(Point([1, 1]), Point([2, 2])),
         Segment(Point([1, 2]), Point([2, 1])), Point([1.5, 1.5])),
        # intersected perpendicular
        (Segment(Point([0, 0]), Point(
            [0, 2])), Segment(Point([-1, 1]), Point([1, 1])), Point([0, 1])),
        # not intersected parallel
        (Segment(Point([1, 2]), Point(
            [2, 2])), Segment(Point([1, 1]), Point([2, 1])), None),
        # not intersected collinear
        (Segment(Point([0, 0]), Point(
            [1, 1])), Segment(Point([1.1, 1.1]), Point([2, 2])), None),
        # overlapped #1
        (Segment(Point([1, 1]), Point([2, 2])),
         Segment(Point([0.5, 0.5]), Point([1.5, 1.5])), Point([1.25, 1.25])),
        # overlapped #2
        (Segment(Point([1, 1]), Point([2, 2])),