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_distance_segment(points1, points2, expected_distance): segment1 = Segment(*points1) segment2 = Segment(*points2) seg = segment1.shortest_segment(segment2) assert seg.seglen == pytest.approx(expected_distance)
def test_intersect(points1, points2, expected_intersect_point, intersect_type): segment1 = Segment(*points1) segment2 = Segment(*points2) intersection = segment1.intersect(segment2) assert intersection.intersect_point == expected_intersect_point assert intersection.intersect_type == intersect_type
def test_overlap(points1, points2, expected_points): segment1 = Segment(*points1) segment2 = Segment(*points2) if expected_points is None: assert segment1.overlap(segment2) == expected_points else: assert segment1.overlap(segment2) == Segment(*expected_points)
def test_angle(points1, points2, expected_angle): segment1 = Segment(*points1) segment2 = Segment(*points2) assert segment1.angle(segment2) == pytest.approx(expected_angle)
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)
def test_segment_point(t, expected_point): segment = Segment(Point([1, 1]), Point([2, 2])) assert segment.point(t) == expected_point
def test_reverse(): segment = Segment(Point([1, 1]), Point([2, 2])) assert segment.reverse() == Segment(Point([2, 2]), Point([1, 1]))
def test_to_curve(): segment = Segment(Point([1, 1]), Point([2, 2])) assert segment.to_curve() == Curve([(1, 2), (1, 2)])
def test_distance_point(segment_points, point, expected_distance): segment = Segment(*segment_points) assert segment.distance(point) == pytest.approx(expected_distance)
def test_singular(): segment = Segment(Point([1, 1]), Point([1, 1])) assert segment.singular
def test_coplanar(points1, points2, expected_flag): segment1 = Segment(*points1) segment2 = Segment(*points2) assert segment1.coplanar(segment2) == expected_flag
def test_parallel(points1, points2, expected_flag): segment1 = Segment(*points1) segment2 = Segment(*points2) assert segment1.parallel(segment2) == expected_flag
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_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))
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])),