open-space-toolkit-mathematics 4.6.0__py39-none-manylinux2014_aarch64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- open_space_toolkit_mathematics-4.6.0.dist-info/METADATA +28 -0
- open_space_toolkit_mathematics-4.6.0.dist-info/RECORD +68 -0
- open_space_toolkit_mathematics-4.6.0.dist-info/WHEEL +5 -0
- open_space_toolkit_mathematics-4.6.0.dist-info/top_level.txt +1 -0
- open_space_toolkit_mathematics-4.6.0.dist-info/zip-safe +1 -0
- ostk/__init__.py +1 -0
- ostk/mathematics/OpenSpaceToolkitMathematicsPy.cpython-39-aarch64-linux-gnu.so +0 -0
- ostk/mathematics/__init__.py +5 -0
- ostk/mathematics/__init__.pyi +11 -0
- ostk/mathematics/curve_fitting/__init__.pyi +155 -0
- ostk/mathematics/curve_fitting/interpolator.pyi +243 -0
- ostk/mathematics/geometry/__init__.pyi +504 -0
- ostk/mathematics/geometry/d2/__init__.pyi +809 -0
- ostk/mathematics/geometry/d2/object.pyi +1779 -0
- ostk/mathematics/geometry/d3/__init__.pyi +1032 -0
- ostk/mathematics/geometry/d3/object.pyi +3709 -0
- ostk/mathematics/geometry/d3/transformation/__init__.pyi +3 -0
- ostk/mathematics/geometry/d3/transformation/rotation.pyi +1358 -0
- ostk/mathematics/libopen-space-toolkit-mathematics.so.4 +0 -0
- ostk/mathematics/object.pyi +387 -0
- ostk/mathematics/solver.pyi +342 -0
- ostk/mathematics/test/__init__.py +1 -0
- ostk/mathematics/test/curve_fitting/__init__.py +1 -0
- ostk/mathematics/test/curve_fitting/interpolator/__init__.py +1 -0
- ostk/mathematics/test/curve_fitting/interpolator/test_barycentric_rational.py +44 -0
- ostk/mathematics/test/curve_fitting/interpolator/test_cubic_spline.py +55 -0
- ostk/mathematics/test/curve_fitting/interpolator/test_interpolator.py +71 -0
- ostk/mathematics/test/curve_fitting/interpolator/test_linear.py +45 -0
- ostk/mathematics/test/geometry/__init__.py +1 -0
- ostk/mathematics/test/geometry/d2/__init__.py +1 -0
- ostk/mathematics/test/geometry/d2/conftest.py +79 -0
- ostk/mathematics/test/geometry/d2/object/__init__.py +1 -0
- ostk/mathematics/test/geometry/d2/object/test_composite.py +93 -0
- ostk/mathematics/test/geometry/d2/object/test_line.py +57 -0
- ostk/mathematics/test/geometry/d2/object/test_linestring.py +174 -0
- ostk/mathematics/test/geometry/d2/object/test_multipolygon.py +94 -0
- ostk/mathematics/test/geometry/d2/object/test_point.py +213 -0
- ostk/mathematics/test/geometry/d2/object/test_point_set.py +100 -0
- ostk/mathematics/test/geometry/d2/object/test_polygon.py +370 -0
- ostk/mathematics/test/geometry/d2/object/test_segment.py +104 -0
- ostk/mathematics/test/geometry/d2/test_object.py +25 -0
- ostk/mathematics/test/geometry/d2/test_transformation.py +84 -0
- ostk/mathematics/test/geometry/d3/__init__.py +1 -0
- ostk/mathematics/test/geometry/d3/object/__init__.py +1 -0
- ostk/mathematics/test/geometry/d3/object/test_composite.py +262 -0
- ostk/mathematics/test/geometry/d3/object/test_cuboid.py +20 -0
- ostk/mathematics/test/geometry/d3/object/test_line.py +68 -0
- ostk/mathematics/test/geometry/d3/object/test_linestring.py +168 -0
- ostk/mathematics/test/geometry/d3/object/test_point.py +234 -0
- ostk/mathematics/test/geometry/d3/object/test_point_set.py +113 -0
- ostk/mathematics/test/geometry/d3/object/test_polygon.py +141 -0
- ostk/mathematics/test/geometry/d3/object/test_segment.py +120 -0
- ostk/mathematics/test/geometry/d3/objects/test_cuboid.py +20 -0
- ostk/mathematics/test/geometry/d3/test_intersection.py +3 -0
- ostk/mathematics/test/geometry/d3/test_object.py +3 -0
- ostk/mathematics/test/geometry/d3/test_transformation.py +3 -0
- ostk/mathematics/test/geometry/d3/transformation/__init__.py +1 -0
- ostk/mathematics/test/geometry/d3/transformation/rotation/__init__.py +1 -0
- ostk/mathematics/test/geometry/d3/transformation/rotation/test_euler_angle.py +138 -0
- ostk/mathematics/test/geometry/d3/transformation/rotation/test_quaternion.py +189 -0
- ostk/mathematics/test/geometry/d3/transformation/rotation/test_rotation_matrix.py +40 -0
- ostk/mathematics/test/geometry/d3/transformation/rotation/test_rotation_vector.py +47 -0
- ostk/mathematics/test/geometry/test_angle.py +345 -0
- ostk/mathematics/test/object/__init__.py +1 -0
- ostk/mathematics/test/object/test_interval.py +515 -0
- ostk/mathematics/test/object/test_vector.py +5 -0
- ostk/mathematics/test/solver/test_numerical_solver.py +176 -0
- ostk/mathematics/test/test_object.py +24 -0
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
# Apache License 2.0
|
|
2
|
+
|
|
3
|
+
import pytest
|
|
4
|
+
|
|
5
|
+
import math
|
|
6
|
+
|
|
7
|
+
import numpy as np
|
|
8
|
+
|
|
9
|
+
import ostk.mathematics as mathematics
|
|
10
|
+
|
|
11
|
+
Object = mathematics.geometry.d3.Object
|
|
12
|
+
Point = mathematics.geometry.d3.object.Point
|
|
13
|
+
Transformation = mathematics.geometry.d3.Transformation
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def test_geometry_d3_object_point_constructor():
|
|
17
|
+
point: Point = Point(1.0, 2.0, 3.0)
|
|
18
|
+
|
|
19
|
+
assert point is not None
|
|
20
|
+
assert isinstance(point, Point)
|
|
21
|
+
assert isinstance(point, Object)
|
|
22
|
+
assert point.is_defined()
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def test_geometry_d3_object_point_undefined():
|
|
26
|
+
point: Point = Point.undefined()
|
|
27
|
+
|
|
28
|
+
assert point is not None
|
|
29
|
+
assert isinstance(point, Point)
|
|
30
|
+
assert isinstance(point, Object)
|
|
31
|
+
assert point.is_defined() is False
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def test_geometry_d3_object_point_origin():
|
|
35
|
+
point: Point = Point.origin()
|
|
36
|
+
|
|
37
|
+
assert point is not None
|
|
38
|
+
assert isinstance(point, Point)
|
|
39
|
+
assert isinstance(point, Object)
|
|
40
|
+
assert point.is_defined()
|
|
41
|
+
assert point.x() == 0.0
|
|
42
|
+
assert point.y() == 0.0
|
|
43
|
+
assert point.z() == 0.0
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def test_geometry_d3_object_point_vector():
|
|
47
|
+
# Construction using a python list
|
|
48
|
+
point: Point = Point.vector([3.4, -6.7, 1.0])
|
|
49
|
+
|
|
50
|
+
assert point is not None
|
|
51
|
+
assert isinstance(point, Point)
|
|
52
|
+
assert isinstance(point, Object)
|
|
53
|
+
assert point.is_defined()
|
|
54
|
+
assert (point.x() - 3.4) <= 1e-15
|
|
55
|
+
assert (point.y() + 6.7) <= 1e-15
|
|
56
|
+
assert (point.z() - 1.0) <= 1e-15
|
|
57
|
+
|
|
58
|
+
# Construction using a python tuple
|
|
59
|
+
point: Point = Point.vector((3.4, -6.7, 1.0))
|
|
60
|
+
|
|
61
|
+
assert point is not None
|
|
62
|
+
assert isinstance(point, Point)
|
|
63
|
+
assert isinstance(point, Object)
|
|
64
|
+
assert point.is_defined()
|
|
65
|
+
assert (point.x() - 3.4) <= 1e-15
|
|
66
|
+
assert (point.y() + 6.7) <= 1e-15
|
|
67
|
+
assert (point.z() - 1.0) <= 1e-15
|
|
68
|
+
|
|
69
|
+
# Construction using a python numpy array
|
|
70
|
+
point: Point = Point.vector(np.array((3.4, -6.7, 1.0)))
|
|
71
|
+
|
|
72
|
+
assert point is not None
|
|
73
|
+
assert isinstance(point, Point)
|
|
74
|
+
assert isinstance(point, Object)
|
|
75
|
+
assert point.is_defined()
|
|
76
|
+
assert (point.x() - 3.4) <= 1e-15
|
|
77
|
+
assert (point.y() + 6.7) <= 1e-15
|
|
78
|
+
assert (point.z() - 1.0) <= 1e-15
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def test_geometry_d3_object_point_comparators():
|
|
82
|
+
point_1: Point = Point(3.4, -6.7, 1.0)
|
|
83
|
+
point_2: Point = Point.vector([3.4, -6.7, 1.0])
|
|
84
|
+
point_3: Point = Point(3.3, -6.5, 1.0)
|
|
85
|
+
point_4: Point = Point.vector(
|
|
86
|
+
(
|
|
87
|
+
3.4,
|
|
88
|
+
-6.7,
|
|
89
|
+
1.0,
|
|
90
|
+
)
|
|
91
|
+
)
|
|
92
|
+
point_5: Point = Point.vector(np.array((3.4, -6.7, 1.0)))
|
|
93
|
+
|
|
94
|
+
assert point_1 == point_1
|
|
95
|
+
assert point_1 == point_2
|
|
96
|
+
assert point_1 != point_3
|
|
97
|
+
assert point_2 != point_3
|
|
98
|
+
assert point_1 == point_4
|
|
99
|
+
assert point_1 == point_5
|
|
100
|
+
assert point_2 == point_4
|
|
101
|
+
assert point_2 == point_5
|
|
102
|
+
assert point_3 != point_4
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def test_geometry_d3_object_point_operators():
|
|
106
|
+
point_1: Point = Point(3.4, -6.7, 1.0)
|
|
107
|
+
point_2: Point = Point.vector([3.4, -6.7, 1.0])
|
|
108
|
+
point_3: Point = Point.vector((3.4, -6.7, 1.0))
|
|
109
|
+
point_4: Point = Point.vector(np.array((3.3, -6.5, 1.0)))
|
|
110
|
+
|
|
111
|
+
point: Point = point_1 + [3.4, -6.7, 1.0]
|
|
112
|
+
|
|
113
|
+
assert point is not None
|
|
114
|
+
assert isinstance(point, Point)
|
|
115
|
+
assert point.is_defined()
|
|
116
|
+
assert point.x() == point_1.x() + point_2.x()
|
|
117
|
+
assert point.y() == point_1.y() + point_2.y()
|
|
118
|
+
assert point.z() == point_1.z() + point_2.z()
|
|
119
|
+
|
|
120
|
+
point: Point = point_3 + [3.4, -6.7, 1.0]
|
|
121
|
+
|
|
122
|
+
assert point is not None
|
|
123
|
+
assert isinstance(point, Point)
|
|
124
|
+
assert point.is_defined()
|
|
125
|
+
assert point.x() == point_3.x() + point_2.x()
|
|
126
|
+
assert point.y() == point_3.y() + point_2.y()
|
|
127
|
+
assert point.z() == point_3.z() + point_2.z()
|
|
128
|
+
|
|
129
|
+
point: Point = point_1 + (3.3, -6.5, 1.0)
|
|
130
|
+
|
|
131
|
+
assert point is not None
|
|
132
|
+
assert isinstance(point, Point)
|
|
133
|
+
assert point.is_defined()
|
|
134
|
+
assert point.x() == point_1.x() + point_4.x()
|
|
135
|
+
assert point.y() == point_1.y() + point_4.y()
|
|
136
|
+
assert point.z() == point_1.z() + point_4.z()
|
|
137
|
+
|
|
138
|
+
point: Point = point_1 + (0.0, 0.0, 0.0)
|
|
139
|
+
|
|
140
|
+
assert point is not None
|
|
141
|
+
assert isinstance(point, Point)
|
|
142
|
+
assert point.is_defined()
|
|
143
|
+
assert point == point_1
|
|
144
|
+
|
|
145
|
+
point: Point = point_1 + [0.0, 0.0, 0.0]
|
|
146
|
+
|
|
147
|
+
assert point is not None
|
|
148
|
+
assert isinstance(point, Point)
|
|
149
|
+
assert point.is_defined()
|
|
150
|
+
assert point == point_1
|
|
151
|
+
|
|
152
|
+
point: Point = point_1 + np.array((0.0, 0.0, 0.0))
|
|
153
|
+
|
|
154
|
+
assert point is not None
|
|
155
|
+
assert isinstance(point, Point)
|
|
156
|
+
assert point.is_defined()
|
|
157
|
+
assert point == point_1
|
|
158
|
+
|
|
159
|
+
# point: Point = point_1 - point_1
|
|
160
|
+
|
|
161
|
+
# assert point is not None
|
|
162
|
+
# assert isinstance(point, Point)
|
|
163
|
+
# assert isinstance(point, Object)
|
|
164
|
+
# assert point.is_defined()
|
|
165
|
+
# assert point.x == 0.0
|
|
166
|
+
# assert point.y == 0.0
|
|
167
|
+
# assert point == Point.origin()
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
def test_geometry_d3_object_point_is_defined():
|
|
171
|
+
point: Point = Point(3.5, 5.6, 4.3)
|
|
172
|
+
|
|
173
|
+
assert point.is_defined()
|
|
174
|
+
assert Point.undefined().is_defined() is False
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
def test_geometry_d3_object_point_is_near():
|
|
178
|
+
point_1: Point = Point(3.5, 5.6, 4.3)
|
|
179
|
+
point_2: Point = Point(3.4999999999, 5.5999999999, 4.30000000000001)
|
|
180
|
+
|
|
181
|
+
assert point_1.is_near(point_2, 1e-8)
|
|
182
|
+
assert point_2.is_near(point_1, 1e-8)
|
|
183
|
+
assert point_1.is_near(point_2, 1e-11) is False
|
|
184
|
+
assert point_1.is_near(point_2, 1e-9) is True
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
def test_geometry_d3_object_point_components():
|
|
188
|
+
point: Point = Point(4.5, 34.5, 3.9)
|
|
189
|
+
|
|
190
|
+
assert point.x() == 4.5
|
|
191
|
+
assert point.y() == 34.5
|
|
192
|
+
assert point.z() == 3.9
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
def test_geometry_d3_object_point_as_vector():
|
|
196
|
+
point: Point = Point(3.4, -3.5, 1.0)
|
|
197
|
+
vec: np.ndarray = point.as_vector()
|
|
198
|
+
|
|
199
|
+
assert vec is not None
|
|
200
|
+
assert isinstance(vec, np.ndarray)
|
|
201
|
+
assert (vec[0] - 3.4) <= 1e-12
|
|
202
|
+
assert (vec[1] + 3.5) <= 1e-12
|
|
203
|
+
assert (vec[2] - 1.0) <= 1e-12
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
def test_geometry_d3_object_point_distance_to():
|
|
207
|
+
point_1: Point = Point(0.0, 4.0, 0.0)
|
|
208
|
+
point_2: Point = Point(0.0, 3.0, 0.0)
|
|
209
|
+
point_3: Point = Point(3.0, 0.0, 0.0)
|
|
210
|
+
point_4: Point = Point(1.1, 1.0, 0.0)
|
|
211
|
+
|
|
212
|
+
assert point_1.distance_to(point_2) - 1.0 <= 1e-12
|
|
213
|
+
assert point_2.distance_to(point_1) - 1.0 <= 1e-12
|
|
214
|
+
|
|
215
|
+
assert point_1.distance_to(point_3) - 5.0 <= 1e-12
|
|
216
|
+
assert point_3.distance_to(point_1) - 5.0 <= 1e-12
|
|
217
|
+
|
|
218
|
+
assert point_1.distance_to(point_4) == math.sqrt((1.1 * 1.1) + 9.0)
|
|
219
|
+
assert point_4.distance_to(point_1) == math.sqrt((1.1 * 1.1) + 9.0)
|
|
220
|
+
|
|
221
|
+
with pytest.raises(TypeError):
|
|
222
|
+
point_1.distance_to((0.0, 0.0, 0.0))
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
# def test_geometry_d3_object_point_to_string ():
|
|
226
|
+
|
|
227
|
+
# point: Point = Point(3.0, 5.0, 1.0)
|
|
228
|
+
|
|
229
|
+
# assert isinstance(point.to_string(), String)
|
|
230
|
+
# assert point.to_string() == '[3.0, 5.0, 1.0]'
|
|
231
|
+
|
|
232
|
+
# def test_geometry_d3_object_point_apply_transformation ():
|
|
233
|
+
|
|
234
|
+
# point: Point = Point(4.5, 5.4, 3.1)
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
# Apache License 2.0
|
|
2
|
+
|
|
3
|
+
from collections.abc import Iterator, Iterable
|
|
4
|
+
|
|
5
|
+
import pytest
|
|
6
|
+
|
|
7
|
+
from ostk.mathematics.geometry.d3 import Object
|
|
8
|
+
from ostk.mathematics.geometry.d3 import Transformation
|
|
9
|
+
from ostk.mathematics.geometry.d3.object import Point
|
|
10
|
+
from ostk.mathematics.geometry.d3.object import PointSet
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
@pytest.fixture
|
|
14
|
+
def point_set() -> PointSet:
|
|
15
|
+
return PointSet(
|
|
16
|
+
[
|
|
17
|
+
Point(1.0, 2.0, 1.0),
|
|
18
|
+
Point(3.0, 4.0, 1.0),
|
|
19
|
+
]
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class TestPointSet:
|
|
24
|
+
def test_constructor_success(self):
|
|
25
|
+
point_1: Point = Point(1.0, 2.0, 1.0)
|
|
26
|
+
point_2: Point = Point(3.0, 4.0, 1.0)
|
|
27
|
+
|
|
28
|
+
# Construction using python list
|
|
29
|
+
point_set: PointSet = PointSet([point_1, point_2])
|
|
30
|
+
|
|
31
|
+
assert point_set is not None
|
|
32
|
+
assert isinstance(point_set, PointSet)
|
|
33
|
+
assert isinstance(point_set, Object)
|
|
34
|
+
assert point_set.is_defined()
|
|
35
|
+
|
|
36
|
+
# Construction using python tuple
|
|
37
|
+
point_set = PointSet((point_1, point_2))
|
|
38
|
+
|
|
39
|
+
assert point_set is not None
|
|
40
|
+
assert isinstance(point_set, PointSet)
|
|
41
|
+
assert isinstance(point_set, Object)
|
|
42
|
+
assert point_set.is_defined()
|
|
43
|
+
|
|
44
|
+
point_set = PointSet((point_1,))
|
|
45
|
+
|
|
46
|
+
assert point_set is not None
|
|
47
|
+
assert isinstance(point_set, PointSet)
|
|
48
|
+
assert isinstance(point_set, Object)
|
|
49
|
+
assert point_set.is_defined()
|
|
50
|
+
|
|
51
|
+
def test_empty_success(self):
|
|
52
|
+
point_set: PointSet = PointSet.empty()
|
|
53
|
+
|
|
54
|
+
assert point_set is not None
|
|
55
|
+
assert isinstance(point_set, PointSet)
|
|
56
|
+
assert isinstance(point_set, Object)
|
|
57
|
+
assert point_set.is_defined() is False
|
|
58
|
+
assert point_set.is_empty()
|
|
59
|
+
|
|
60
|
+
def test_get_size_success(self):
|
|
61
|
+
point_1: Point = Point(1.0, 2.0, 1.0)
|
|
62
|
+
point_2: Point = Point(3.0, 4.0, 1.0)
|
|
63
|
+
|
|
64
|
+
point_set_1: PointSet = PointSet([point_1, point_2])
|
|
65
|
+
point_set_2: PointSet = PointSet((point_2, point_1))
|
|
66
|
+
point_set_3: PointSet = PointSet([point_2])
|
|
67
|
+
point_set_4: PointSet = PointSet.empty()
|
|
68
|
+
point_set_5: PointSet = PointSet([point_1, point_1])
|
|
69
|
+
|
|
70
|
+
assert point_set_1.get_size() == 2
|
|
71
|
+
assert point_set_2.get_size() == 2
|
|
72
|
+
assert point_set_3.get_size() == 1
|
|
73
|
+
assert point_set_4.get_size() == 0
|
|
74
|
+
assert point_set_5.get_size() == 1
|
|
75
|
+
|
|
76
|
+
def test_comparators_success(self):
|
|
77
|
+
point_1: Point = Point(1.0, 2.0, 1.0)
|
|
78
|
+
point_2: Point = Point(3.0, 4.0, 1.0)
|
|
79
|
+
|
|
80
|
+
point_set_1: PointSet = PointSet([point_1, point_2])
|
|
81
|
+
point_set_2: PointSet = PointSet((point_2, point_1))
|
|
82
|
+
point_set_3: PointSet = PointSet([point_2])
|
|
83
|
+
|
|
84
|
+
assert point_set_1 == point_set_2
|
|
85
|
+
assert point_set_1 == point_set_2
|
|
86
|
+
assert point_set_3 != point_set_1
|
|
87
|
+
assert point_set_2 != point_set_3
|
|
88
|
+
|
|
89
|
+
def test_distance_to_success_point(self, point_set: PointSet):
|
|
90
|
+
assert point_set.distance_to(Point(1.0, 2.0, 3.0)) == 2.0
|
|
91
|
+
|
|
92
|
+
def test_len_success(self, point_set: PointSet):
|
|
93
|
+
assert len(point_set) == 2
|
|
94
|
+
assert len(PointSet.empty()) == 0
|
|
95
|
+
|
|
96
|
+
def test_iter_success(self, point_set: PointSet):
|
|
97
|
+
for point in point_set:
|
|
98
|
+
assert isinstance(point, Point)
|
|
99
|
+
|
|
100
|
+
assert iter(point_set) is not None
|
|
101
|
+
assert isinstance(iter(point_set), Iterator)
|
|
102
|
+
assert isinstance(iter(point_set), Iterable)
|
|
103
|
+
|
|
104
|
+
def test_get_item_success(self, point_set: PointSet):
|
|
105
|
+
assert point_set[0] is not None
|
|
106
|
+
|
|
107
|
+
# def test_is_near_success(self):
|
|
108
|
+
|
|
109
|
+
# def test_get_point_closest_to_success(self):
|
|
110
|
+
|
|
111
|
+
# def test_to_string_success(self):
|
|
112
|
+
|
|
113
|
+
# def test_apply_transformation_success(self):
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
# Apache License 2.0
|
|
2
|
+
|
|
3
|
+
import pytest
|
|
4
|
+
|
|
5
|
+
import numpy as np
|
|
6
|
+
|
|
7
|
+
import ostk.mathematics as mathematics
|
|
8
|
+
|
|
9
|
+
from ostk.core.type import String
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
Point3d = mathematics.geometry.d3.object.Point
|
|
13
|
+
Point2d = mathematics.geometry.d2.object.Point
|
|
14
|
+
Polygon3d = mathematics.geometry.d3.object.Polygon
|
|
15
|
+
Object3d = mathematics.geometry.d3.Object
|
|
16
|
+
Polygon2d = mathematics.geometry.d2.object.Polygon
|
|
17
|
+
Transformation = mathematics.geometry.d3.Transformation
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def test_geometry_d3_object_polygon():
|
|
21
|
+
## Constructors
|
|
22
|
+
|
|
23
|
+
# Construct a Polygon2d
|
|
24
|
+
point_1: Point2d = Point2d(-1.0, 1.0)
|
|
25
|
+
point_2: Point2d = Point2d(1.0, 1.0)
|
|
26
|
+
point_3: Point2d = Point2d(1.0, -1.0)
|
|
27
|
+
point_4: Point2d = Point2d(-1.0, -1.0)
|
|
28
|
+
|
|
29
|
+
polygon2d: Polygon2d = Polygon2d([point_1, point_2, point_3, point_4])
|
|
30
|
+
|
|
31
|
+
assert polygon2d is not None
|
|
32
|
+
assert isinstance(polygon2d, Polygon2d)
|
|
33
|
+
assert polygon2d.is_defined()
|
|
34
|
+
|
|
35
|
+
# Construct a Polygon3d using python list constructors for vectors
|
|
36
|
+
point_5: Point3d = Point3d(1.0, 1.0, 1.0)
|
|
37
|
+
vector_1 = [1.0, 0.0, 0.0]
|
|
38
|
+
vector_2 = [0.0, 1.0, 0.0]
|
|
39
|
+
|
|
40
|
+
polygon3d_1: Polygon3d = Polygon3d(polygon2d, point_5, vector_1, vector_2)
|
|
41
|
+
|
|
42
|
+
assert polygon3d_1 is not None
|
|
43
|
+
assert isinstance(polygon3d_1, Polygon3d)
|
|
44
|
+
assert isinstance(polygon3d_1, Object3d)
|
|
45
|
+
assert polygon3d_1.is_defined()
|
|
46
|
+
|
|
47
|
+
# Construct a Polygon3d using python tuple constructors for vectors
|
|
48
|
+
point_5: Point3d = Point3d(1.0, 1.0, 1.0)
|
|
49
|
+
vector_1 = (1.0, 0.0, 0.0)
|
|
50
|
+
vector_2 = (0.0, 1.0, 0.0)
|
|
51
|
+
|
|
52
|
+
polygon3d_2: Polygon3d = Polygon3d(polygon2d, point_5, vector_1, vector_2)
|
|
53
|
+
|
|
54
|
+
assert polygon3d_2 is not None
|
|
55
|
+
assert isinstance(polygon3d_2, Polygon3d)
|
|
56
|
+
assert isinstance(polygon3d_2, Object3d)
|
|
57
|
+
assert polygon3d_2.is_defined()
|
|
58
|
+
|
|
59
|
+
# Construct a Polygon3d using python numpy array constructors for vectors
|
|
60
|
+
point_5: Point3d = Point3d(1.0, 1.0, 1.0)
|
|
61
|
+
vector_3 = np.array((1.0, 0.0, 0.0))
|
|
62
|
+
vector_4 = (0.0, 1.0, 1.0)
|
|
63
|
+
|
|
64
|
+
polygon3d_3: Polygon3d = Polygon3d(polygon2d, point_5, vector_3, vector_4)
|
|
65
|
+
|
|
66
|
+
assert polygon3d_3 is not None
|
|
67
|
+
assert isinstance(polygon3d_3, Polygon3d)
|
|
68
|
+
assert isinstance(polygon3d_3, Object3d)
|
|
69
|
+
assert polygon3d_3.is_defined()
|
|
70
|
+
|
|
71
|
+
# Construct using the static "undefined" method
|
|
72
|
+
polygon3d_4: Polygon3d = Polygon3d.undefined()
|
|
73
|
+
|
|
74
|
+
assert polygon3d_4 is not None
|
|
75
|
+
assert isinstance(polygon3d_4, Polygon3d)
|
|
76
|
+
assert isinstance(polygon3d_4, Object3d)
|
|
77
|
+
assert polygon3d_4.is_defined() is False
|
|
78
|
+
|
|
79
|
+
## Comparators
|
|
80
|
+
|
|
81
|
+
assert polygon3d_1 == polygon3d_1
|
|
82
|
+
assert polygon3d_2 == polygon3d_2
|
|
83
|
+
assert polygon3d_3 == polygon3d_3
|
|
84
|
+
assert polygon3d_1 == polygon3d_2
|
|
85
|
+
assert polygon3d_3 != polygon3d_1
|
|
86
|
+
assert polygon3d_3 != polygon3d_2
|
|
87
|
+
|
|
88
|
+
## get_polygon2d
|
|
89
|
+
|
|
90
|
+
polygon2d_1: Polygon2d = polygon3d_1.get_polygon2d()
|
|
91
|
+
polygon2d_2: Polygon2d = polygon3d_2.get_polygon2d()
|
|
92
|
+
polygon2d_3: Polygon2d = polygon3d_2.get_polygon2d()
|
|
93
|
+
|
|
94
|
+
assert polygon2d_1 is not None
|
|
95
|
+
assert polygon2d_2 is not None
|
|
96
|
+
assert polygon2d_3 is not None
|
|
97
|
+
|
|
98
|
+
assert isinstance(polygon2d_1, Polygon2d)
|
|
99
|
+
assert isinstance(polygon2d_2, Polygon2d)
|
|
100
|
+
assert isinstance(polygon2d_3, Polygon2d)
|
|
101
|
+
|
|
102
|
+
assert polygon2d_1 == polygon2d_2
|
|
103
|
+
assert polygon2d_2 == polygon2d_3
|
|
104
|
+
|
|
105
|
+
## get_origin
|
|
106
|
+
|
|
107
|
+
origin_1: Point3d = polygon3d_1.get_origin()
|
|
108
|
+
origin_2: Point3d = polygon3d_2.get_origin()
|
|
109
|
+
origin_3: Point3d = polygon3d_3.get_origin()
|
|
110
|
+
|
|
111
|
+
assert origin_1 == point_5
|
|
112
|
+
assert origin_2 == point_5
|
|
113
|
+
assert origin_3 == point_5
|
|
114
|
+
|
|
115
|
+
## get_x_axis
|
|
116
|
+
|
|
117
|
+
xaxis_1: np.ndarray = polygon3d_1.get_x_axis()
|
|
118
|
+
xaxis_2: np.ndarray = polygon3d_2.get_x_axis()
|
|
119
|
+
xaxis_3: np.ndarray = polygon3d_3.get_x_axis()
|
|
120
|
+
|
|
121
|
+
assert np.array_equal(xaxis_1, np.array(vector_1))
|
|
122
|
+
assert np.array_equal(xaxis_2, np.array(vector_1))
|
|
123
|
+
assert np.array_equal(xaxis_3, np.array(vector_3))
|
|
124
|
+
|
|
125
|
+
## get_y_axis
|
|
126
|
+
|
|
127
|
+
yaxis_1: np.ndarray = polygon3d_1.get_y_axis()
|
|
128
|
+
yaxis_2: np.ndarray = polygon3d_2.get_y_axis()
|
|
129
|
+
yaxis_3: np.ndarray = polygon3d_3.get_y_axis()
|
|
130
|
+
|
|
131
|
+
assert np.array_equal(yaxis_1, np.array(vector_2))
|
|
132
|
+
assert np.array_equal(yaxis_2, np.array(vector_2))
|
|
133
|
+
assert np.array_equal(
|
|
134
|
+
yaxis_3, np.array(vector_4) / np.linalg.norm(np.array(vector_4))
|
|
135
|
+
)
|
|
136
|
+
|
|
137
|
+
## is_near
|
|
138
|
+
|
|
139
|
+
## get_normal_vector
|
|
140
|
+
|
|
141
|
+
## apply_transformation
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
# Apache License 2.0
|
|
2
|
+
|
|
3
|
+
import pytest
|
|
4
|
+
|
|
5
|
+
import numpy as np
|
|
6
|
+
|
|
7
|
+
import ostk.mathematics as mathematics
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
Object = mathematics.geometry.d3.Object
|
|
11
|
+
Point = mathematics.geometry.d3.object.Point
|
|
12
|
+
PointSet = mathematics.geometry.d3.object.PointSet
|
|
13
|
+
Segment = mathematics.geometry.d3.object.Segment
|
|
14
|
+
Line = mathematics.geometry.d3.object.Line
|
|
15
|
+
Plane = mathematics.geometry.d3.object.Plane
|
|
16
|
+
Sphere = mathematics.geometry.d3.object.Sphere
|
|
17
|
+
Ellipsoid = mathematics.geometry.d3.object.Ellipsoid
|
|
18
|
+
Intersection = mathematics.geometry.d3.Intersection
|
|
19
|
+
Transformation = mathematics.geometry.d3.Transformation
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
@pytest.fixture
|
|
23
|
+
def segment() -> Segment:
|
|
24
|
+
return Segment(
|
|
25
|
+
Point(0.0, 0.0, 0.0),
|
|
26
|
+
Point(0.0, 0.0, 2.0),
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class TestSegment:
|
|
31
|
+
def test_constructor_success(self):
|
|
32
|
+
point_1: Point = Point(-1.0, 1.0, 0.0)
|
|
33
|
+
point_2: Point = Point(1.0, 1.0, 1.0)
|
|
34
|
+
|
|
35
|
+
segment: Segment = Segment(point_1, point_2)
|
|
36
|
+
|
|
37
|
+
assert segment is not None
|
|
38
|
+
assert isinstance(segment, Segment)
|
|
39
|
+
assert isinstance(segment, Object)
|
|
40
|
+
assert segment.is_defined()
|
|
41
|
+
|
|
42
|
+
segment: Segment = Segment(point_1, point_1)
|
|
43
|
+
|
|
44
|
+
assert segment is not None
|
|
45
|
+
assert isinstance(segment, Segment)
|
|
46
|
+
assert isinstance(segment, Object)
|
|
47
|
+
assert segment.is_defined()
|
|
48
|
+
|
|
49
|
+
def test_comparators_success(self):
|
|
50
|
+
point_1: Point = Point(-1.0, 1.0, 0.0)
|
|
51
|
+
point_2: Point = Point(1.0, 1.0, 0.0)
|
|
52
|
+
|
|
53
|
+
segment_1: Segment = Segment(point_1, point_2)
|
|
54
|
+
segment_2: Segment = Segment(point_1, point_1)
|
|
55
|
+
|
|
56
|
+
assert segment_1 == segment_1
|
|
57
|
+
assert segment_1 != segment_2
|
|
58
|
+
|
|
59
|
+
def test_getters_success(self):
|
|
60
|
+
point_1: Point = Point(-1.0, 1.0, 0.0)
|
|
61
|
+
point_2: Point = Point(1.0, 1.0, 0.0)
|
|
62
|
+
|
|
63
|
+
segment: Segment = Segment(point_1, point_2)
|
|
64
|
+
|
|
65
|
+
assert isinstance(segment.get_first_point(), Point)
|
|
66
|
+
assert segment.get_first_point() == point_1
|
|
67
|
+
|
|
68
|
+
assert isinstance(segment.get_second_point(), Point)
|
|
69
|
+
assert segment.get_second_point() == point_2
|
|
70
|
+
|
|
71
|
+
assert isinstance(segment.get_center(), Point)
|
|
72
|
+
assert segment.get_center() == Point(0.0, 1.0, 0.0)
|
|
73
|
+
|
|
74
|
+
assert isinstance(segment.get_direction(), np.ndarray)
|
|
75
|
+
assert np.array_equal(segment.get_direction(), np.array((1.0, 0.0, 0.0)))
|
|
76
|
+
|
|
77
|
+
assert segment.get_length() == 2.0
|
|
78
|
+
|
|
79
|
+
def test_is_defined_success(self, segment: Segment):
|
|
80
|
+
assert segment.is_defined() is True
|
|
81
|
+
|
|
82
|
+
def test_is_degenerate_success(self, segment: Segment):
|
|
83
|
+
assert segment.is_degenerate() is False
|
|
84
|
+
|
|
85
|
+
def test_intersects_success_plane(self, segment: Segment):
|
|
86
|
+
assert (
|
|
87
|
+
segment.intersects(Plane(Point(0.0, 0.0, 0.0), np.array((1.0, 0.0, 0.0))))
|
|
88
|
+
is True
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
def test_intersects_success_sphere(self, segment: Segment):
|
|
92
|
+
assert segment.intersects(Sphere(Point(0.0, 0.0, 0.0), 1.0)) is True
|
|
93
|
+
|
|
94
|
+
def test_intersects_success_ellipsoid(self, segment: Segment):
|
|
95
|
+
assert segment.intersects(Ellipsoid(Point(0.0, 0.0, 0.0), 0.5, 0.5, 0.5)) is True
|
|
96
|
+
|
|
97
|
+
def test_contains_success_point(self, segment: Segment):
|
|
98
|
+
assert segment.contains(Point(0.0, 0.0, 0.0)) is True
|
|
99
|
+
|
|
100
|
+
def test_get_length_success(self, segment: Segment):
|
|
101
|
+
assert segment.get_length() == 2.0
|
|
102
|
+
|
|
103
|
+
def test_distance_to_success_point(self, segment: Segment):
|
|
104
|
+
assert segment.distance_to(Point(0.0, 0.0, 0.0)) == 0.0
|
|
105
|
+
|
|
106
|
+
def test_distance_to_success_point_set(self, segment: Segment):
|
|
107
|
+
assert (
|
|
108
|
+
segment.distance_to(PointSet([Point(0.0, 0.0, 0.0), Point(1.0, 0.0, 0.0)]))
|
|
109
|
+
== 0.0
|
|
110
|
+
)
|
|
111
|
+
|
|
112
|
+
def test_intersection_with_success_plane(self, segment: Segment):
|
|
113
|
+
assert segment.intersection_with(
|
|
114
|
+
Plane(Point(0.0, 0.0, 0.0), np.array((0.0, 0.0, 1.0)))
|
|
115
|
+
) == Intersection.point(Point(0.0, 0.0, 0.0))
|
|
116
|
+
|
|
117
|
+
def test_to_line_success(self, segment: Segment):
|
|
118
|
+
assert segment.to_line() == Line(Point(0.0, 0.0, 0.0), np.array((0.0, 0.0, 1.0)))
|
|
119
|
+
|
|
120
|
+
# def test_apply_transformation_success (self):
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# Apache License 2.0
|
|
2
|
+
|
|
3
|
+
import pytest
|
|
4
|
+
|
|
5
|
+
import numpy as np
|
|
6
|
+
|
|
7
|
+
import ostk.mathematics as mathematics
|
|
8
|
+
|
|
9
|
+
from ostk.core.type import String
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
Point3d = mathematics.geometry.d3.object.Point
|
|
13
|
+
Point2d = mathematics.geometry.d2.object.Point
|
|
14
|
+
Polygon3d = mathematics.geometry.d3.object.Polygon
|
|
15
|
+
Object3d = mathematics.geometry.d3.Object
|
|
16
|
+
Polygon2d = mathematics.geometry.d2.object.Polygon
|
|
17
|
+
Transformation = mathematics.geometry.d3.Transformation
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
# def test_geometry_d3_objects_cuboid ():
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# Apache License 2.0
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# Apache License 2.0
|