Coverage for geometry/tests/test_intersection.py: 100%
25 statements
« prev ^ index » next coverage.py v7.11.0, created at 2025-11-16 22:49 +1300
« prev ^ index » next coverage.py v7.11.0, created at 2025-11-16 22:49 +1300
1"""Define the unit tests for the :mod:`colour.geometry.intersection` module."""
3from __future__ import annotations
5import numpy as np
7from colour.constants import TOLERANCE_ABSOLUTE_TESTS
8from colour.geometry import extend_line_segment, intersect_line_segments
10__author__ = "Colour Developers"
11__copyright__ = "Copyright 2013 Colour Developers"
12__license__ = "BSD-3-Clause - https://opensource.org/licenses/BSD-3-Clause"
13__maintainer__ = "Colour Developers"
14__email__ = "colour-developers@colour-science.org"
15__status__ = "Production"
17__all__ = [
18 "TestExtendLineSegment",
19 "TestIntersectLineSegments",
20]
23class TestExtendLineSegment:
24 """
25 Define :func:`colour.geometry.intersection.extend_line_segment` definition unit
26 tests methods.
27 """
29 def test_extend_line_segment(self) -> None:
30 """Test :func:`colour.geometry.intersection.extend_line_segment` definition."""
32 np.testing.assert_allclose(
33 extend_line_segment(
34 np.array([0.95694934, 0.13720932]),
35 np.array([0.28382835, 0.60608318]),
36 ),
37 np.array([-0.5367248, 1.17765341]),
38 atol=TOLERANCE_ABSOLUTE_TESTS,
39 )
41 np.testing.assert_allclose(
42 extend_line_segment(
43 np.array([0.95694934, 0.13720932]),
44 np.array([0.28382835, 0.60608318]),
45 5,
46 ),
47 np.array([-3.81893739, 3.46393435]),
48 atol=TOLERANCE_ABSOLUTE_TESTS,
49 )
51 np.testing.assert_allclose(
52 extend_line_segment(
53 np.array([0.95694934, 0.13720932]),
54 np.array([0.28382835, 0.60608318]),
55 -1,
56 ),
57 np.array([1.1043815, 0.03451295]),
58 atol=TOLERANCE_ABSOLUTE_TESTS,
59 )
62class TestIntersectLineSegments:
63 """
64 Define :func:`colour.geometry.intersection.intersect_line_segments`
65 definition unit tests methods.
66 """
68 def test_intersect_line_segments(self) -> None:
69 """
70 Test :func:`colour.geometry.intersection.intersect_line_segments`
71 definition.
72 """
74 l_1 = np.array(
75 [
76 [[0.15416284, 0.7400497], [0.26331502, 0.53373939]],
77 [[0.01457496, 0.91874701], [0.90071485, 0.03342143]],
78 ]
79 )
80 l_2 = np.array(
81 [
82 [[0.95694934, 0.13720932], [0.28382835, 0.60608318]],
83 [[0.94422514, 0.85273554], [0.00225923, 0.52122603]],
84 [[0.55203763, 0.48537741], [0.76813415, 0.16071675]],
85 [[0.01457496, 0.91874701], [0.90071485, 0.03342143]],
86 ]
87 )
89 s = intersect_line_segments(l_1, l_2)
91 np.testing.assert_allclose(
92 s.xy,
93 np.array(
94 [
95 [
96 [np.nan, np.nan],
97 [0.22791841, 0.60064309],
98 [np.nan, np.nan],
99 [np.nan, np.nan],
100 ],
101 [
102 [0.42814517, 0.50555685],
103 [0.30560559, 0.62798382],
104 [0.7578749, 0.17613012],
105 [np.nan, np.nan],
106 ],
107 ]
108 ),
109 atol=TOLERANCE_ABSOLUTE_TESTS,
110 )
112 np.testing.assert_array_equal(
113 s.intersect,
114 np.array([[False, True, False, False], [True, True, True, False]]),
115 )
117 np.testing.assert_array_equal(
118 s.parallel,
119 np.array([[False, False, False, False], [False, False, False, True]]),
120 )
122 np.testing.assert_array_equal(
123 s.coincident,
124 np.array([[False, False, False, False], [False, False, False, True]]),
125 )