open-space-toolkit-mathematics 4.4.0__py311-none-manylinux2014_x86_64.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.
Potentially problematic release.
This version of open-space-toolkit-mathematics might be problematic. Click here for more details.
- open_space_toolkit_mathematics-4.4.0.dist-info/METADATA +28 -0
- open_space_toolkit_mathematics-4.4.0.dist-info/RECORD +69 -0
- open_space_toolkit_mathematics-4.4.0.dist-info/WHEEL +5 -0
- open_space_toolkit_mathematics-4.4.0.dist-info/top_level.txt +1 -0
- open_space_toolkit_mathematics-4.4.0.dist-info/zip-safe +1 -0
- ostk/__init__.py +1 -0
- ostk/mathematics/OpenSpaceToolkitMathematicsPy.cpython-311-x86_64-linux-gnu.so +0 -0
- ostk/mathematics/__init__.py +5 -0
- ostk/mathematics/__init__.pyi +11 -0
- ostk/mathematics/curve_fitting/__init__.pyi +65 -0
- ostk/mathematics/curve_fitting/interpolator.pyi +46 -0
- ostk/mathematics/geometry/__init__.pyi +178 -0
- ostk/mathematics/geometry/d2/__init__.pyi +315 -0
- ostk/mathematics/geometry/d2/object.pyi +405 -0
- ostk/mathematics/geometry/d3/__init__.pyi +351 -0
- ostk/mathematics/geometry/d3/object.pyi +837 -0
- ostk/mathematics/geometry/d3/transformation/__init__.pyi +3 -0
- ostk/mathematics/geometry/d3/transformation/rotation.pyi +421 -0
- ostk/mathematics/libopen-space-toolkit-mathematics.so.4 +0 -0
- ostk/mathematics/object.pyi +123 -0
- ostk/mathematics/py.typed +0 -0
- ostk/mathematics/solver.pyi +147 -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 +34 -0
- ostk/mathematics/test/curve_fitting/interpolator/test_cubic_spline.py +45 -0
- ostk/mathematics/test/curve_fitting/interpolator/test_interpolator.py +71 -0
- ostk/mathematics/test/curve_fitting/interpolator/test_linear.py +35 -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 +82 -0
- ostk/mathematics/test/geometry/d2/object/__init__.py +1 -0
- ostk/mathematics/test/geometry/d2/object/test_composite.py +96 -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 +101 -0
- ostk/mathematics/test/geometry/d2/object/test_point.py +213 -0
- ostk/mathematics/test/geometry/d2/object/test_point_set.py +103 -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 +116 -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 +185 -0
- ostk/mathematics/test/geometry/d3/transformation/rotation/test_rotation_matrix.py +29 -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 @@
|
|
|
1
|
+
# Apache License 2.0
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# Apache License 2.0
|
|
2
|
+
|
|
3
|
+
import pytest
|
|
4
|
+
|
|
5
|
+
from ostk.mathematics.curve_fitting import Interpolator
|
|
6
|
+
from ostk.mathematics.curve_fitting.interpolator import BarycentricRational
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
@pytest.fixture
|
|
10
|
+
def interpolator() -> BarycentricRational:
|
|
11
|
+
return BarycentricRational(
|
|
12
|
+
x=[0.0, 1.0, 2.0, 4.0, 5.0, 6.0], y=[0.0, 3.0, 6.0, 9.0, 17.0, 5.0]
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class TestBarycentricRational:
|
|
17
|
+
def test_constructor_success(self, interpolator: BarycentricRational):
|
|
18
|
+
assert interpolator is not None
|
|
19
|
+
assert isinstance(interpolator, Interpolator)
|
|
20
|
+
assert isinstance(interpolator, BarycentricRational)
|
|
21
|
+
|
|
22
|
+
def test_evaluate(self, interpolator: BarycentricRational):
|
|
23
|
+
|
|
24
|
+
assert interpolator.evaluate(0.0) == 0.0
|
|
25
|
+
assert interpolator.evaluate(1.0) == 3.0
|
|
26
|
+
assert interpolator.evaluate(2.0) == 6.0
|
|
27
|
+
assert interpolator.evaluate(4.0) == 9.0
|
|
28
|
+
assert interpolator.evaluate(5.0) == 17.0
|
|
29
|
+
assert interpolator.evaluate(6.0) == 5.0
|
|
30
|
+
|
|
31
|
+
assert (
|
|
32
|
+
interpolator.evaluate(x=[0.0, 1.0, 2.0, 4.0, 5.0, 6.0])
|
|
33
|
+
== [0.0, 3.0, 6.0, 9.0, 17.0, 5.0]
|
|
34
|
+
).all()
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# Apache License 2.0
|
|
2
|
+
|
|
3
|
+
import pytest
|
|
4
|
+
|
|
5
|
+
import numpy as np
|
|
6
|
+
|
|
7
|
+
from ostk.mathematics.curve_fitting import Interpolator
|
|
8
|
+
from ostk.mathematics.curve_fitting.interpolator import CubicSpline
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@pytest.fixture
|
|
12
|
+
def interpolator() -> CubicSpline:
|
|
13
|
+
return CubicSpline(
|
|
14
|
+
x=[0.0, 1.0, 2.0, 3.0, 4.0, 5.0], y=[0.0, 3.0, 6.0, 9.0, 17.0, 5.0]
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class TestCubicSpline:
|
|
19
|
+
def test_constructor_success(self, interpolator: CubicSpline):
|
|
20
|
+
assert interpolator is not None
|
|
21
|
+
assert isinstance(interpolator, Interpolator)
|
|
22
|
+
assert isinstance(interpolator, CubicSpline)
|
|
23
|
+
|
|
24
|
+
def test_default_constructor_2(self):
|
|
25
|
+
CubicSpline(y=[0.0, 3.0, 6.0, 9.0, 17.0, 5.0], x_0=0.0, h=1.0)
|
|
26
|
+
|
|
27
|
+
def test_evaluate(self):
|
|
28
|
+
y: list[float] = [
|
|
29
|
+
-4.632122947015880607e06,
|
|
30
|
+
-4.638362755234977230e06,
|
|
31
|
+
-4.644761115514834411e06,
|
|
32
|
+
-4.650595795951002277e06,
|
|
33
|
+
-4.655866062354639173e06,
|
|
34
|
+
-4.660571249500595033e06,
|
|
35
|
+
-4.664710761221675202e06,
|
|
36
|
+
-4.668284070493859239e06,
|
|
37
|
+
-4.671290719512360170e06,
|
|
38
|
+
-4.673730319758670405e06,
|
|
39
|
+
]
|
|
40
|
+
interpolator = CubicSpline(y, 0.0, 10.0)
|
|
41
|
+
|
|
42
|
+
for i in range(10):
|
|
43
|
+
assert pytest.approx(interpolator.evaluate(i * 10.0)) == y[i]
|
|
44
|
+
|
|
45
|
+
assert pytest.approx(interpolator.evaluate(np.linspace(0.0, 90.0, 10))) == y
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# Apache License 2.0
|
|
2
|
+
|
|
3
|
+
import pytest
|
|
4
|
+
|
|
5
|
+
from ostk.mathematics.curve_fitting import Interpolator
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
@pytest.fixture
|
|
9
|
+
def interpolation_type() -> Interpolator.Type:
|
|
10
|
+
return Interpolator.Type.Linear
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
@pytest.fixture
|
|
14
|
+
def interpolator(interpolation_type: Interpolator.Type) -> Interpolator:
|
|
15
|
+
class MyInterpolator(Interpolator):
|
|
16
|
+
def evaluate(self, x: list[float]) -> list[float]:
|
|
17
|
+
return x
|
|
18
|
+
|
|
19
|
+
def evaluate(self, x: float) -> float:
|
|
20
|
+
return x
|
|
21
|
+
|
|
22
|
+
return MyInterpolator(interpolation_type=interpolation_type)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class TestInterpolator:
|
|
26
|
+
def test_subclass(self, interpolator: Interpolator):
|
|
27
|
+
assert interpolator is not None
|
|
28
|
+
assert isinstance(interpolator, Interpolator)
|
|
29
|
+
|
|
30
|
+
def test_get_interpolation_type(
|
|
31
|
+
self,
|
|
32
|
+
interpolator: Interpolator,
|
|
33
|
+
interpolation_type: Interpolator.Type,
|
|
34
|
+
):
|
|
35
|
+
assert interpolator.get_interpolation_type() == interpolation_type
|
|
36
|
+
|
|
37
|
+
@pytest.mark.parametrize(
|
|
38
|
+
"parametrized_interpolation_type, x, y",
|
|
39
|
+
[
|
|
40
|
+
(
|
|
41
|
+
Interpolator.Type.BarycentricRational,
|
|
42
|
+
[0.0, 1.0, 2.0, 4.0, 5.0, 6.0],
|
|
43
|
+
[0.0, 3.0, 6.0, 9.0, 17.0, 5.0],
|
|
44
|
+
),
|
|
45
|
+
(
|
|
46
|
+
Interpolator.Type.CubicSpline,
|
|
47
|
+
[0.0, 1.0, 2.0, 3.0, 4.0, 5.0],
|
|
48
|
+
[0.0, 3.0, 6.0, 9.0, 17.0, 5.0],
|
|
49
|
+
),
|
|
50
|
+
(
|
|
51
|
+
Interpolator.Type.Linear,
|
|
52
|
+
[0.0, 1.0, 2.0, 4.0, 5.0, 6.0],
|
|
53
|
+
[0.0, 3.0, 6.0, 9.0, 17.0, 5.0],
|
|
54
|
+
),
|
|
55
|
+
],
|
|
56
|
+
)
|
|
57
|
+
def test_generate_interpolators(
|
|
58
|
+
self,
|
|
59
|
+
parametrized_interpolation_type: Interpolator.Type,
|
|
60
|
+
x: list[float],
|
|
61
|
+
y: list[float],
|
|
62
|
+
):
|
|
63
|
+
interpolator: Interpolator = Interpolator.generate_interpolator(
|
|
64
|
+
interpolation_type=parametrized_interpolation_type,
|
|
65
|
+
x=x,
|
|
66
|
+
y=y,
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
assert interpolator is not None
|
|
70
|
+
assert isinstance(interpolator, Interpolator)
|
|
71
|
+
assert interpolator.get_interpolation_type() == parametrized_interpolation_type
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# Apache License 2.0
|
|
2
|
+
|
|
3
|
+
import pytest
|
|
4
|
+
|
|
5
|
+
from ostk.mathematics.curve_fitting import Interpolator
|
|
6
|
+
from ostk.mathematics.curve_fitting.interpolator import Linear
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
@pytest.fixture
|
|
10
|
+
def interpolator() -> Linear:
|
|
11
|
+
return Linear(x=[0.0, 1.0, 2.0, 4.0, 5.0, 6.0], y=[0.0, 3.0, 6.0, 9.0, 17.0, 5.0])
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class TestLinear:
|
|
15
|
+
def test_constructor_success(self, interpolator: Linear):
|
|
16
|
+
assert interpolator is not None
|
|
17
|
+
assert isinstance(interpolator, Interpolator)
|
|
18
|
+
assert isinstance(interpolator, Linear)
|
|
19
|
+
|
|
20
|
+
def test_evaluate(self):
|
|
21
|
+
interpolator = Linear(
|
|
22
|
+
x=[0.0, 1.0, 2.0, 4.0, 5.0, 6.0], y=[0.0, 3.0, 6.0, 9.0, 17.0, 5.0]
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
assert interpolator.evaluate(0.0) == 0.0
|
|
26
|
+
assert interpolator.evaluate(1.0) == 3.0
|
|
27
|
+
assert interpolator.evaluate(2.0) == 6.0
|
|
28
|
+
assert interpolator.evaluate(4.0) == 9.0
|
|
29
|
+
assert interpolator.evaluate(5.0) == 17.0
|
|
30
|
+
assert interpolator.evaluate(6.0) == 5.0
|
|
31
|
+
|
|
32
|
+
assert (
|
|
33
|
+
interpolator.evaluate(x=[0.0, 1.0, 2.0, 4.0, 5.0, 6.0])
|
|
34
|
+
== [0.0, 3.0, 6.0, 9.0, 17.0, 5.0]
|
|
35
|
+
).all()
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# Apache License 2.0
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# Apache License 2.0
|
|
@@ -0,0 +1,82 @@
|
|
|
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
|
+
Point = mathematics.geometry.d2.object.Point
|
|
11
|
+
PointSet = mathematics.geometry.d2.object.PointSet
|
|
12
|
+
Line = mathematics.geometry.d2.object.Line
|
|
13
|
+
Segment = mathematics.geometry.d2.object.Segment
|
|
14
|
+
Polygon = mathematics.geometry.d2.object.Polygon
|
|
15
|
+
Composite = mathematics.geometry.d2.object.Composite
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
@pytest.fixture
|
|
19
|
+
def point() -> Point:
|
|
20
|
+
return Point(-2.0, 5.0)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
@pytest.fixture
|
|
24
|
+
def point_set() -> PointSet:
|
|
25
|
+
return PointSet([Point(1.0, 2.0), Point(2.0, 3.0)])
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
@pytest.fixture
|
|
29
|
+
def line() -> Line:
|
|
30
|
+
return Line(Point(1.0, 2.0), np.array((1.0, 1.0)))
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
@pytest.fixture
|
|
34
|
+
def segment() -> Segment:
|
|
35
|
+
return Segment(Point(0.0, 0.0), Point(0.0, 2.0))
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
@pytest.fixture
|
|
39
|
+
def polygon() -> Polygon:
|
|
40
|
+
point_1: Point = Point(-1.0, 1.0)
|
|
41
|
+
point_2: Point = Point(1.0, 1.0)
|
|
42
|
+
point_3: Point = Point(1.0, -1.0)
|
|
43
|
+
point_4: Point = Point(-1.0, -1.0)
|
|
44
|
+
|
|
45
|
+
return Polygon([point_1, point_2, point_3, point_4])
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def square(center: Point) -> Polygon:
|
|
49
|
+
point_1: Point = center + [0.5, 0.5]
|
|
50
|
+
point_2: Point = center + [0.5, -0.5]
|
|
51
|
+
point_3: Point = center + [-0.5, -0.5]
|
|
52
|
+
point_4: Point = center + [-0.5, 0.5]
|
|
53
|
+
|
|
54
|
+
return Polygon([point_1, point_2, point_3, point_4])
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
@pytest.fixture
|
|
58
|
+
def square_1() -> Polygon:
|
|
59
|
+
return square(Point(0.0, 0.0))
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
@pytest.fixture
|
|
63
|
+
def square_2() -> Polygon:
|
|
64
|
+
return square(Point(0.0, 10.0))
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
@pytest.fixture
|
|
68
|
+
def square_3() -> Polygon:
|
|
69
|
+
return square(Point(0.5, 0.0))
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
@pytest.fixture
|
|
73
|
+
def square_4() -> Polygon:
|
|
74
|
+
return square(Point(1.0, 0.0))
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
@pytest.fixture
|
|
78
|
+
def composite(polygon: Polygon, point: Point) -> Composite:
|
|
79
|
+
composite = Composite(polygon)
|
|
80
|
+
composite += Composite(point)
|
|
81
|
+
|
|
82
|
+
return composite
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# Apache License 2.0
|
|
@@ -0,0 +1,96 @@
|
|
|
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
|
+
Point = mathematics.geometry.d2.object.Point
|
|
10
|
+
Polygon = mathematics.geometry.d2.object.Polygon
|
|
11
|
+
Composite = mathematics.geometry.d2.object.Composite
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class TestComposite:
|
|
15
|
+
def test_constructor_success(self, polygon: Polygon):
|
|
16
|
+
composite: Composite = Composite(polygon)
|
|
17
|
+
|
|
18
|
+
assert composite is not None
|
|
19
|
+
assert isinstance(composite, Composite)
|
|
20
|
+
assert composite.is_defined()
|
|
21
|
+
|
|
22
|
+
def test_empty_success(self):
|
|
23
|
+
composite: Composite = Composite.empty()
|
|
24
|
+
|
|
25
|
+
assert composite is not None
|
|
26
|
+
assert isinstance(composite, Composite)
|
|
27
|
+
assert isinstance(composite, Object)
|
|
28
|
+
assert composite.is_defined()
|
|
29
|
+
assert composite.is_empty()
|
|
30
|
+
|
|
31
|
+
def test_is_defined_success(self):
|
|
32
|
+
composite: Composite = Composite.undefined()
|
|
33
|
+
|
|
34
|
+
assert composite is not None
|
|
35
|
+
assert isinstance(composite, Composite)
|
|
36
|
+
assert isinstance(composite, Object)
|
|
37
|
+
assert composite.is_defined() is False
|
|
38
|
+
|
|
39
|
+
def test_comparators_success(
|
|
40
|
+
self,
|
|
41
|
+
composite: Composite,
|
|
42
|
+
polygon: Polygon,
|
|
43
|
+
):
|
|
44
|
+
other_composite: Composite = Composite(polygon)
|
|
45
|
+
|
|
46
|
+
assert composite == composite
|
|
47
|
+
assert composite != other_composite
|
|
48
|
+
assert other_composite != composite
|
|
49
|
+
|
|
50
|
+
def test_addition_operator_success(
|
|
51
|
+
self,
|
|
52
|
+
composite: Composite,
|
|
53
|
+
polygon: Polygon,
|
|
54
|
+
):
|
|
55
|
+
assert composite is not None
|
|
56
|
+
assert isinstance(composite, Composite)
|
|
57
|
+
assert composite.is_defined()
|
|
58
|
+
assert composite.get_object_count() == 2
|
|
59
|
+
|
|
60
|
+
with pytest.raises(RuntimeError):
|
|
61
|
+
other_composite = Composite.undefined() + composite
|
|
62
|
+
|
|
63
|
+
with pytest.raises(RuntimeError):
|
|
64
|
+
other_composite = composite + Composite.undefined()
|
|
65
|
+
|
|
66
|
+
composite += composite
|
|
67
|
+
|
|
68
|
+
assert isinstance(composite, Composite)
|
|
69
|
+
assert composite.is_defined()
|
|
70
|
+
assert composite.get_object_count() == 4
|
|
71
|
+
|
|
72
|
+
with pytest.raises(RuntimeError):
|
|
73
|
+
composite += Composite.undefined()
|
|
74
|
+
|
|
75
|
+
def test_is_success(
|
|
76
|
+
self,
|
|
77
|
+
composite: Composite,
|
|
78
|
+
polygon: Polygon,
|
|
79
|
+
):
|
|
80
|
+
assert composite.is_point() is False
|
|
81
|
+
assert composite.is_polygon() is False
|
|
82
|
+
|
|
83
|
+
assert Composite(polygon).is_polygon()
|
|
84
|
+
|
|
85
|
+
def test_access_object_at_success(
|
|
86
|
+
self,
|
|
87
|
+
composite: Composite,
|
|
88
|
+
polygon: Polygon,
|
|
89
|
+
point: Point,
|
|
90
|
+
):
|
|
91
|
+
assert composite.get_object_count() == 2
|
|
92
|
+
assert composite.access_object_at(0) == polygon
|
|
93
|
+
assert composite.access_object_at(1) == point
|
|
94
|
+
|
|
95
|
+
with pytest.raises(RuntimeError):
|
|
96
|
+
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):
|