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,93 @@
|
|
|
1
|
+
# Apache License 2.0
|
|
2
|
+
|
|
3
|
+
import pytest
|
|
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 Polygon
|
|
8
|
+
from ostk.mathematics.geometry.d2.object import Composite
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class TestComposite:
|
|
12
|
+
def test_constructor_success(self, polygon: Polygon):
|
|
13
|
+
composite: Composite = Composite(polygon)
|
|
14
|
+
|
|
15
|
+
assert composite is not None
|
|
16
|
+
assert isinstance(composite, Composite)
|
|
17
|
+
assert composite.is_defined()
|
|
18
|
+
|
|
19
|
+
def test_empty_success(self):
|
|
20
|
+
composite: Composite = Composite.empty()
|
|
21
|
+
|
|
22
|
+
assert composite is not None
|
|
23
|
+
assert isinstance(composite, Composite)
|
|
24
|
+
assert isinstance(composite, Object)
|
|
25
|
+
assert composite.is_defined()
|
|
26
|
+
assert composite.is_empty()
|
|
27
|
+
|
|
28
|
+
def test_is_defined_success(self):
|
|
29
|
+
composite: Composite = Composite.undefined()
|
|
30
|
+
|
|
31
|
+
assert composite is not None
|
|
32
|
+
assert isinstance(composite, Composite)
|
|
33
|
+
assert isinstance(composite, Object)
|
|
34
|
+
assert composite.is_defined() is False
|
|
35
|
+
|
|
36
|
+
def test_comparators_success(
|
|
37
|
+
self,
|
|
38
|
+
composite: Composite,
|
|
39
|
+
polygon: Polygon,
|
|
40
|
+
):
|
|
41
|
+
other_composite: Composite = Composite(polygon)
|
|
42
|
+
|
|
43
|
+
assert composite == composite
|
|
44
|
+
assert composite != other_composite
|
|
45
|
+
assert other_composite != composite
|
|
46
|
+
|
|
47
|
+
def test_addition_operator_success(
|
|
48
|
+
self,
|
|
49
|
+
composite: Composite,
|
|
50
|
+
polygon: Polygon,
|
|
51
|
+
):
|
|
52
|
+
assert composite is not None
|
|
53
|
+
assert isinstance(composite, Composite)
|
|
54
|
+
assert composite.is_defined()
|
|
55
|
+
assert composite.get_object_count() == 2
|
|
56
|
+
|
|
57
|
+
with pytest.raises(RuntimeError):
|
|
58
|
+
other_composite = Composite.undefined() + composite
|
|
59
|
+
|
|
60
|
+
with pytest.raises(RuntimeError):
|
|
61
|
+
other_composite = composite + Composite.undefined()
|
|
62
|
+
|
|
63
|
+
composite += composite
|
|
64
|
+
|
|
65
|
+
assert isinstance(composite, Composite)
|
|
66
|
+
assert composite.is_defined()
|
|
67
|
+
assert composite.get_object_count() == 4
|
|
68
|
+
|
|
69
|
+
with pytest.raises(RuntimeError):
|
|
70
|
+
composite += Composite.undefined()
|
|
71
|
+
|
|
72
|
+
def test_is_success(
|
|
73
|
+
self,
|
|
74
|
+
composite: Composite,
|
|
75
|
+
polygon: Polygon,
|
|
76
|
+
):
|
|
77
|
+
assert composite.is_point() is False
|
|
78
|
+
assert composite.is_polygon() is False
|
|
79
|
+
|
|
80
|
+
assert Composite(polygon).is_polygon()
|
|
81
|
+
|
|
82
|
+
def test_access_object_at_success(
|
|
83
|
+
self,
|
|
84
|
+
composite: Composite,
|
|
85
|
+
polygon: Polygon,
|
|
86
|
+
point: Point,
|
|
87
|
+
):
|
|
88
|
+
assert composite.get_object_count() == 2
|
|
89
|
+
assert composite.access_object_at(0) == polygon
|
|
90
|
+
assert composite.access_object_at(1) == point
|
|
91
|
+
|
|
92
|
+
with pytest.raises(RuntimeError):
|
|
93
|
+
composite.access_object_at(2)
|
|
@@ -0,0 +1,57 @@
|
|
|
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
|
+
Line = mathematics.geometry.d2.object.Line
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class TestLine:
|
|
17
|
+
def test_constructor_success(self):
|
|
18
|
+
line = Line(
|
|
19
|
+
Point(1.0, 2.0),
|
|
20
|
+
np.array((3.4, 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(
|
|
29
|
+
self,
|
|
30
|
+
line: Line,
|
|
31
|
+
point_set: PointSet,
|
|
32
|
+
):
|
|
33
|
+
assert line.contains(point_set) is True
|
|
34
|
+
|
|
35
|
+
def test_distance_to_success_point(
|
|
36
|
+
self,
|
|
37
|
+
line: Line,
|
|
38
|
+
):
|
|
39
|
+
assert float(line.distance_to(Point(2.0, 3.0))) == pytest.approx(0.0, 1e-5)
|
|
40
|
+
assert float(line.distance_to(Point(1.0, 5.0))) == pytest.approx(2.12132, 1e-5)
|
|
41
|
+
|
|
42
|
+
def test_undefined_success(self):
|
|
43
|
+
line = Line.undefined()
|
|
44
|
+
|
|
45
|
+
assert line is not None
|
|
46
|
+
assert isinstance(line, Line)
|
|
47
|
+
assert isinstance(line, Object)
|
|
48
|
+
assert line.is_defined() is False
|
|
49
|
+
|
|
50
|
+
def test_points_success(
|
|
51
|
+
self,
|
|
52
|
+
line: Line,
|
|
53
|
+
):
|
|
54
|
+
assert line is not None
|
|
55
|
+
assert isinstance(line, Line)
|
|
56
|
+
assert isinstance(line, Object)
|
|
57
|
+
assert line.is_defined() is True
|
|
@@ -0,0 +1,174 @@
|
|
|
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.d2.Object
|
|
15
|
+
Point = mathematics.geometry.d2.object.Point
|
|
16
|
+
LineString = mathematics.geometry.d2.object.LineString
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class TestLineString:
|
|
20
|
+
def test_constructor_success(self):
|
|
21
|
+
point_1: Point = Point(-1.0, 1.0)
|
|
22
|
+
point_2: Point = Point(1.0, 1.0)
|
|
23
|
+
point_3: Point = Point(1.0, -1.0)
|
|
24
|
+
point_4: Point = Point(-1.0, -1.0)
|
|
25
|
+
|
|
26
|
+
# Construction with Array of Points using python list
|
|
27
|
+
linestring: LineString = LineString([point_1, point_2, point_3, point_4])
|
|
28
|
+
|
|
29
|
+
assert linestring is not None
|
|
30
|
+
assert isinstance(linestring, LineString)
|
|
31
|
+
assert isinstance(linestring, Object)
|
|
32
|
+
assert linestring.is_defined()
|
|
33
|
+
|
|
34
|
+
# Construction with Array of Points using python tuple
|
|
35
|
+
linestring: LineString = LineString((point_1, point_2, point_3, point_4))
|
|
36
|
+
|
|
37
|
+
assert linestring is not None
|
|
38
|
+
assert isinstance(linestring, LineString)
|
|
39
|
+
assert isinstance(linestring, Object)
|
|
40
|
+
assert linestring.is_defined()
|
|
41
|
+
|
|
42
|
+
# Construction with Array of Points using python numpy array
|
|
43
|
+
linestring: LineString = LineString(
|
|
44
|
+
np.array((point_1, point_2, point_3, point_4))
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
assert linestring is not None
|
|
48
|
+
assert isinstance(linestring, LineString)
|
|
49
|
+
assert isinstance(linestring, Object)
|
|
50
|
+
assert linestring.is_defined()
|
|
51
|
+
|
|
52
|
+
def test_empty_constructor_success(self):
|
|
53
|
+
linestring: LineString = LineString.empty()
|
|
54
|
+
|
|
55
|
+
assert linestring is not None
|
|
56
|
+
assert isinstance(linestring, LineString)
|
|
57
|
+
assert isinstance(linestring, Object)
|
|
58
|
+
assert linestring.is_defined() is False
|
|
59
|
+
assert linestring.is_empty()
|
|
60
|
+
|
|
61
|
+
def test_comparators_success(self):
|
|
62
|
+
point_1: Point = Point(-1.0, 1.0)
|
|
63
|
+
point_2: Point = Point(1.0, 1.0)
|
|
64
|
+
|
|
65
|
+
linestring_1: LineString = LineString([point_1, point_2])
|
|
66
|
+
linestring_2: LineString = LineString((point_1, point_2))
|
|
67
|
+
linestring_3: LineString = LineString(np.array([point_1, point_2]))
|
|
68
|
+
linestring_4: LineString = LineString([point_1])
|
|
69
|
+
|
|
70
|
+
assert linestring_1 == linestring_1
|
|
71
|
+
assert linestring_1 == linestring_2
|
|
72
|
+
assert linestring_1 == linestring_3
|
|
73
|
+
assert linestring_1 != linestring_4
|
|
74
|
+
assert linestring_2 != linestring_4
|
|
75
|
+
assert linestring_3 != linestring_4
|
|
76
|
+
|
|
77
|
+
def test_is_near_success(self):
|
|
78
|
+
point_1: Point = Point(-1.0, 1.0)
|
|
79
|
+
point_2: Point = Point(1.0, 1.0)
|
|
80
|
+
|
|
81
|
+
point_3: Point = Point(-0.996, 0.9995)
|
|
82
|
+
point_4: Point = Point(0.997, 0.996)
|
|
83
|
+
|
|
84
|
+
linestring_1: LineString = LineString([point_1, point_2])
|
|
85
|
+
linestring_2: LineString = LineString([point_3, point_4])
|
|
86
|
+
|
|
87
|
+
assert linestring_1.is_near(linestring_1, 10.0)
|
|
88
|
+
assert linestring_1.is_near(linestring_1, 0.1)
|
|
89
|
+
assert linestring_1.is_near(linestring_1, 1e-9)
|
|
90
|
+
|
|
91
|
+
assert linestring_2.is_near(linestring_2, 10.0)
|
|
92
|
+
assert linestring_2.is_near(linestring_2, 0.1)
|
|
93
|
+
assert linestring_2.is_near(linestring_2, 1e-9)
|
|
94
|
+
|
|
95
|
+
assert linestring_1.is_near(linestring_2, 1e-1)
|
|
96
|
+
assert linestring_1.is_near(linestring_2, 1e-2)
|
|
97
|
+
|
|
98
|
+
assert linestring_2.is_near(linestring_1, 1e-1)
|
|
99
|
+
assert linestring_2.is_near(linestring_1, 1e-2)
|
|
100
|
+
|
|
101
|
+
def test_getters_success(self):
|
|
102
|
+
point_1: Point = Point(-1.0, 1.0)
|
|
103
|
+
point_2: Point = Point(1.0, 1.0)
|
|
104
|
+
|
|
105
|
+
linestring_1: LineString = LineString([point_1])
|
|
106
|
+
linestring_2: LineString = LineString([point_1, point_2])
|
|
107
|
+
|
|
108
|
+
assert LineString.empty().get_point_count() == 0
|
|
109
|
+
assert linestring_1.get_point_count() == 1
|
|
110
|
+
assert linestring_2.get_point_count() == 2
|
|
111
|
+
|
|
112
|
+
assert linestring_1.get_point_closest_to(Point(0.0, 0.0)) == point_1
|
|
113
|
+
|
|
114
|
+
assert linestring_2.get_point_closest_to(Point(0.0, 0.0)) == point_1
|
|
115
|
+
assert linestring_2.get_point_closest_to(Point(-0.9, 1.0)) == point_1
|
|
116
|
+
assert linestring_2.get_point_closest_to(Point(0.9, 1.0)) == point_2
|
|
117
|
+
|
|
118
|
+
def test_get_point_count_success(self):
|
|
119
|
+
point_1: Point = Point(-1.0, 1.0)
|
|
120
|
+
point_2: Point = Point(1.0, 1.0)
|
|
121
|
+
|
|
122
|
+
linestring: LineString = LineString([point_1, point_2])
|
|
123
|
+
|
|
124
|
+
assert len(linestring) == 2
|
|
125
|
+
assert len(linestring) == linestring.get_point_count()
|
|
126
|
+
assert len(LineString.empty()) == 0
|
|
127
|
+
|
|
128
|
+
def test_len_success(self):
|
|
129
|
+
point_1: Point = Point(-1.0, 1.0)
|
|
130
|
+
point_2: Point = Point(1.0, 1.0)
|
|
131
|
+
|
|
132
|
+
linestring: LineString = LineString([point_1, point_2])
|
|
133
|
+
|
|
134
|
+
assert len(linestring) == 2
|
|
135
|
+
assert len(LineString.empty()) == 0
|
|
136
|
+
|
|
137
|
+
def test_getitem_success(self):
|
|
138
|
+
point_1: Point = Point(-1.0, 1.0)
|
|
139
|
+
point_2: Point = Point(1.0, 1.0)
|
|
140
|
+
|
|
141
|
+
linestring: LineString = LineString([point_1, point_2])
|
|
142
|
+
|
|
143
|
+
assert linestring[0] == point_1
|
|
144
|
+
assert linestring[1] == point_2
|
|
145
|
+
|
|
146
|
+
assert isinstance(linestring[0], Point)
|
|
147
|
+
assert isinstance(linestring[1], Point)
|
|
148
|
+
|
|
149
|
+
with pytest.raises(RuntimeError):
|
|
150
|
+
point = linestring[2]
|
|
151
|
+
|
|
152
|
+
linestring_list = list(linestring)
|
|
153
|
+
|
|
154
|
+
assert isinstance(linestring_list, list)
|
|
155
|
+
assert isinstance(linestring_list[0], Point)
|
|
156
|
+
assert isinstance(linestring_list[1], Point)
|
|
157
|
+
assert len(linestring_list) == 2
|
|
158
|
+
|
|
159
|
+
def test_iter_success(self):
|
|
160
|
+
point_1: Point = Point(-1.0, 1.0)
|
|
161
|
+
point_2: Point = Point(1.0, 1.0)
|
|
162
|
+
|
|
163
|
+
linestring: LineString = LineString([point_1, point_2])
|
|
164
|
+
|
|
165
|
+
for point in linestring:
|
|
166
|
+
assert isinstance(point, Point)
|
|
167
|
+
|
|
168
|
+
assert iter(linestring) is not None
|
|
169
|
+
assert isinstance(iter(linestring), Iterator)
|
|
170
|
+
assert isinstance(iter(linestring), Iterable)
|
|
171
|
+
|
|
172
|
+
# def test_to_string_success(self):
|
|
173
|
+
|
|
174
|
+
# def test_apply_transformation_success(self):
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
# Apache License 2.0
|
|
2
|
+
|
|
3
|
+
import numpy as np
|
|
4
|
+
|
|
5
|
+
from ostk.mathematics.geometry.d2 import Object
|
|
6
|
+
from ostk.mathematics.geometry.d2.object import Polygon
|
|
7
|
+
from ostk.mathematics.geometry.d2.object import MultiPolygon
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class TestMultipolygon:
|
|
11
|
+
def test_constructor_success(self, square_1: Polygon, square_2: Polygon):
|
|
12
|
+
# Construction using a python list of polygons
|
|
13
|
+
multipolygon: MultiPolygon = MultiPolygon([square_1, square_2])
|
|
14
|
+
|
|
15
|
+
assert multipolygon is not None
|
|
16
|
+
assert isinstance(multipolygon, MultiPolygon)
|
|
17
|
+
assert isinstance(multipolygon, Object)
|
|
18
|
+
assert multipolygon.is_defined()
|
|
19
|
+
|
|
20
|
+
# Construction using a python tuple of polygons
|
|
21
|
+
multipolygon: MultiPolygon = MultiPolygon((square_1, square_2))
|
|
22
|
+
|
|
23
|
+
assert multipolygon is not None
|
|
24
|
+
assert isinstance(multipolygon, MultiPolygon)
|
|
25
|
+
assert isinstance(multipolygon, Object)
|
|
26
|
+
assert multipolygon.is_defined()
|
|
27
|
+
|
|
28
|
+
# Construction using a python numpy array of polygons
|
|
29
|
+
multipolygon: MultiPolygon = MultiPolygon(np.array((square_1, square_2)))
|
|
30
|
+
|
|
31
|
+
assert multipolygon is not None
|
|
32
|
+
assert isinstance(multipolygon, MultiPolygon)
|
|
33
|
+
assert isinstance(multipolygon, Object)
|
|
34
|
+
assert multipolygon.is_defined()
|
|
35
|
+
|
|
36
|
+
# Construction using polygon static constructor
|
|
37
|
+
multipolygon: MultiPolygon = MultiPolygon.polygon(square_1)
|
|
38
|
+
|
|
39
|
+
assert multipolygon is not None
|
|
40
|
+
assert isinstance(multipolygon, MultiPolygon)
|
|
41
|
+
assert isinstance(multipolygon, Object)
|
|
42
|
+
assert multipolygon.is_defined()
|
|
43
|
+
|
|
44
|
+
# Construction using an array of one polygon
|
|
45
|
+
multipolygon: MultiPolygon = MultiPolygon([square_1])
|
|
46
|
+
|
|
47
|
+
assert multipolygon is not None
|
|
48
|
+
assert isinstance(multipolygon, MultiPolygon)
|
|
49
|
+
assert isinstance(multipolygon, Object)
|
|
50
|
+
assert multipolygon.is_defined()
|
|
51
|
+
|
|
52
|
+
def test_comparators_success(self, square_1: Polygon, square_2: Polygon):
|
|
53
|
+
# Multiple MultiPolygons
|
|
54
|
+
multipolygon_1: MultiPolygon = MultiPolygon([square_1, square_2])
|
|
55
|
+
multipolygon_2: MultiPolygon = MultiPolygon([square_1])
|
|
56
|
+
multipolygon_3: MultiPolygon = MultiPolygon.polygon(square_1)
|
|
57
|
+
|
|
58
|
+
assert multipolygon_1 == multipolygon_1
|
|
59
|
+
assert multipolygon_1 != multipolygon_2
|
|
60
|
+
assert multipolygon_1 != multipolygon_3
|
|
61
|
+
assert multipolygon_2 == multipolygon_3
|
|
62
|
+
|
|
63
|
+
def test_undefined_constructor_success(self):
|
|
64
|
+
multipolygon: MultiPolygon = MultiPolygon.undefined()
|
|
65
|
+
|
|
66
|
+
assert multipolygon is not None
|
|
67
|
+
assert isinstance(multipolygon, MultiPolygon)
|
|
68
|
+
assert isinstance(multipolygon, Object)
|
|
69
|
+
assert multipolygon.is_defined() is False
|
|
70
|
+
|
|
71
|
+
def test_getters_success(
|
|
72
|
+
self,
|
|
73
|
+
square_1: Polygon,
|
|
74
|
+
square_2: Polygon,
|
|
75
|
+
):
|
|
76
|
+
# Multiple Polygons
|
|
77
|
+
multipolygon: MultiPolygon = MultiPolygon([square_1, square_2])
|
|
78
|
+
|
|
79
|
+
assert multipolygon.get_polygon_count() == 2
|
|
80
|
+
assert multipolygon.get_polygons()[0] == square_1
|
|
81
|
+
assert multipolygon.get_polygons()[-1] == square_2
|
|
82
|
+
|
|
83
|
+
# One Polygon
|
|
84
|
+
multipolygon: MultiPolygon = MultiPolygon.polygon(square_1)
|
|
85
|
+
|
|
86
|
+
assert multipolygon.get_polygon_count() == 1
|
|
87
|
+
assert multipolygon.get_polygons()[0] == square_1
|
|
88
|
+
assert multipolygon.get_convex_hull() == square_1
|
|
89
|
+
|
|
90
|
+
# def test_union_with_success (self) :
|
|
91
|
+
|
|
92
|
+
# def test_to_string_success (self):
|
|
93
|
+
|
|
94
|
+
# def test_apply_transformation_success (self):
|
|
@@ -0,0 +1,213 @@
|
|
|
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
|
+
from ostk.core.type import String
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
Object = mathematics.geometry.d2.Object
|
|
15
|
+
Point = mathematics.geometry.d2.object.Point
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class TestPoint:
|
|
19
|
+
def test_constructor_success(self):
|
|
20
|
+
point: Point = Point(1.0, 2.0)
|
|
21
|
+
|
|
22
|
+
assert point is not None
|
|
23
|
+
assert isinstance(point, Point)
|
|
24
|
+
assert isinstance(point, Object)
|
|
25
|
+
assert point.is_defined()
|
|
26
|
+
|
|
27
|
+
def test_undefined_constructor_success(self):
|
|
28
|
+
point: Point = Point.undefined()
|
|
29
|
+
|
|
30
|
+
assert point is not None
|
|
31
|
+
assert isinstance(point, Point)
|
|
32
|
+
assert isinstance(point, Object)
|
|
33
|
+
assert point.is_defined() is False
|
|
34
|
+
|
|
35
|
+
def test_origin_constructor_success(self):
|
|
36
|
+
point: Point = Point.origin()
|
|
37
|
+
|
|
38
|
+
assert point is not None
|
|
39
|
+
assert isinstance(point, Point)
|
|
40
|
+
assert isinstance(point, Object)
|
|
41
|
+
assert point.is_defined()
|
|
42
|
+
assert point.x() - 0.0 <= 1e-12
|
|
43
|
+
assert point.y() - 0.0 <= 1e-12
|
|
44
|
+
|
|
45
|
+
def test_vector_constructor_success(self):
|
|
46
|
+
# Construction using a python list
|
|
47
|
+
point: Point = Point.vector([3.4, -6.7])
|
|
48
|
+
|
|
49
|
+
assert point is not None
|
|
50
|
+
assert isinstance(point, Point)
|
|
51
|
+
assert isinstance(point, Object)
|
|
52
|
+
assert point.is_defined()
|
|
53
|
+
assert (point.x() - 3.4) <= 1e-15
|
|
54
|
+
assert (point.y() + 6.7) <= 1e-15
|
|
55
|
+
|
|
56
|
+
# Construction using a python tuple
|
|
57
|
+
point: Point = Point.vector((3.4, -6.7))
|
|
58
|
+
|
|
59
|
+
assert point is not None
|
|
60
|
+
assert isinstance(point, Point)
|
|
61
|
+
assert isinstance(point, Object)
|
|
62
|
+
assert point.is_defined()
|
|
63
|
+
assert (point.x() - 3.4) <= 1e-15
|
|
64
|
+
assert (point.y() + 6.7) <= 1e-15
|
|
65
|
+
|
|
66
|
+
# Construction using a python numpy array
|
|
67
|
+
point: Point = Point.vector(np.array((3.4, -6.7)))
|
|
68
|
+
|
|
69
|
+
assert point is not None
|
|
70
|
+
assert isinstance(point, Point)
|
|
71
|
+
assert isinstance(point, Object)
|
|
72
|
+
assert point.is_defined()
|
|
73
|
+
assert (point.x() - 3.4) <= 1e-15
|
|
74
|
+
assert (point.y() + 6.7) <= 1e-15
|
|
75
|
+
|
|
76
|
+
def test_comparators_success(self):
|
|
77
|
+
point_1: Point = Point(3.4, -6.7)
|
|
78
|
+
point_2: Point = Point.vector([3.4, -6.7])
|
|
79
|
+
point_3: Point = Point(3.3, -6.5)
|
|
80
|
+
point_4: Point = Point.vector(
|
|
81
|
+
(
|
|
82
|
+
3.4,
|
|
83
|
+
-6.7,
|
|
84
|
+
)
|
|
85
|
+
)
|
|
86
|
+
point_5: Point = Point.vector(np.array((3.4, -6.7)))
|
|
87
|
+
|
|
88
|
+
assert point_1 == point_1
|
|
89
|
+
assert point_1 == point_2
|
|
90
|
+
assert point_1 != point_3
|
|
91
|
+
assert point_2 != point_3
|
|
92
|
+
assert point_1 == point_4
|
|
93
|
+
assert point_1 == point_5
|
|
94
|
+
assert point_2 == point_4
|
|
95
|
+
assert point_2 == point_5
|
|
96
|
+
assert point_3 != point_4
|
|
97
|
+
|
|
98
|
+
def test_operators_success(self):
|
|
99
|
+
point_1: Point = Point(3.4, -6.7)
|
|
100
|
+
point_2: Point = Point.vector([3.4, -6.7])
|
|
101
|
+
point_3: Point = Point.vector((3.4, -6.7))
|
|
102
|
+
point_4: Point = Point.vector(np.array((3.3, -6.5)))
|
|
103
|
+
|
|
104
|
+
point: Point = point_1 + [3.4, -6.7]
|
|
105
|
+
|
|
106
|
+
assert point is not None
|
|
107
|
+
assert isinstance(point, Point)
|
|
108
|
+
assert point.is_defined()
|
|
109
|
+
assert point.x() - (point_1.x() + point_2.x()) <= 1e-12
|
|
110
|
+
assert point.y() - (point_1.y() + point_2.y()) <= 1e-12
|
|
111
|
+
|
|
112
|
+
point: Point = point_3 + [3.4, -6.7]
|
|
113
|
+
|
|
114
|
+
assert point is not None
|
|
115
|
+
assert isinstance(point, Point)
|
|
116
|
+
assert point.is_defined()
|
|
117
|
+
assert point.x() - (point_3.x() + point_2.x()) <= 1e-12
|
|
118
|
+
assert point.y() - (point_3.y() + point_2.y()) <= 1e-12
|
|
119
|
+
|
|
120
|
+
point: Point = point_1 + (3.3, -6.5)
|
|
121
|
+
|
|
122
|
+
assert point is not None
|
|
123
|
+
assert isinstance(point, Point)
|
|
124
|
+
assert point.is_defined()
|
|
125
|
+
assert point.x() - (point_1.x() + point_4.x()) <= 1e-12
|
|
126
|
+
assert point.y() - (point_1.y() + point_4.y()) <= 1e-12
|
|
127
|
+
|
|
128
|
+
point: Point = point_1 + (0.0, 0.0)
|
|
129
|
+
|
|
130
|
+
assert point is not None
|
|
131
|
+
assert isinstance(point, Point)
|
|
132
|
+
assert point.is_defined()
|
|
133
|
+
assert point == point_1
|
|
134
|
+
|
|
135
|
+
point: Point = point_1 + [0.0, 0.0]
|
|
136
|
+
|
|
137
|
+
assert point is not None
|
|
138
|
+
assert isinstance(point, Point)
|
|
139
|
+
assert point.is_defined()
|
|
140
|
+
assert point == point_1
|
|
141
|
+
|
|
142
|
+
point: Point = point_1 + np.array((0.0, 0.0))
|
|
143
|
+
|
|
144
|
+
assert point is not None
|
|
145
|
+
assert isinstance(point, Point)
|
|
146
|
+
assert point.is_defined()
|
|
147
|
+
assert point == point_1
|
|
148
|
+
|
|
149
|
+
# point: Point = point_1 - point_1
|
|
150
|
+
|
|
151
|
+
# assert point is not None
|
|
152
|
+
# assert isinstance(point, Point)
|
|
153
|
+
# assert isinstance(point, Object)
|
|
154
|
+
# assert point.is_defined()
|
|
155
|
+
# assert point.x == 0.0
|
|
156
|
+
# assert point.y == 0.0
|
|
157
|
+
# assert point == Point.origin()
|
|
158
|
+
|
|
159
|
+
def test_is_defined(self):
|
|
160
|
+
point: Point = Point(3.5, 5.6)
|
|
161
|
+
|
|
162
|
+
assert point.is_defined()
|
|
163
|
+
assert Point.undefined().is_defined() is False
|
|
164
|
+
|
|
165
|
+
def test_is_near(self):
|
|
166
|
+
point_1: Point = Point(3.5, 5.6)
|
|
167
|
+
point_2: Point = Point(3.4999999999, 5.5999999999)
|
|
168
|
+
|
|
169
|
+
assert point_1.is_near(point_2, 1e-8) is True
|
|
170
|
+
assert point_2.is_near(point_1, 1e-8) is True
|
|
171
|
+
assert point_1.is_near(point_2, 1e-11) is False
|
|
172
|
+
assert point_1.is_near(point_2, 1e-9) is True
|
|
173
|
+
|
|
174
|
+
def test_coordinates(self):
|
|
175
|
+
point: Point = Point(4.5, 34.5)
|
|
176
|
+
|
|
177
|
+
assert point.x() == 4.5
|
|
178
|
+
assert point.y() == 34.5
|
|
179
|
+
|
|
180
|
+
def test_as_vector(self):
|
|
181
|
+
point: Point = Point(3.4, -3.5)
|
|
182
|
+
vec: np.ndarray = point.as_vector()
|
|
183
|
+
|
|
184
|
+
assert vec is not None
|
|
185
|
+
assert isinstance(vec, np.ndarray)
|
|
186
|
+
|
|
187
|
+
def test_distance_to(self):
|
|
188
|
+
point_1: Point = Point(0.0, 4.0)
|
|
189
|
+
point_2: Point = Point(0.0, 3.0)
|
|
190
|
+
point_3: Point = Point(3.0, 0.0)
|
|
191
|
+
point_4: Point = Point(1.1, 1.0)
|
|
192
|
+
|
|
193
|
+
assert point_1.distance_to(point_2) == 1.0
|
|
194
|
+
assert point_2.distance_to(point_1) == 1.0
|
|
195
|
+
|
|
196
|
+
assert point_1.distance_to(point_3) == 5.0
|
|
197
|
+
assert point_3.distance_to(point_1) == 5.0
|
|
198
|
+
|
|
199
|
+
assert point_1.distance_to(point_4) == math.sqrt((1.1 * 1.1) + 9.0)
|
|
200
|
+
assert point_4.distance_to(point_1) == math.sqrt((1.1 * 1.1) + 9.0)
|
|
201
|
+
|
|
202
|
+
with pytest.raises(TypeError):
|
|
203
|
+
point_1.distance_to((0.0, 0.0))
|
|
204
|
+
|
|
205
|
+
def test_to_string(self):
|
|
206
|
+
point: Point = Point(3.0, 5.0)
|
|
207
|
+
|
|
208
|
+
assert isinstance(point.to_string(), String)
|
|
209
|
+
assert point.to_string() == "[3.0, 5.0]"
|
|
210
|
+
|
|
211
|
+
# def test_apply_transformation_success (self):
|
|
212
|
+
|
|
213
|
+
# point: Point = Point(4.5, 5.4)
|