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,100 @@
|
|
|
1
|
+
# Apache License 2.0
|
|
2
|
+
|
|
3
|
+
from collections.abc import Iterator, Iterable
|
|
4
|
+
|
|
5
|
+
from ostk.mathematics.geometry.d2 import Object
|
|
6
|
+
from ostk.mathematics.geometry.d2.object import Point
|
|
7
|
+
from ostk.mathematics.geometry.d2.object import PointSet
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class TestPointSet:
|
|
11
|
+
def test_constructor_success(self):
|
|
12
|
+
point_1: Point = Point(1.0, 2.0)
|
|
13
|
+
point_2: Point = Point(3.0, 4.0)
|
|
14
|
+
|
|
15
|
+
# Construction using python list
|
|
16
|
+
point_set: PointSet = PointSet([point_1, point_2])
|
|
17
|
+
|
|
18
|
+
assert point_set is not None
|
|
19
|
+
assert isinstance(point_set, PointSet)
|
|
20
|
+
assert isinstance(point_set, Object)
|
|
21
|
+
assert point_set.is_defined()
|
|
22
|
+
|
|
23
|
+
# Construction using python tuple
|
|
24
|
+
point_set = PointSet((point_1, point_2))
|
|
25
|
+
|
|
26
|
+
assert point_set is not None
|
|
27
|
+
assert isinstance(point_set, PointSet)
|
|
28
|
+
assert isinstance(point_set, Object)
|
|
29
|
+
assert point_set.is_defined()
|
|
30
|
+
|
|
31
|
+
point_set = PointSet((point_1,))
|
|
32
|
+
|
|
33
|
+
assert point_set is not None
|
|
34
|
+
assert isinstance(point_set, PointSet)
|
|
35
|
+
assert isinstance(point_set, Object)
|
|
36
|
+
assert point_set.is_defined()
|
|
37
|
+
|
|
38
|
+
def test_empty_success(self):
|
|
39
|
+
point_set: Pointset = PointSet.empty()
|
|
40
|
+
|
|
41
|
+
assert point_set is not None
|
|
42
|
+
assert isinstance(point_set, PointSet)
|
|
43
|
+
assert isinstance(point_set, Object)
|
|
44
|
+
assert point_set.is_defined() is False
|
|
45
|
+
assert point_set.is_empty()
|
|
46
|
+
|
|
47
|
+
def test_comparators_success(self):
|
|
48
|
+
point_1: Point = Point(1.0, 2.0)
|
|
49
|
+
point_2: Point = Point(3.0, 4.0)
|
|
50
|
+
|
|
51
|
+
point_set_1: PointSet = PointSet([point_1, point_2])
|
|
52
|
+
point_set_2: PointSet = PointSet((point_2, point_1))
|
|
53
|
+
point_set_3: PointSet = PointSet([point_2])
|
|
54
|
+
|
|
55
|
+
assert point_set_1 == point_set_2
|
|
56
|
+
assert point_set_1 == point_set_2
|
|
57
|
+
assert point_set_3 != point_set_1
|
|
58
|
+
assert point_set_2 != point_set_3
|
|
59
|
+
|
|
60
|
+
def test_get_size_success(self):
|
|
61
|
+
point_1: Point = Point(1.0, 2.0)
|
|
62
|
+
point_2: Point = Point(3.0, 4.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_distance_to_success_point(self, point_set: PointSet):
|
|
77
|
+
assert point_set.distance_to(Point(1.0, 2.0)) == 0.0
|
|
78
|
+
|
|
79
|
+
def test_len_success(self, point_set: PointSet):
|
|
80
|
+
assert len(point_set) == 2
|
|
81
|
+
assert len(PointSet.empty()) == 0
|
|
82
|
+
|
|
83
|
+
def test_iter_success(self, point_set: PointSet):
|
|
84
|
+
for point in point_set:
|
|
85
|
+
assert isinstance(point, Point)
|
|
86
|
+
|
|
87
|
+
assert iter(point_set) is not None
|
|
88
|
+
assert isinstance(iter(point_set), Iterator)
|
|
89
|
+
assert isinstance(iter(point_set), Iterable)
|
|
90
|
+
|
|
91
|
+
def test_get_item_success(self, point_set: PointSet):
|
|
92
|
+
assert point_set[0] is not None
|
|
93
|
+
|
|
94
|
+
# def test_is_near_success(self):
|
|
95
|
+
|
|
96
|
+
# def test_get_point_closest_to_success(self):
|
|
97
|
+
|
|
98
|
+
# def test_to_string_success(self):
|
|
99
|
+
|
|
100
|
+
# def test_apply_transformation_success(self):
|
|
@@ -0,0 +1,370 @@
|
|
|
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.d2.Object
|
|
11
|
+
Point = mathematics.geometry.d2.object.Point
|
|
12
|
+
PointSet = mathematics.geometry.d2.object.PointSet
|
|
13
|
+
Polygon = mathematics.geometry.d2.object.Polygon
|
|
14
|
+
MultiPolygon = mathematics.geometry.d2.object.MultiPolygon
|
|
15
|
+
LineString = mathematics.geometry.d2.object.LineString
|
|
16
|
+
Segment = mathematics.geometry.d2.object.Segment
|
|
17
|
+
Intersection = mathematics.geometry.d2.Intersection
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class TestPolygon:
|
|
21
|
+
def test_constructor_empty_inner_ring(self):
|
|
22
|
+
point_1: Point = Point(-1.0, 1.0)
|
|
23
|
+
point_2: Point = Point(1.0, 1.0)
|
|
24
|
+
point_3: Point = Point(1.0, -1.0)
|
|
25
|
+
point_4: Point = Point(-1.0, -1.0)
|
|
26
|
+
|
|
27
|
+
# Default constructor with Array of Points using python list
|
|
28
|
+
polygon: Polygon = Polygon([point_1, point_2, point_3, point_4])
|
|
29
|
+
|
|
30
|
+
assert polygon is not None
|
|
31
|
+
assert isinstance(polygon, Polygon)
|
|
32
|
+
assert isinstance(polygon, Object)
|
|
33
|
+
assert polygon.is_defined()
|
|
34
|
+
|
|
35
|
+
# Default constructor with Array of Points using python tuple
|
|
36
|
+
polygon: Polygon = Polygon((point_1, point_2, point_3, point_4))
|
|
37
|
+
|
|
38
|
+
assert polygon is not None
|
|
39
|
+
assert isinstance(polygon, Polygon)
|
|
40
|
+
assert isinstance(polygon, Object)
|
|
41
|
+
assert polygon.is_defined()
|
|
42
|
+
|
|
43
|
+
# Default constructor with Array of Points using python numpy array
|
|
44
|
+
polygon: Polygon = Polygon((point_1, point_2, point_3, point_4))
|
|
45
|
+
|
|
46
|
+
assert polygon is not None
|
|
47
|
+
assert isinstance(polygon, Polygon)
|
|
48
|
+
assert isinstance(polygon, Object)
|
|
49
|
+
assert polygon.is_defined()
|
|
50
|
+
|
|
51
|
+
# Defaut constructor with 3 points (minimum)
|
|
52
|
+
polygon: Polygon = Polygon((point_1, point_2, point_3))
|
|
53
|
+
|
|
54
|
+
assert polygon is not None
|
|
55
|
+
assert isinstance(polygon, Polygon)
|
|
56
|
+
assert isinstance(polygon, Object)
|
|
57
|
+
assert polygon.is_defined()
|
|
58
|
+
|
|
59
|
+
# Invalid constructions
|
|
60
|
+
with pytest.raises(RuntimeError):
|
|
61
|
+
polygon: Polygon = Polygon([point_1, point_2])
|
|
62
|
+
|
|
63
|
+
with pytest.raises(RuntimeError):
|
|
64
|
+
polygon: Polygon = Polygon((point_1, point_2))
|
|
65
|
+
|
|
66
|
+
with pytest.raises(RuntimeError):
|
|
67
|
+
polygon: Polygon = Polygon([point_1])
|
|
68
|
+
|
|
69
|
+
def test_constructor_nonempty_inner_ring(self):
|
|
70
|
+
# Outer Ring Vertices
|
|
71
|
+
point_1: Point = Point(-1.0, 1.0)
|
|
72
|
+
point_2: Point = Point(1.0, 1.0)
|
|
73
|
+
point_3: Point = Point(1.0, -1.0)
|
|
74
|
+
point_4: Point = Point(-1.0, -1.0)
|
|
75
|
+
|
|
76
|
+
# Inner Ring Vertices
|
|
77
|
+
point_5: Point = Point(-0.5, 0.5)
|
|
78
|
+
point_6: Point = Point(0.5, 0.5)
|
|
79
|
+
point_7: Point = Point(0.5, -0.5)
|
|
80
|
+
point_8: Point = Point(-0.5, -0.5)
|
|
81
|
+
|
|
82
|
+
# Outer Ring Definitions
|
|
83
|
+
outer_ring_list = [point_1, point_2, point_3, point_4]
|
|
84
|
+
outer_ring_tuple = (point_1, point_2, point_3, point_4)
|
|
85
|
+
outer_ring_numpy = np.array(outer_ring_tuple)
|
|
86
|
+
|
|
87
|
+
# Inner Ring Definitions
|
|
88
|
+
inner_ring_list = [point_5, point_6, point_7, point_8]
|
|
89
|
+
inner_ring_tuple = (point_5, point_6, point_7, point_8)
|
|
90
|
+
inner_ring_numpy = np.array(inner_ring_tuple)
|
|
91
|
+
|
|
92
|
+
# Inner Rings Definitions
|
|
93
|
+
inner_rings_list_list = [
|
|
94
|
+
inner_ring_list,
|
|
95
|
+
]
|
|
96
|
+
inner_rings_list_tuple = (inner_ring_list,)
|
|
97
|
+
inner_rings_tuple_list = [
|
|
98
|
+
inner_ring_tuple,
|
|
99
|
+
]
|
|
100
|
+
inner_rings_tuple_tuple = (inner_ring_tuple,)
|
|
101
|
+
inner_rings_numpy = np.array(inner_rings_list_list)
|
|
102
|
+
|
|
103
|
+
# Default constructor with Inner Ring using Python list
|
|
104
|
+
polygon: Polyon = Polygon(outer_ring_list, inner_rings_list_list)
|
|
105
|
+
|
|
106
|
+
assert polygon is not None
|
|
107
|
+
assert isinstance(polygon, Polygon)
|
|
108
|
+
assert isinstance(polygon, Object)
|
|
109
|
+
assert polygon.is_defined()
|
|
110
|
+
|
|
111
|
+
# Default constructor with Inner Ring using Python tuples
|
|
112
|
+
polygon: Polyon = Polygon(outer_ring_tuple, inner_rings_tuple_tuple)
|
|
113
|
+
|
|
114
|
+
assert polygon is not None
|
|
115
|
+
assert isinstance(polygon, Polygon)
|
|
116
|
+
assert isinstance(polygon, Object)
|
|
117
|
+
assert polygon.is_defined()
|
|
118
|
+
|
|
119
|
+
# Default constructor with Inner Ring using Python numpy arrays
|
|
120
|
+
polygon: Polygon = Polygon(outer_ring_numpy, inner_rings_numpy)
|
|
121
|
+
|
|
122
|
+
assert polygon is not None
|
|
123
|
+
assert isinstance(polygon, Polygon)
|
|
124
|
+
assert isinstance(polygon, Object)
|
|
125
|
+
assert polygon.is_defined()
|
|
126
|
+
|
|
127
|
+
# Default constructor with Inner Ring multiple types 1
|
|
128
|
+
polygon: Polygon = Polygon(outer_ring_numpy, inner_rings_list_list)
|
|
129
|
+
|
|
130
|
+
assert polygon is not None
|
|
131
|
+
assert isinstance(polygon, Polygon)
|
|
132
|
+
assert isinstance(polygon, Object)
|
|
133
|
+
assert polygon.is_defined()
|
|
134
|
+
|
|
135
|
+
# Default constructor with Inner Ring multiple types 2
|
|
136
|
+
polygon: Polygon = Polygon(outer_ring_tuple, inner_rings_numpy)
|
|
137
|
+
|
|
138
|
+
assert polygon is not None
|
|
139
|
+
assert isinstance(polygon, Polygon)
|
|
140
|
+
assert isinstance(polygon, Object)
|
|
141
|
+
assert polygon.is_defined()
|
|
142
|
+
|
|
143
|
+
# Default constructor with Inner Ring multiple types 3
|
|
144
|
+
polygon: Polygon = Polygon(outer_ring_list, inner_rings_numpy)
|
|
145
|
+
|
|
146
|
+
assert polygon is not None
|
|
147
|
+
assert isinstance(polygon, Polygon)
|
|
148
|
+
assert isinstance(polygon, Object)
|
|
149
|
+
assert polygon.is_defined()
|
|
150
|
+
|
|
151
|
+
# Default constructor with Inner Ring multiple types 4
|
|
152
|
+
polygon: Polygon = Polygon(outer_ring_list, inner_rings_tuple_tuple)
|
|
153
|
+
|
|
154
|
+
assert polygon is not None
|
|
155
|
+
assert isinstance(polygon, Polygon)
|
|
156
|
+
assert isinstance(polygon, Object)
|
|
157
|
+
assert polygon.is_defined()
|
|
158
|
+
|
|
159
|
+
# Default constructor with Inner Ring multiple types 5
|
|
160
|
+
polygon: Polygon = Polygon(outer_ring_numpy, inner_rings_tuple_tuple)
|
|
161
|
+
|
|
162
|
+
assert polygon is not None
|
|
163
|
+
assert isinstance(polygon, Polygon)
|
|
164
|
+
assert isinstance(polygon, Object)
|
|
165
|
+
assert polygon.is_defined()
|
|
166
|
+
|
|
167
|
+
# Default constructor with Inner Ring multiple types 6
|
|
168
|
+
polygon: Polygon = Polygon(outer_ring_numpy, inner_rings_list_tuple)
|
|
169
|
+
|
|
170
|
+
assert polygon is not None
|
|
171
|
+
assert isinstance(polygon, Polygon)
|
|
172
|
+
assert isinstance(polygon, Object)
|
|
173
|
+
assert polygon.is_defined()
|
|
174
|
+
|
|
175
|
+
# Default constructor with Inner Ring multiple types 7
|
|
176
|
+
polygon: Polygon = Polygon(outer_ring_numpy, inner_rings_tuple_list)
|
|
177
|
+
|
|
178
|
+
assert polygon is not None
|
|
179
|
+
assert isinstance(polygon, Polygon)
|
|
180
|
+
assert isinstance(polygon, Object)
|
|
181
|
+
assert polygon.is_defined()
|
|
182
|
+
|
|
183
|
+
# Default constructor with Inner Ring multiple types 8
|
|
184
|
+
polygon: Polygon = Polygon(outer_ring_tuple, inner_rings_list_list)
|
|
185
|
+
|
|
186
|
+
assert polygon is not None
|
|
187
|
+
assert isinstance(polygon, Polygon)
|
|
188
|
+
assert isinstance(polygon, Object)
|
|
189
|
+
assert polygon.is_defined()
|
|
190
|
+
|
|
191
|
+
# ...
|
|
192
|
+
|
|
193
|
+
def test_comparators(self):
|
|
194
|
+
point_1: Point = Point(-1.0, 1.0)
|
|
195
|
+
point_2: Point = Point(1.0, 1.0)
|
|
196
|
+
point_3: Point = Point(1.0, -1.0)
|
|
197
|
+
point_4: Point = Point(-1.0, -1.0)
|
|
198
|
+
|
|
199
|
+
polygon_1: Polygon = Polygon((point_1, point_2, point_3, point_4))
|
|
200
|
+
polygon_2: Polygon = Polygon((point_1, point_2, point_3))
|
|
201
|
+
|
|
202
|
+
assert polygon_1 == polygon_1
|
|
203
|
+
assert polygon_2 == polygon_2
|
|
204
|
+
assert polygon_1 != polygon_2
|
|
205
|
+
|
|
206
|
+
def test_intersects_polygon(
|
|
207
|
+
self,
|
|
208
|
+
square_1: Polygon,
|
|
209
|
+
square_2: Polygon,
|
|
210
|
+
square_3: Polygon,
|
|
211
|
+
square_4: Polygon,
|
|
212
|
+
):
|
|
213
|
+
assert square_1.intersects(square_2) is False
|
|
214
|
+
assert square_1.intersects(square_3) is True
|
|
215
|
+
assert square_1.intersects(square_4) is True
|
|
216
|
+
assert square_2.intersects(square_4) is False
|
|
217
|
+
assert square_2.intersects(square_3) is False
|
|
218
|
+
|
|
219
|
+
def test_contains(self):
|
|
220
|
+
point_1: Point = Point(-1.0, 1.0)
|
|
221
|
+
point_2: Point = Point(1.0, 1.0)
|
|
222
|
+
point_3: Point = Point(1.0, -1.0)
|
|
223
|
+
point_4: Point = Point(-1.0, -1.0)
|
|
224
|
+
|
|
225
|
+
point_set: PointSet = PointSet([Point(0.0, 0.0)])
|
|
226
|
+
polygon: Polygon = Polygon((point_1, point_2, point_3, point_4))
|
|
227
|
+
|
|
228
|
+
assert polygon.contains(Point.origin())
|
|
229
|
+
assert polygon.contains(point_1)
|
|
230
|
+
assert polygon.contains(point_2)
|
|
231
|
+
assert polygon.contains(point_3)
|
|
232
|
+
assert polygon.contains(point_4)
|
|
233
|
+
assert polygon.contains(Point(10.0, 10.0)) is False
|
|
234
|
+
|
|
235
|
+
assert polygon.contains(point_set)
|
|
236
|
+
|
|
237
|
+
def test_getters(self):
|
|
238
|
+
# Outer Ring Vertices
|
|
239
|
+
point_1: Point = Point(-1.0, 1.0)
|
|
240
|
+
point_2: Point = Point(1.0, 1.0)
|
|
241
|
+
point_3: Point = Point(1.0, -1.0)
|
|
242
|
+
point_4: Point = Point(-1.0, -1.0)
|
|
243
|
+
|
|
244
|
+
# Inner Ring Vertices
|
|
245
|
+
point_5: Point = Point(-0.5, 0.5)
|
|
246
|
+
point_6: Point = Point(0.5, -0.5)
|
|
247
|
+
point_7: Point = Point(0.5, 0.5)
|
|
248
|
+
point_8: Point = Point(-0.5, -0.5)
|
|
249
|
+
|
|
250
|
+
# Rings Definitions
|
|
251
|
+
outer_ring = [point_1, point_2, point_3, point_4]
|
|
252
|
+
inner_rings = [
|
|
253
|
+
[point_5, point_6, point_7, point_8],
|
|
254
|
+
]
|
|
255
|
+
|
|
256
|
+
# Define polygon
|
|
257
|
+
polygon: Polygon = Polygon(outer_ring, inner_rings)
|
|
258
|
+
|
|
259
|
+
# get_inner_rings_count
|
|
260
|
+
assert polygon.get_inner_ring_count() == 1
|
|
261
|
+
|
|
262
|
+
# get_edge_count
|
|
263
|
+
assert polygon.get_edge_count() == 8
|
|
264
|
+
|
|
265
|
+
# get_vertex_count
|
|
266
|
+
assert polygon.get_vertex_count() == 8
|
|
267
|
+
|
|
268
|
+
# get_outer_ring
|
|
269
|
+
assert isinstance(polygon.get_outer_ring(), LineString)
|
|
270
|
+
assert polygon.get_outer_ring() == LineString(
|
|
271
|
+
[point_1, point_2, point_3, point_4, point_1]
|
|
272
|
+
)
|
|
273
|
+
|
|
274
|
+
# get_inner_ring_at
|
|
275
|
+
assert isinstance(polygon.get_inner_ring_at(0), LineString)
|
|
276
|
+
assert polygon.get_inner_ring_at(0) == LineString(
|
|
277
|
+
[point_5, point_6, point_7, point_8, point_5]
|
|
278
|
+
)
|
|
279
|
+
|
|
280
|
+
with pytest.raises(RuntimeError):
|
|
281
|
+
polygon.get_inner_ring_at(1)
|
|
282
|
+
|
|
283
|
+
# get_edge_at
|
|
284
|
+
edge_0 = polygon.get_edge_at(0)
|
|
285
|
+
edge_1 = polygon.get_edge_at(1)
|
|
286
|
+
edge_2 = polygon.get_edge_at(2)
|
|
287
|
+
|
|
288
|
+
assert isinstance(edge_0, Segment)
|
|
289
|
+
assert isinstance(edge_1, Segment)
|
|
290
|
+
assert isinstance(edge_2, Segment)
|
|
291
|
+
|
|
292
|
+
assert edge_0.get_first_point() == point_1
|
|
293
|
+
assert edge_0.get_second_point() == point_2
|
|
294
|
+
assert edge_1.get_first_point() == point_2
|
|
295
|
+
assert edge_1.get_second_point() == point_3
|
|
296
|
+
assert edge_2.get_first_point() == point_3
|
|
297
|
+
|
|
298
|
+
# get_vertex_at
|
|
299
|
+
vertex_0 = polygon.get_vertex_at(0)
|
|
300
|
+
vertex_1 = polygon.get_vertex_at(1)
|
|
301
|
+
|
|
302
|
+
assert isinstance(vertex_0, Point)
|
|
303
|
+
assert isinstance(vertex_1, Point)
|
|
304
|
+
assert vertex_0 == point_1
|
|
305
|
+
assert vertex_1 == point_2
|
|
306
|
+
|
|
307
|
+
# get_edges
|
|
308
|
+
|
|
309
|
+
# get_vertices
|
|
310
|
+
|
|
311
|
+
# get_convex_hull
|
|
312
|
+
|
|
313
|
+
def test_union_with(
|
|
314
|
+
self,
|
|
315
|
+
square_1: Polygon,
|
|
316
|
+
square_4: Polygon,
|
|
317
|
+
):
|
|
318
|
+
multipolygon: MultiPolygon = square_1.union_with(square_4)
|
|
319
|
+
|
|
320
|
+
assert multipolygon is not None
|
|
321
|
+
assert isinstance(multipolygon, MultiPolygon)
|
|
322
|
+
assert multipolygon.is_defined()
|
|
323
|
+
|
|
324
|
+
def test_intersection_with(
|
|
325
|
+
self,
|
|
326
|
+
square_1: Polygon,
|
|
327
|
+
square_4: Polygon,
|
|
328
|
+
):
|
|
329
|
+
intersection: Intersection = square_1.intersection_with(square_1)
|
|
330
|
+
|
|
331
|
+
assert intersection is not None
|
|
332
|
+
assert isinstance(intersection, Intersection)
|
|
333
|
+
assert intersection.is_defined()
|
|
334
|
+
assert intersection.is_polygon()
|
|
335
|
+
|
|
336
|
+
assert intersection.as_polygon() == square_1
|
|
337
|
+
|
|
338
|
+
intersection_2: Intersection = square_1.intersection_with(square_4)
|
|
339
|
+
|
|
340
|
+
assert intersection_2 is not None
|
|
341
|
+
assert isinstance(intersection_2, Intersection)
|
|
342
|
+
assert intersection_2.is_defined()
|
|
343
|
+
assert intersection_2.is_line_string()
|
|
344
|
+
assert intersection_2.as_line_string() == LineString(
|
|
345
|
+
[Point(0.5, 0.5), Point(0.5, -0.5)]
|
|
346
|
+
)
|
|
347
|
+
assert intersection_2.get_type() == Intersection.Type.LineString
|
|
348
|
+
|
|
349
|
+
def test_difference_with(
|
|
350
|
+
self,
|
|
351
|
+
square_1: Polygon,
|
|
352
|
+
square_3: Polygon,
|
|
353
|
+
):
|
|
354
|
+
difference: Intersection = square_1.difference_with(square_1)
|
|
355
|
+
|
|
356
|
+
assert difference is not None
|
|
357
|
+
assert isinstance(difference, Intersection)
|
|
358
|
+
assert difference.is_defined()
|
|
359
|
+
assert difference.is_empty()
|
|
360
|
+
|
|
361
|
+
difference_2: Intersection = square_1.difference_with(square_3)
|
|
362
|
+
|
|
363
|
+
assert difference_2 is not None
|
|
364
|
+
assert isinstance(difference_2, Intersection)
|
|
365
|
+
assert difference_2.is_defined()
|
|
366
|
+
assert difference_2.is_polygon()
|
|
367
|
+
assert difference_2.as_polygon() == Polygon(
|
|
368
|
+
[Point(0.0, 0.5), Point(-0.5, 0.5), Point(-0.5, -0.5), Point(0.0, -0.5)]
|
|
369
|
+
)
|
|
370
|
+
assert difference_2.get_type() == Intersection.Type.Polygon
|
|
@@ -0,0 +1,104 @@
|
|
|
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.d2.Object
|
|
11
|
+
Point = mathematics.geometry.d2.object.Point
|
|
12
|
+
PointSet = mathematics.geometry.d2.object.PointSet
|
|
13
|
+
Segment = mathematics.geometry.d2.object.Segment
|
|
14
|
+
Line = mathematics.geometry.d2.object.Line
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class TestSegment:
|
|
18
|
+
def test_constructor_success(self):
|
|
19
|
+
point_1: Point = Point(-1.0, 1.0)
|
|
20
|
+
point_2: Point = Point(1.0, 1.0)
|
|
21
|
+
|
|
22
|
+
segment: Segment = Segment(point_1, point_2)
|
|
23
|
+
|
|
24
|
+
assert segment is not None
|
|
25
|
+
assert isinstance(segment, Segment)
|
|
26
|
+
assert isinstance(segment, Object)
|
|
27
|
+
assert segment.is_defined()
|
|
28
|
+
|
|
29
|
+
segment: Segment = Segment(point_1, point_1)
|
|
30
|
+
|
|
31
|
+
assert segment is not None
|
|
32
|
+
assert isinstance(segment, Segment)
|
|
33
|
+
assert isinstance(segment, Object)
|
|
34
|
+
assert segment.is_defined()
|
|
35
|
+
|
|
36
|
+
def test_defined_success(self):
|
|
37
|
+
segment: Segment = Segment.undefined()
|
|
38
|
+
|
|
39
|
+
assert segment is not None
|
|
40
|
+
assert isinstance(segment, Segment)
|
|
41
|
+
assert isinstance(segment, Object)
|
|
42
|
+
assert segment.is_defined() is False
|
|
43
|
+
|
|
44
|
+
def test_degenerate_success(self):
|
|
45
|
+
point_1: Point = Point(-1.0, 1.0)
|
|
46
|
+
point_2: Point = Point(1.0, 1.0)
|
|
47
|
+
|
|
48
|
+
segment_1: Segment = Segment(point_1, point_2)
|
|
49
|
+
segment_2: Segment = Segment(point_1, point_1)
|
|
50
|
+
|
|
51
|
+
assert segment_1.is_degenerate() is False
|
|
52
|
+
assert segment_2.is_degenerate() is True
|
|
53
|
+
|
|
54
|
+
def test_comparators_success(self):
|
|
55
|
+
point_1: Point = Point(-1.0, 1.0)
|
|
56
|
+
point_2: Point = Point(1.0, 1.0)
|
|
57
|
+
|
|
58
|
+
segment_1: Segment = Segment(point_1, point_2)
|
|
59
|
+
segment_2: Segment = Segment(point_1, point_1)
|
|
60
|
+
|
|
61
|
+
assert segment_1 == segment_1
|
|
62
|
+
assert segment_1 != segment_2
|
|
63
|
+
|
|
64
|
+
def test_getters_success(self):
|
|
65
|
+
point_1: Point = Point(-1.0, 1.0)
|
|
66
|
+
point_2: Point = Point(1.0, 1.0)
|
|
67
|
+
|
|
68
|
+
segment: Segment = Segment(point_1, point_2)
|
|
69
|
+
|
|
70
|
+
assert isinstance(segment.get_first_point(), Point)
|
|
71
|
+
assert segment.get_first_point() == point_1
|
|
72
|
+
|
|
73
|
+
assert isinstance(segment.get_second_point(), Point)
|
|
74
|
+
assert segment.get_second_point() == point_2
|
|
75
|
+
|
|
76
|
+
assert isinstance(segment.get_center(), Point)
|
|
77
|
+
assert segment.get_center() == Point(0.0, 1.0)
|
|
78
|
+
|
|
79
|
+
assert isinstance(segment.get_direction(), np.ndarray)
|
|
80
|
+
assert np.array_equal(segment.get_direction(), np.array((1.0, 0.0)))
|
|
81
|
+
|
|
82
|
+
assert segment.get_length() == 2.0
|
|
83
|
+
|
|
84
|
+
def test_distance_to_success_point(
|
|
85
|
+
self,
|
|
86
|
+
segment: Segment,
|
|
87
|
+
):
|
|
88
|
+
assert segment.distance_to(Point(0.0, 0.0)) == 0.0
|
|
89
|
+
|
|
90
|
+
def test_distance_to_success_point_set(
|
|
91
|
+
self,
|
|
92
|
+
segment: Segment,
|
|
93
|
+
):
|
|
94
|
+
assert segment.distance_to(PointSet([Point(0.0, 0.0), Point(1.0, 0.0)])) == 0.0
|
|
95
|
+
|
|
96
|
+
def test_to_line_success(
|
|
97
|
+
self,
|
|
98
|
+
segment: Segment,
|
|
99
|
+
):
|
|
100
|
+
assert segment.to_line() == Line(Point(0.0, 0.0), np.array((0.0, 1.0)))
|
|
101
|
+
|
|
102
|
+
# def test_to_string_success (self):
|
|
103
|
+
|
|
104
|
+
# def test_apply_transformation_success (self):
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Apache License 2.0
|
|
2
|
+
|
|
3
|
+
import pytest
|
|
4
|
+
|
|
5
|
+
import ostk.mathematics as mathematics
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
Object = mathematics.geometry.d2.Object
|
|
9
|
+
Format = Object.Format
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def test_geometry_d2_object_format():
|
|
13
|
+
enum_members = Format.__members__
|
|
14
|
+
|
|
15
|
+
list_keys = ["Undefined", "Standard", "WKT"]
|
|
16
|
+
|
|
17
|
+
list_values = [Format.Undefined, Format.Standard, Format.WKT]
|
|
18
|
+
|
|
19
|
+
assert list(enum_members.keys()) == list_keys
|
|
20
|
+
assert list(enum_members.values()) == list_values
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def test_geometry_d2_object_no_constructor():
|
|
24
|
+
with pytest.raises(TypeError):
|
|
25
|
+
ob = Object()
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# Apache License 2.0
|
|
2
|
+
|
|
3
|
+
import numpy as np
|
|
4
|
+
|
|
5
|
+
import pytest
|
|
6
|
+
|
|
7
|
+
import ostk.mathematics as mathematics
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
Transformation = mathematics.geometry.d2.Transformation
|
|
11
|
+
Type = Transformation.Type
|
|
12
|
+
Point = mathematics.geometry.d2.object.Point
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def test_geometry_d2_transformation_type():
|
|
16
|
+
enum_members = Type.__members__
|
|
17
|
+
|
|
18
|
+
list_keys = [
|
|
19
|
+
"Undefined",
|
|
20
|
+
"Identity",
|
|
21
|
+
"Translation",
|
|
22
|
+
"Rotation",
|
|
23
|
+
"Scaling",
|
|
24
|
+
"Reflection",
|
|
25
|
+
"Shear",
|
|
26
|
+
"Affine",
|
|
27
|
+
]
|
|
28
|
+
|
|
29
|
+
list_values = [
|
|
30
|
+
Type.Undefined,
|
|
31
|
+
Type.Identity,
|
|
32
|
+
Type.Translation,
|
|
33
|
+
Type.Rotation,
|
|
34
|
+
Type.Scaling,
|
|
35
|
+
Type.Reflection,
|
|
36
|
+
Type.Shear,
|
|
37
|
+
Type.Affine,
|
|
38
|
+
]
|
|
39
|
+
|
|
40
|
+
assert list(enum_members.keys()) == list_keys
|
|
41
|
+
assert list(enum_members.values()) == list_values
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def test_geometry_d2_transformation_constructor():
|
|
45
|
+
# Construction using python matrix
|
|
46
|
+
M = [[1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0]]
|
|
47
|
+
transformation: Transformation = Transformation(M)
|
|
48
|
+
|
|
49
|
+
assert transformation is not None
|
|
50
|
+
assert isinstance(transformation, Transformation)
|
|
51
|
+
assert transformation.is_defined()
|
|
52
|
+
|
|
53
|
+
# Construction using python numpy array
|
|
54
|
+
M = np.array(M)
|
|
55
|
+
transformation: Transformation = Transformation(M)
|
|
56
|
+
|
|
57
|
+
assert transformation is not None
|
|
58
|
+
assert isinstance(transformation, Transformation)
|
|
59
|
+
assert transformation.is_defined()
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def test_geometry_d2_transformation_comparators():
|
|
63
|
+
M1 = [[1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0]]
|
|
64
|
+
|
|
65
|
+
transformation: Transformation = Transformation(M1)
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def test_geometry_d2_transformation_defined():
|
|
69
|
+
transformation: Transformation = Transformation.undefined()
|
|
70
|
+
|
|
71
|
+
assert transformation is not None
|
|
72
|
+
assert isinstance(transformation, Transformation)
|
|
73
|
+
assert transformation.is_defined() is False
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
# def test_geometry_d2_transformation_getters ():
|
|
77
|
+
|
|
78
|
+
# def test_geometry_d2_transformation_identity ():
|
|
79
|
+
|
|
80
|
+
# def test_geometry_d2_transformation_translation ():
|
|
81
|
+
|
|
82
|
+
# def test_geometry_d2_transformation_rotation ():
|
|
83
|
+
|
|
84
|
+
# def test_geometry_d2_transformation_rotation_around ():
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# Apache License 2.0
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# Apache License 2.0
|