Coverage for geometry/tests/test_intersection.py: 100%

1"""Define the unit tests for the :mod:`colour.geometry.intersection` module."""

2

3 from __future__ import annotations

4

5 import numpy as np

6

7 from colour.constants import TOLERANCE_ABSOLUTE_TESTS

8 from colour.geometry import extend_line_segment, intersect_line_segments

9

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"

16

17 __all__ = [

18 "TestExtendLineSegment",

19 "TestIntersectLineSegments",

20]

21

22

23 class TestExtendLineSegment:

24 """

25 Define :func:`colour.geometry.intersection.extend_line_segment` definition unit

26 tests methods.

27 """

28

29 def test_extend_line_segment(self) -> None:

30 """Test :func:`colour.geometry.intersection.extend_line_segment` definition."""

31

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 )

40

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 )

50

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 )

60

61

62 class TestIntersectLineSegments:

63 """

64 Define :func:`colour.geometry.intersection.intersect_line_segments`

65 definition unit tests methods.

66 """

67

68 def test_intersect_line_segments(self) -> None:

69 """

70 Test :func:`colour.geometry.intersection.intersect_line_segments`

71 definition.

72 """

73

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 )

88

89 s = intersect_line_segments(l_1, l_2)

90

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 )

111

112 np.testing.assert_array_equal(

113 s.intersect,

114 np.array([[False, True, False, False], [True, True, True, False]]),

115 )

116

117 np.testing.assert_array_equal(

118 s.parallel,

119 np.array([[False, False, False, False], [False, False, False, True]]),

120 )

121

122 np.testing.assert_array_equal(

123 s.coincident,

124 np.array([[False, False, False, False], [False, False, False, True]]),

125 )