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,262 @@
|
|
|
1
|
+
# Apache License 2.0
|
|
2
|
+
|
|
3
|
+
import pytest
|
|
4
|
+
|
|
5
|
+
import numpy as np
|
|
6
|
+
|
|
7
|
+
from ostk.mathematics.geometry import Angle
|
|
8
|
+
from ostk.mathematics.geometry.d2.object import Point as Point2d
|
|
9
|
+
from ostk.mathematics.geometry.d2.object import Polygon as Polygon2d
|
|
10
|
+
from ostk.mathematics.geometry.d3 import Object as Object
|
|
11
|
+
from ostk.mathematics.geometry.d3.object import Composite as Composite
|
|
12
|
+
from ostk.mathematics.geometry.d3.object import Point
|
|
13
|
+
from ostk.mathematics.geometry.d3.object import PointSet
|
|
14
|
+
from ostk.mathematics.geometry.d3.object import Line
|
|
15
|
+
from ostk.mathematics.geometry.d3.object import Ray
|
|
16
|
+
from ostk.mathematics.geometry.d3.object import Segment
|
|
17
|
+
from ostk.mathematics.geometry.d3.object import LineString
|
|
18
|
+
from ostk.mathematics.geometry.d3.object import Polygon
|
|
19
|
+
from ostk.mathematics.geometry.d3.object import Plane
|
|
20
|
+
from ostk.mathematics.geometry.d3.object import Sphere
|
|
21
|
+
from ostk.mathematics.geometry.d3.object import Ellipsoid
|
|
22
|
+
from ostk.mathematics.geometry.d3.object import Pyramid
|
|
23
|
+
from ostk.mathematics.geometry.d3.object import Cone
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
@pytest.fixture
|
|
27
|
+
def point() -> Point:
|
|
28
|
+
return Point(1.0, 2.0, 1.0)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
@pytest.fixture
|
|
32
|
+
def point_set(point: Point) -> PointSet:
|
|
33
|
+
return PointSet([point])
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
@pytest.fixture
|
|
37
|
+
def direction() -> np.ndarray:
|
|
38
|
+
return np.array([1.0, 0.0, 0.0])
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
@pytest.fixture
|
|
42
|
+
def line(point: Point, direction: np.ndarray) -> Line:
|
|
43
|
+
return Line(point, direction)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
@pytest.fixture
|
|
47
|
+
def ray(point: Point, direction: np.ndarray) -> Ray:
|
|
48
|
+
return Ray(point, direction)
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
@pytest.fixture
|
|
52
|
+
def segment():
|
|
53
|
+
point_1: Point = Point(1.0, 2.0, 1.0)
|
|
54
|
+
point_2: Point = Point(1.0, 1.0, 1.0)
|
|
55
|
+
return Segment(point_1, point_2)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
@pytest.fixture
|
|
59
|
+
def line_string() -> LineString:
|
|
60
|
+
point_1: Point = Point(1.0, 2.0, 1.0)
|
|
61
|
+
point_2: Point = Point(1.0, 1.0, 1.0)
|
|
62
|
+
return LineString([point_1, point_2])
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
@pytest.fixture
|
|
66
|
+
def polygon2d() -> Polygon2d:
|
|
67
|
+
point_1: Point2d = Point2d(-1.0, 1.0)
|
|
68
|
+
point_2: Point2d = Point2d(1.0, 1.0)
|
|
69
|
+
point_3: Point2d = Point2d(1.0, -1.0)
|
|
70
|
+
point_4: Point2d = Point2d(-1.0, -1.0)
|
|
71
|
+
return Polygon2d([point_1, point_2, point_3, point_4])
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
@pytest.fixture
|
|
75
|
+
def polygon(point: Point, polygon2d: Polygon2d) -> Polygon:
|
|
76
|
+
vector_1 = (1.0, 0.0, 0.0)
|
|
77
|
+
vector_2 = (0.0, 1.0, 0.0)
|
|
78
|
+
return Polygon(polygon2d, point, vector_1, vector_2)
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
@pytest.fixture
|
|
82
|
+
def plane(point: Point, direction: np.ndarray) -> Plane:
|
|
83
|
+
return Plane(point, direction)
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
@pytest.fixture
|
|
87
|
+
def sphere(point: Point) -> Sphere:
|
|
88
|
+
return Sphere(point, 1.0)
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
@pytest.fixture
|
|
92
|
+
def ellipsoid(point: Point) -> Ellipsoid:
|
|
93
|
+
return Ellipsoid(point, 1.0, 1.0, 1.0)
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
@pytest.fixture
|
|
97
|
+
def pyramid(polygon: Polygon, point: Point) -> Pyramid:
|
|
98
|
+
return Pyramid(polygon, point)
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
@pytest.fixture
|
|
102
|
+
def cone(point: Point, direction: np.ndarray) -> Cone:
|
|
103
|
+
return Cone(point, direction, Angle.degrees(5.0))
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
@pytest.fixture
|
|
107
|
+
def composite_with_polygon(segment: Segment, polygon: Polygon) -> Composite:
|
|
108
|
+
composite_1 = Composite(segment)
|
|
109
|
+
return composite_1 + Composite(polygon)
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
class Test3DComposite:
|
|
113
|
+
@pytest.mark.parametrize(
|
|
114
|
+
"geometry_name",
|
|
115
|
+
[
|
|
116
|
+
("point"),
|
|
117
|
+
("point_set"),
|
|
118
|
+
("line"),
|
|
119
|
+
("ray"),
|
|
120
|
+
("segment"),
|
|
121
|
+
("line_string"),
|
|
122
|
+
("polygon"),
|
|
123
|
+
("plane"),
|
|
124
|
+
("sphere"),
|
|
125
|
+
("ellipsoid"),
|
|
126
|
+
("pyramid"),
|
|
127
|
+
("cone"),
|
|
128
|
+
],
|
|
129
|
+
)
|
|
130
|
+
def test_geometry_d3_object_composite_constructor(self, geometry_name: str, request):
|
|
131
|
+
geometry = request.getfixturevalue(geometry_name)
|
|
132
|
+
composite: Composite = Composite(geometry)
|
|
133
|
+
|
|
134
|
+
assert composite is not None
|
|
135
|
+
assert isinstance(composite, Composite)
|
|
136
|
+
assert composite.is_defined()
|
|
137
|
+
|
|
138
|
+
def test_geometry_d3_object_composite_empty(self):
|
|
139
|
+
composite: Composite = Composite.empty()
|
|
140
|
+
|
|
141
|
+
assert composite is not None
|
|
142
|
+
assert isinstance(composite, Composite)
|
|
143
|
+
assert isinstance(composite, Object)
|
|
144
|
+
assert composite.is_defined()
|
|
145
|
+
assert composite.is_empty()
|
|
146
|
+
|
|
147
|
+
def test_geometry_d3_object_composite_comparators(self):
|
|
148
|
+
point_1: Point = Point(1.0, 2.0, 1.0)
|
|
149
|
+
point_2: Point = Point(1.0, 1.0, 1.0)
|
|
150
|
+
point_3: Point = Point(1.0, 4.0, 1.0)
|
|
151
|
+
|
|
152
|
+
segment_1: Segment = Segment(point_1, point_2)
|
|
153
|
+
segment_2: Segment = Segment(point_1, point_3)
|
|
154
|
+
segment_3: Segment = Segment(point_2, point_1)
|
|
155
|
+
|
|
156
|
+
composite_1 = Composite(segment_1)
|
|
157
|
+
composite_2 = Composite(segment_2)
|
|
158
|
+
composite_3 = Composite(segment_3)
|
|
159
|
+
|
|
160
|
+
assert composite_1 == composite_3
|
|
161
|
+
assert composite_1 != composite_2
|
|
162
|
+
assert composite_2 != composite_3
|
|
163
|
+
|
|
164
|
+
def tes_geometry_d3_object_composite_addition_operator(self):
|
|
165
|
+
point_1: Point = Point(1.0, 2.0, 1.0)
|
|
166
|
+
point_2: Point = Point(1.0, 1.0, 1.0)
|
|
167
|
+
point_3: Point = Point(1.0, 4.0, 1.0)
|
|
168
|
+
|
|
169
|
+
segment_1: Segment = Segment(point_1, point_2)
|
|
170
|
+
segment_2: Segment = Segment(point_1, point_3)
|
|
171
|
+
|
|
172
|
+
composite_1 = Composite(segment_1)
|
|
173
|
+
composite_2 = Composite(segment_2)
|
|
174
|
+
|
|
175
|
+
composite_3 = composite_1 + composite_2
|
|
176
|
+
|
|
177
|
+
assert composite_3 is not None
|
|
178
|
+
assert isinstance(composite_3, Composite)
|
|
179
|
+
assert composite_3.is_defined()
|
|
180
|
+
assert composite_3.get_object_count() == 2
|
|
181
|
+
|
|
182
|
+
with pytest.raises(RuntimeError):
|
|
183
|
+
composite = Composite.undefined() + composite_1
|
|
184
|
+
|
|
185
|
+
with pytest.raises(RuntimeError):
|
|
186
|
+
composite = composite_1 + Composite.undefined()
|
|
187
|
+
|
|
188
|
+
composite_3 += composite_1
|
|
189
|
+
|
|
190
|
+
assert isinstance(composite_3, Composite)
|
|
191
|
+
assert composite_3.is_defined()
|
|
192
|
+
assert composite_3.get_object_count() == 3
|
|
193
|
+
|
|
194
|
+
with pytest.raises(RuntimeError):
|
|
195
|
+
composite_3 += Composite.undefined()
|
|
196
|
+
|
|
197
|
+
def test_geometry_d3_object_composite_access_object_at(
|
|
198
|
+
self,
|
|
199
|
+
composite_with_polygon: Composite,
|
|
200
|
+
):
|
|
201
|
+
object: Object = composite_with_polygon.access_object_at(0)
|
|
202
|
+
|
|
203
|
+
assert object is not None
|
|
204
|
+
assert isinstance(object, Object)
|
|
205
|
+
assert isinstance(object, Segment)
|
|
206
|
+
|
|
207
|
+
object_2: Object = composite_with_polygon.access_object_at(1)
|
|
208
|
+
|
|
209
|
+
assert object_2 is not None
|
|
210
|
+
assert isinstance(object_2, Object)
|
|
211
|
+
assert isinstance(object_2, Polygon)
|
|
212
|
+
|
|
213
|
+
with pytest.raises(RuntimeError):
|
|
214
|
+
composite_with_polygon.access_object_at(2)
|
|
215
|
+
|
|
216
|
+
@pytest.mark.parametrize(
|
|
217
|
+
"geometry_name",
|
|
218
|
+
[
|
|
219
|
+
("point"),
|
|
220
|
+
("point_set"),
|
|
221
|
+
("line"),
|
|
222
|
+
("ray"),
|
|
223
|
+
("segment"),
|
|
224
|
+
("line_string"),
|
|
225
|
+
("polygon"),
|
|
226
|
+
("plane"),
|
|
227
|
+
("sphere"),
|
|
228
|
+
("ellipsoid"),
|
|
229
|
+
("pyramid"),
|
|
230
|
+
("cone"),
|
|
231
|
+
],
|
|
232
|
+
)
|
|
233
|
+
def test_geometry_d3_object_composite_is(self, geometry_name: str, request):
|
|
234
|
+
geometry = request.getfixturevalue(geometry_name)
|
|
235
|
+
composite: Composite = Composite(geometry)
|
|
236
|
+
|
|
237
|
+
assert composite.is_defined()
|
|
238
|
+
assert getattr(composite, f"is_{geometry_name}")()
|
|
239
|
+
|
|
240
|
+
@pytest.mark.parametrize(
|
|
241
|
+
"geometry_name",
|
|
242
|
+
[
|
|
243
|
+
("point"),
|
|
244
|
+
("point_set"),
|
|
245
|
+
("line"),
|
|
246
|
+
("ray"),
|
|
247
|
+
("segment"),
|
|
248
|
+
("line_string"),
|
|
249
|
+
("polygon"),
|
|
250
|
+
("plane"),
|
|
251
|
+
("sphere"),
|
|
252
|
+
("ellipsoid"),
|
|
253
|
+
("pyramid"),
|
|
254
|
+
("cone"),
|
|
255
|
+
],
|
|
256
|
+
)
|
|
257
|
+
def test_geometry_d3_object_composite_as(self, geometry_name: str, request):
|
|
258
|
+
geometry = request.getfixturevalue(geometry_name)
|
|
259
|
+
composite: Composite = Composite(geometry)
|
|
260
|
+
|
|
261
|
+
assert composite.is_defined()
|
|
262
|
+
assert getattr(composite, f"as_{geometry_name}")().is_defined()
|
|
@@ -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_object_cuboid ():
|
|
@@ -0,0 +1,68 @@
|
|
|
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
|
+
Line = mathematics.geometry.d3.object.Line
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class TestLine:
|
|
17
|
+
def test_constructor_success(self):
|
|
18
|
+
line = Line(
|
|
19
|
+
Point(1.0, 2.0, 3.0),
|
|
20
|
+
np.array((3.4, -6.7, 1.0)),
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
assert line is not None
|
|
24
|
+
assert isinstance(line, Line)
|
|
25
|
+
assert isinstance(line, Object)
|
|
26
|
+
assert line.is_defined()
|
|
27
|
+
|
|
28
|
+
def test_contains_success_point_set(self):
|
|
29
|
+
line = Line(
|
|
30
|
+
Point(1.0, 2.0, 3.0),
|
|
31
|
+
np.array((1.0, 1.0, 1.0)),
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
point_set = PointSet(
|
|
35
|
+
[
|
|
36
|
+
Point(1.0, 2.0, 3.0),
|
|
37
|
+
Point(2.0, 3.0, 4.0),
|
|
38
|
+
]
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
assert line.contains(point_set) is True
|
|
42
|
+
|
|
43
|
+
def test_distance_to_success_point(self):
|
|
44
|
+
line = Line(
|
|
45
|
+
Point(1.0, 2.0, 3.0),
|
|
46
|
+
np.array((1.0, 1.0, 1.0)),
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
assert float(line.distance_to(Point(2.0, 3.0, 4.0))) == pytest.approx(0.0, 1e-10)
|
|
50
|
+
|
|
51
|
+
def test_undefined_success(self):
|
|
52
|
+
line = Line.undefined()
|
|
53
|
+
|
|
54
|
+
assert line is not None
|
|
55
|
+
assert isinstance(line, Line)
|
|
56
|
+
assert isinstance(line, Object)
|
|
57
|
+
assert line.is_defined() is False
|
|
58
|
+
|
|
59
|
+
def test_points_success(self):
|
|
60
|
+
line = Line.points(
|
|
61
|
+
Point(1.0, 2.0, 3.0),
|
|
62
|
+
Point(2.0, 4.0, 4.0),
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
assert line is not None
|
|
66
|
+
assert isinstance(line, Line)
|
|
67
|
+
assert isinstance(line, Object)
|
|
68
|
+
assert line.is_defined() is True
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
# Apache License 2.0
|
|
2
|
+
|
|
3
|
+
from collections.abc import Iterator, Iterable
|
|
4
|
+
|
|
5
|
+
import numpy as np
|
|
6
|
+
|
|
7
|
+
import pytest
|
|
8
|
+
|
|
9
|
+
from ostk.core.type import String
|
|
10
|
+
|
|
11
|
+
import ostk.mathematics as mathematics
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
Object = mathematics.geometry.d3.Object
|
|
15
|
+
Point = mathematics.geometry.d3.object.Point
|
|
16
|
+
LineString = mathematics.geometry.d3.object.LineString
|
|
17
|
+
Transformation = mathematics.geometry.d3.Transformation
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class TestLineString:
|
|
21
|
+
def test_constructor_success(self):
|
|
22
|
+
point_1: Point = Point(-1.0, 1.0, 1.0)
|
|
23
|
+
point_2: Point = Point(1.0, 1.0, -1.0)
|
|
24
|
+
point_3: Point = Point(1.0, -1.0, 1.0)
|
|
25
|
+
point_4: Point = Point(-1.0, -1.0, 0.0)
|
|
26
|
+
|
|
27
|
+
# Construction with Array of Points using python list
|
|
28
|
+
linestring: LineString = LineString([point_1, point_2, point_3, point_4])
|
|
29
|
+
|
|
30
|
+
assert linestring is not None
|
|
31
|
+
assert isinstance(linestring, LineString)
|
|
32
|
+
assert isinstance(linestring, Object)
|
|
33
|
+
assert linestring.is_defined()
|
|
34
|
+
|
|
35
|
+
# Construction with Array of Points using python tuple
|
|
36
|
+
linestring: LineString = LineString((point_1, point_2, point_3, point_4))
|
|
37
|
+
|
|
38
|
+
assert linestring is not None
|
|
39
|
+
assert isinstance(linestring, LineString)
|
|
40
|
+
assert isinstance(linestring, Object)
|
|
41
|
+
assert linestring.is_defined()
|
|
42
|
+
|
|
43
|
+
# Construction with Array of Points using python numpy array
|
|
44
|
+
linestring: LineString = LineString(
|
|
45
|
+
np.array((point_1, point_2, point_3, point_4))
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
assert linestring is not None
|
|
49
|
+
assert isinstance(linestring, LineString)
|
|
50
|
+
assert isinstance(linestring, Object)
|
|
51
|
+
assert linestring.is_defined()
|
|
52
|
+
|
|
53
|
+
def test_empty_success(self):
|
|
54
|
+
linestring: LineString = LineString.empty()
|
|
55
|
+
|
|
56
|
+
assert linestring is not None
|
|
57
|
+
assert isinstance(linestring, LineString)
|
|
58
|
+
assert isinstance(linestring, Object)
|
|
59
|
+
assert linestring.is_defined() is False
|
|
60
|
+
assert linestring.is_empty()
|
|
61
|
+
|
|
62
|
+
def test_comparators_success(self):
|
|
63
|
+
point_1: Point = Point(-1.0, 1.0, 0.0)
|
|
64
|
+
point_2: Point = Point(1.0, 1.0, -1.0)
|
|
65
|
+
|
|
66
|
+
linestring_1: LineString = LineString([point_1, point_2])
|
|
67
|
+
linestring_2: LineString = LineString((point_1, point_2))
|
|
68
|
+
linestring_3: LineString = LineString(np.array([point_1, point_2]))
|
|
69
|
+
linestring_4: LineString = LineString([point_1])
|
|
70
|
+
|
|
71
|
+
assert linestring_1 == linestring_1
|
|
72
|
+
assert linestring_1 == linestring_2
|
|
73
|
+
assert linestring_1 == linestring_3
|
|
74
|
+
assert linestring_1 != linestring_4
|
|
75
|
+
assert linestring_2 != linestring_4
|
|
76
|
+
assert linestring_3 != linestring_4
|
|
77
|
+
|
|
78
|
+
def test_is_near_success(self):
|
|
79
|
+
point_1: Point = Point(-1.0, 1.0, 0.0)
|
|
80
|
+
point_2: Point = Point(1.0, 1.0, 0.0)
|
|
81
|
+
|
|
82
|
+
point_3: Point = Point(-0.996, 0.9995, 0.0)
|
|
83
|
+
point_4: Point = Point(0.997, 0.996, 0.0)
|
|
84
|
+
|
|
85
|
+
linestring_1: LineString = LineString([point_1, point_2])
|
|
86
|
+
linestring_2: LineString = LineString([point_3, point_4])
|
|
87
|
+
|
|
88
|
+
assert linestring_1.is_near(linestring_1, 10.0)
|
|
89
|
+
assert linestring_1.is_near(linestring_1, 0.1)
|
|
90
|
+
assert linestring_1.is_near(linestring_1, 1e-9)
|
|
91
|
+
|
|
92
|
+
assert linestring_2.is_near(linestring_2, 10.0)
|
|
93
|
+
assert linestring_2.is_near(linestring_2, 0.1)
|
|
94
|
+
assert linestring_2.is_near(linestring_2, 1e-9)
|
|
95
|
+
|
|
96
|
+
assert linestring_1.is_near(linestring_2, 1e-1)
|
|
97
|
+
assert linestring_1.is_near(linestring_2, 1e-2)
|
|
98
|
+
|
|
99
|
+
assert linestring_2.is_near(linestring_1, 1e-1)
|
|
100
|
+
assert linestring_2.is_near(linestring_1, 1e-2)
|
|
101
|
+
|
|
102
|
+
def test_getters_success(self):
|
|
103
|
+
point_1: Point = Point(-1.0, 1.0, 0.0)
|
|
104
|
+
point_2: Point = Point(1.0, 1.0, 0.0)
|
|
105
|
+
|
|
106
|
+
linestring_1: LineString = LineString([point_1])
|
|
107
|
+
linestring_2: LineString = LineString([point_1, point_2])
|
|
108
|
+
|
|
109
|
+
assert LineString.empty().get_point_count() == 0
|
|
110
|
+
assert linestring_1.get_point_count() == 1
|
|
111
|
+
assert linestring_2.get_point_count() == 2
|
|
112
|
+
|
|
113
|
+
assert linestring_1.get_point_closest_to(Point(0.0, 0.0, 0.0)) == point_1
|
|
114
|
+
|
|
115
|
+
assert linestring_2.get_point_closest_to(Point(0.0, 0.0, 0.0)) == point_1
|
|
116
|
+
assert linestring_2.get_point_closest_to(Point(-0.9, 1.0, 0.0)) == point_1
|
|
117
|
+
assert linestring_2.get_point_closest_to(Point(0.9, 1.0, 0.0)) == point_2
|
|
118
|
+
|
|
119
|
+
def test_len_success(self):
|
|
120
|
+
point_1: Point = Point(-1.0, 1.0, 0.0)
|
|
121
|
+
point_2: Point = Point(1.0, 1.0, 0.0)
|
|
122
|
+
|
|
123
|
+
linestring: LineString = LineString([point_1, point_2])
|
|
124
|
+
|
|
125
|
+
assert len(linestring) == 2
|
|
126
|
+
assert len(linestring) == linestring.get_point_count()
|
|
127
|
+
assert len(LineString.empty()) == 0
|
|
128
|
+
|
|
129
|
+
linestring: LineString = LineString([point_1, point_1])
|
|
130
|
+
assert len(linestring) == 2
|
|
131
|
+
assert len(linestring) == linestring.get_point_count()
|
|
132
|
+
|
|
133
|
+
def test_getitem_success(self):
|
|
134
|
+
point_1: Point = Point(-1.0, 1.0, 0.0)
|
|
135
|
+
point_2: Point = Point(1.0, 1.0, 1.0)
|
|
136
|
+
|
|
137
|
+
linestring: LineString = LineString([point_1, point_2])
|
|
138
|
+
|
|
139
|
+
assert linestring[0] == point_1
|
|
140
|
+
assert linestring[1] == point_2
|
|
141
|
+
|
|
142
|
+
assert isinstance(linestring[0], Point)
|
|
143
|
+
assert isinstance(linestring[1], Point)
|
|
144
|
+
|
|
145
|
+
with pytest.raises(RuntimeError):
|
|
146
|
+
point = linestring[2]
|
|
147
|
+
|
|
148
|
+
linestring_list = list(linestring)
|
|
149
|
+
|
|
150
|
+
assert isinstance(linestring_list, list)
|
|
151
|
+
assert isinstance(linestring_list[0], Point)
|
|
152
|
+
assert isinstance(linestring_list[1], Point)
|
|
153
|
+
assert len(linestring_list) == 2
|
|
154
|
+
|
|
155
|
+
def test_iter_success(self):
|
|
156
|
+
point_1: Point = Point(-1.0, 1.0, 0.0)
|
|
157
|
+
point_2: Point = Point(1.0, 1.0, 1.0)
|
|
158
|
+
|
|
159
|
+
linestring: LineString = LineString([point_1, point_2])
|
|
160
|
+
|
|
161
|
+
for point in linestring:
|
|
162
|
+
assert isinstance(point, Point)
|
|
163
|
+
|
|
164
|
+
assert iter(linestring) is not None
|
|
165
|
+
assert isinstance(iter(linestring), Iterator)
|
|
166
|
+
assert isinstance(iter(linestring), Iterable)
|
|
167
|
+
|
|
168
|
+
# def test_apply_transformation_success(self):
|