コード例 #1
0
ファイル: test_curve.py プロジェクト: espdev/scikit-curve
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
ファイル: test_point.py プロジェクト: espdev/scikit-curve
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
ファイル: test_intersect.py プロジェクト: espdev/scikit-curve
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
ファイル: test_curve.py プロジェクト: espdev/scikit-curve
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
ファイル: test_curve.py プロジェクト: espdev/scikit-curve
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
ファイル: test_point.py プロジェクト: espdev/scikit-curve
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
ファイル: test_point.py プロジェクト: espdev/scikit-curve
def test_get_item(index, expected_data):
    point = Point([1, 2, 3, 4])
    assert point[index] == expected_data
コード例 #12
0
ファイル: test_point.py プロジェクト: espdev/scikit-curve
def test_ne(point_data):
    p1 = Point([1, 2, 3, 4])
    p2 = Point(point_data)
    assert p1 != p2
コード例 #13
0
ファイル: test_point.py プロジェクト: espdev/scikit-curve
def test_eq_integer():
    p1 = Point([1, 2], dtype=int)
    p2 = Point([1, 2], dtype=int)
    assert p1 == p2
コード例 #14
0
ファイル: test_point.py プロジェクト: espdev/scikit-curve
def test_eq():
    p1 = Point([1, 2])
    p2 = Point([1, 2])
    assert p1 == p2
コード例 #15
0
ファイル: test_point.py プロジェクト: espdev/scikit-curve
@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
ファイル: test_curve.py プロジェクト: espdev/scikit-curve
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
ファイル: test_point.py プロジェクト: espdev/scikit-curve
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
ファイル: test_curve.py プロジェクト: espdev/scikit-curve
    [[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
ファイル: test_curve.py プロジェクト: espdev/scikit-curve
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
ファイル: test_curve.py プロジェクト: espdev/scikit-curve
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
ファイル: test_curve.py プロジェクト: espdev/scikit-curve
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
ファイル: test_intersect.py プロジェクト: espdev/scikit-curve
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])),