Coverage for colour/geometry/tests/test_ellipse.py: 100%
26 statements
« prev ^ index » next coverage.py v7.11.0, created at 2025-11-15 19:01 +1300
« prev ^ index » next coverage.py v7.11.0, created at 2025-11-15 19:01 +1300
1"""Define the unit tests for the :mod:`colour.geometry.ellipse` module."""
3from __future__ import annotations
5import numpy as np
7from colour.constants import TOLERANCE_ABSOLUTE_TESTS
8from colour.geometry import (
9 ellipse_coefficients_canonical_form,
10 ellipse_coefficients_general_form,
11 ellipse_fitting_Halir1998,
12 point_at_angle_on_ellipse,
13)
15__author__ = "Colour Developers"
16__copyright__ = "Copyright 2013 Colour Developers"
17__license__ = "BSD-3-Clause - https://opensource.org/licenses/BSD-3-Clause"
18__maintainer__ = "Colour Developers"
19__email__ = "colour-developers@colour-science.org"
20__status__ = "Production"
22__all__ = [
23 "TestEllipseCoefficientsCanonicalForm",
24 "TestEllipseCoefficientsGeneralForm",
25 "TestPointAtAngleOnEllipse",
26 "TestEllipseFittingHalir1998",
27]
30class TestEllipseCoefficientsCanonicalForm:
31 """
32 Define :func:`colour.geometry.ellipse.ellipse_coefficients_canonical_form`
33 definition unit tests methods.
34 """
36 def test_ellipse_coefficients_canonical_form(self) -> None:
37 """
38 Test :func:`colour.geometry.ellipse.\
39ellipse_coefficients_canonical_form` definition.
40 """
42 np.testing.assert_allclose(
43 ellipse_coefficients_canonical_form(
44 np.array([2.5, -3.0, 2.5, -1.0, -1.0, -3.5])
45 ),
46 np.array([0.5, 0.5, 2, 1, 45]),
47 atol=TOLERANCE_ABSOLUTE_TESTS,
48 )
50 np.testing.assert_allclose(
51 ellipse_coefficients_canonical_form(
52 np.array([1.0, 0.0, 1.0, 0.0, 0.0, -1.0])
53 ),
54 np.array([0.0, 0.0, 1, 1, 0]),
55 atol=TOLERANCE_ABSOLUTE_TESTS,
56 )
59class TestEllipseCoefficientsGeneralForm:
60 """
61 Define :func:`colour.geometry.ellipse.ellipse_coefficients_general_form`
62 definition unit tests methods.
63 """
65 def test_ellipse_coefficients_general_form(self) -> None:
66 """
67 Test :func:`colour.geometry.ellipse.ellipse_coefficients_general_form`
68 definition.
69 """
71 np.testing.assert_allclose(
72 ellipse_coefficients_general_form(np.array([0.5, 0.5, 2, 1, 45])),
73 np.array([2.5, -3.0, 2.5, -1.0, -1.0, -3.5]),
74 atol=TOLERANCE_ABSOLUTE_TESTS,
75 )
77 np.testing.assert_allclose(
78 ellipse_coefficients_general_form(np.array([0.0, 0.0, 1, 1, 0])),
79 np.array([1.0, 0.0, 1.0, 0.0, 0.0, -1.0]),
80 atol=TOLERANCE_ABSOLUTE_TESTS,
81 )
84class TestPointAtAngleOnEllipse:
85 """
86 Define :func:`colour.geometry.ellipse.point_at_angle_on_ellipse`
87 definition unit tests methods.
88 """
90 def test_point_at_angle_on_ellipse(self) -> None:
91 """
92 Test :func:`colour.geometry.ellipse.point_at_angle_on_ellipse`
93 definition.
94 """
96 np.testing.assert_allclose(
97 point_at_angle_on_ellipse(
98 np.array([0, 90, 180, 270]), np.array([0.0, 0.0, 2, 1, 0])
99 ),
100 np.array([[2, 0], [0, 1], [-2, 0], [0, -1]]),
101 atol=TOLERANCE_ABSOLUTE_TESTS,
102 )
104 np.testing.assert_allclose(
105 point_at_angle_on_ellipse(
106 np.linspace(0, 360, 10), np.array([0.5, 0.5, 2, 1, 45])
107 ),
108 np.array(
109 [
110 [1.91421356, 1.91421356],
111 [1.12883096, 2.03786992],
112 [0.04921137, 1.44193985],
113 [-0.81947922, 0.40526565],
114 [-1.07077081, -0.58708129],
115 [-0.58708129, -1.07077081],
116 [0.40526565, -0.81947922],
117 [1.44193985, 0.04921137],
118 [2.03786992, 1.12883096],
119 [1.91421356, 1.91421356],
120 ]
121 ),
122 atol=TOLERANCE_ABSOLUTE_TESTS,
123 )
126class TestEllipseFittingHalir1998:
127 """
128 Define :func:`colour.geometry.ellipse.ellipse_fitting_Halir1998`
129 definition unit tests methods.
130 """
132 def test_ellipse_fitting_Halir1998(self) -> None:
133 """
134 Test :func:`colour.geometry.ellipse.ellipse_fitting_Halir1998`
135 definition.
136 """
138 np.testing.assert_allclose(
139 ellipse_fitting_Halir1998(np.array([[2, 0], [0, 1], [-2, 0], [0, -1]])),
140 np.array(
141 [
142 0.24253563,
143 0.00000000,
144 0.97014250,
145 0.00000000,
146 0.00000000,
147 -0.97014250,
148 ]
149 ),
150 atol=TOLERANCE_ABSOLUTE_TESTS,
151 )