codac4matlab 2.0.0.dev25__cp314-cp314-manylinux_2_26_aarch64.manylinux_2_28_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.
- codac4matlab/__init__.py +4 -0
- codac4matlab/_core.cpython-314-aarch64-linux-gnu.so +0 -0
- codac4matlab/_graphics.cpython-314-aarch64-linux-gnu.so +0 -0
- codac4matlab/_unsupported.cpython-314-aarch64-linux-gnu.so +0 -0
- codac4matlab/core/__init__.py +588 -0
- codac4matlab/empty.cpython-314-aarch64-linux-gnu.so +0 -0
- codac4matlab/graphics/__init__.py +1 -0
- codac4matlab/tests/__init__.py +1 -0
- codac4matlab/tests/test_AnalyticFunction.py +442 -0
- codac4matlab/tests/test_AnalyticTraj.py +62 -0
- codac4matlab/tests/test_Approx.py +27 -0
- codac4matlab/tests/test_BoolInterval.py +96 -0
- codac4matlab/tests/test_Color.py +77 -0
- codac4matlab/tests/test_ConvexPolygon.py +300 -0
- codac4matlab/tests/test_CtcAction.py +30 -0
- codac4matlab/tests/test_CtcCartProd.py +39 -0
- codac4matlab/tests/test_CtcCtcBoundary.py +48 -0
- codac4matlab/tests/test_CtcDeriv.py +434 -0
- codac4matlab/tests/test_CtcEval.py +214 -0
- codac4matlab/tests/test_CtcFixpoint.py +65 -0
- codac4matlab/tests/test_CtcInter.py +39 -0
- codac4matlab/tests/test_CtcInverse.py +213 -0
- codac4matlab/tests/test_CtcInverseNotIn.py +129 -0
- codac4matlab/tests/test_CtcLazy.py +50 -0
- codac4matlab/tests/test_CtcPolygon.py +91 -0
- codac4matlab/tests/test_CtcSegment.py +104 -0
- codac4matlab/tests/test_Ellipsoid.py +20 -0
- codac4matlab/tests/test_GaussJordan.py +34 -0
- codac4matlab/tests/test_IntFullPivLU.py +84 -0
- codac4matlab/tests/test_Interval.py +254 -0
- codac4matlab/tests/test_IntervalMatrix.py +664 -0
- codac4matlab/tests/test_IntervalVector.py +657 -0
- codac4matlab/tests/test_Interval_operations.py +293 -0
- codac4matlab/tests/test_Matrix.py +81 -0
- codac4matlab/tests/test_OctaSym.py +41 -0
- codac4matlab/tests/test_Parallelepiped.py +35 -0
- codac4matlab/tests/test_Parallelepiped_eval.py +62 -0
- codac4matlab/tests/test_Polygon.py +120 -0
- codac4matlab/tests/test_SampledTraj.py +135 -0
- codac4matlab/tests/test_Segment.py +138 -0
- codac4matlab/tests/test_SepCartProd.py +34 -0
- codac4matlab/tests/test_SepCtcBoundary.py +52 -0
- codac4matlab/tests/test_SepInverse.py +104 -0
- codac4matlab/tests/test_SepPolygon.py +102 -0
- codac4matlab/tests/test_SepProj.py +39 -0
- codac4matlab/tests/test_SepTransform.py +41 -0
- codac4matlab/tests/test_Slice.py +78 -0
- codac4matlab/tests/test_Slice_polygon.py +208 -0
- codac4matlab/tests/test_SlicedTube.py +562 -0
- codac4matlab/tests/test_SlicedTube_integral.py +380 -0
- codac4matlab/tests/test_TDomain.py +115 -0
- codac4matlab/tests/test_Vector.py +41 -0
- codac4matlab/tests/test_arithmetic_add.py +54 -0
- codac4matlab/tests/test_arithmetic_div.py +46 -0
- codac4matlab/tests/test_arithmetic_mul.py +114 -0
- codac4matlab/tests/test_arithmetic_sub.py +54 -0
- codac4matlab/tests/test_capd.py +19 -0
- codac4matlab/tests/test_cart_prod.py +38 -0
- codac4matlab/tests/test_eigen.py +19 -0
- codac4matlab/tests/test_geometry.py +136 -0
- codac4matlab/tests/test_hull.py +35 -0
- codac4matlab/tests/test_ibex.py +19 -0
- codac4matlab/tests/test_inversion.py +57 -0
- codac4matlab/tests/test_linear_ctc.py +77 -0
- codac4matlab/tests/test_operators.py +377 -0
- codac4matlab/tests/test_peibos.py +83 -0
- codac4matlab/tests/test_predefined_tubes.py +193 -0
- codac4matlab/tests/test_serialization.py +30 -0
- codac4matlab/tests/test_transformations.py +61 -0
- codac4matlab/tests/test_trunc.py +95 -0
- codac4matlab/unsupported/__init__.py +1 -0
- codac4matlab/version.py +1 -0
- codac4matlab-2.0.0.dev25.dist-info/METADATA +23 -0
- codac4matlab-2.0.0.dev25.dist-info/RECORD +76 -0
- codac4matlab-2.0.0.dev25.dist-info/WHEEL +6 -0
- codac4matlab-2.0.0.dev25.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
|
|
3
|
+
# Codac tests
|
|
4
|
+
# ----------------------------------------------------------------------------
|
|
5
|
+
# \date 2024
|
|
6
|
+
# \author Simon Rohou
|
|
7
|
+
# \copyright Copyright 2024 Codac Team
|
|
8
|
+
# \license GNU Lesser General Public License (LGPL)
|
|
9
|
+
|
|
10
|
+
import unittest
|
|
11
|
+
from codac import *
|
|
12
|
+
import sys, math, numpy as np
|
|
13
|
+
|
|
14
|
+
class TestSampledTraj(unittest.TestCase):
|
|
15
|
+
|
|
16
|
+
def test_SampledTraj(self):
|
|
17
|
+
|
|
18
|
+
x = SampledVectorTraj({
|
|
19
|
+
0.25: [-0.5,0.5],
|
|
20
|
+
1.: [0,0],
|
|
21
|
+
2.: [1,0],
|
|
22
|
+
3.: [1,1],
|
|
23
|
+
4.: [-1,1],
|
|
24
|
+
5.: [-1,-1],
|
|
25
|
+
6.: [2,-1]
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
self.assertTrue(x.tdomain() == Interval(0.25,6))
|
|
29
|
+
self.assertTrue(x.size() == 2)
|
|
30
|
+
self.assertTrue(x.nb_samples() == 7)
|
|
31
|
+
self.assertTrue(not x.is_empty())
|
|
32
|
+
self.assertTrue(x.codomain() == IntervalVector([[-1,2],[-1,1]]))
|
|
33
|
+
self.assertTrue(x(0.25) == Vector([-0.5,0.5]))
|
|
34
|
+
self.assertTrue(x(1.) == Vector([0,0]))
|
|
35
|
+
self.assertTrue(x(6.) == Vector([2,-1]))
|
|
36
|
+
# Interpolations:
|
|
37
|
+
self.assertTrue(Approx(x(0.75)) == Vector([-1/6.,1/6.]))
|
|
38
|
+
self.assertTrue(x(1.5) == Vector([0.5,0]))
|
|
39
|
+
self.assertTrue(x(5.5) == Vector([0.5,-1]))
|
|
40
|
+
self.assertTrue(x(Interval(1,4)) == IntervalVector([[-1,1],[0,1]]))
|
|
41
|
+
|
|
42
|
+
x_sampled = x.sampled(0.1)
|
|
43
|
+
self.assertTrue(x_sampled.tdomain() == Interval(0.25,6))
|
|
44
|
+
self.assertTrue(x_sampled.size() == 2)
|
|
45
|
+
self.assertTrue(x_sampled.nb_samples() > 5*x.nb_samples()) # approx
|
|
46
|
+
self.assertTrue(not x_sampled.is_empty())
|
|
47
|
+
self.assertTrue(x_sampled.codomain() == IntervalVector([[-1,2],[-1,1]]))
|
|
48
|
+
self.assertTrue(x_sampled(0.25) == Vector([-0.5,0.5]))
|
|
49
|
+
self.assertTrue(x_sampled(1.) == Vector([0,0]))
|
|
50
|
+
self.assertTrue(x_sampled(6.) == Vector([2,-1]))
|
|
51
|
+
# Interpolations:
|
|
52
|
+
self.assertTrue(Approx(x_sampled(0.75)) == Vector([-1/6.,1/6.]))
|
|
53
|
+
self.assertTrue(Approx(x_sampled(1.5)) == Vector([0.5,0]))
|
|
54
|
+
self.assertTrue(Approx(x_sampled(5.5)) == Vector([0.5,-1]))
|
|
55
|
+
self.assertTrue(x_sampled(Interval(1,4)) == IntervalVector([[-1,1],[0,1]]))
|
|
56
|
+
|
|
57
|
+
#DefaultFigure.set_window_properties([75,75],[700,700])
|
|
58
|
+
#DefaultFigure.draw_trajectory(x, Color.blue())
|
|
59
|
+
#DefaultFigure.draw_trajectory(x_sampled, Color.red())
|
|
60
|
+
|
|
61
|
+
# SampledTraj as operator (1d case)
|
|
62
|
+
|
|
63
|
+
t = ScalarVar()
|
|
64
|
+
f = AnalyticFunction(
|
|
65
|
+
[t], cos(t)
|
|
66
|
+
)
|
|
67
|
+
analytic_traj = AnalyticTraj(f, [-math.pi,math.pi])
|
|
68
|
+
sampled_traj = analytic_traj.sampled(1e-2)
|
|
69
|
+
g = sampled_traj.as_function()
|
|
70
|
+
|
|
71
|
+
h = AnalyticFunction(
|
|
72
|
+
[t], g(t)
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
t_ = -math.pi
|
|
76
|
+
while t_ < math.pi:
|
|
77
|
+
self.assertTrue(Approx(h.real_eval(t_),1e-8) == math.cos(t_))
|
|
78
|
+
t_=t_+1e-2
|
|
79
|
+
|
|
80
|
+
# SampledTraj as operator (nd case)
|
|
81
|
+
|
|
82
|
+
t = ScalarVar()
|
|
83
|
+
f = AnalyticFunction(
|
|
84
|
+
[t],
|
|
85
|
+
vec(2*cos(t),sin(2*t))
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
analytic_traj = AnalyticTraj(f, [0,5])
|
|
89
|
+
sampled_traj = analytic_traj.sampled(1e-2)
|
|
90
|
+
g = sampled_traj.as_function()
|
|
91
|
+
|
|
92
|
+
h = AnalyticFunction(
|
|
93
|
+
[t],
|
|
94
|
+
g(t)
|
|
95
|
+
)
|
|
96
|
+
|
|
97
|
+
t_ = 0
|
|
98
|
+
while t_ < 5:
|
|
99
|
+
self.assertTrue(Approx(h.real_eval(t_),1e-8) == Vector([2*math.cos(t_),math.sin(2*t_)]))
|
|
100
|
+
t_=t_+1e-2
|
|
101
|
+
|
|
102
|
+
h = AnalyticFunction(
|
|
103
|
+
[t],
|
|
104
|
+
[ g(t)[0],g(t)[1] ]
|
|
105
|
+
)
|
|
106
|
+
|
|
107
|
+
t_ = 0
|
|
108
|
+
while t_ < 5:
|
|
109
|
+
self.assertTrue(Approx(h.real_eval(t_),1e-8) == Vector([2*math.cos(t_),math.sin(2*t_)]))
|
|
110
|
+
t_=t_+1e-2
|
|
111
|
+
|
|
112
|
+
# SampledTraj (nan case)
|
|
113
|
+
|
|
114
|
+
x = SampledVectorTraj()
|
|
115
|
+
x.set(Vector([0,0]),0.)
|
|
116
|
+
x.set(Vector([2,2]),2.)
|
|
117
|
+
self.assertTrue(x(1.) == Vector([1,1]))
|
|
118
|
+
x.set(Vector([0,float("nan")]),0.)
|
|
119
|
+
self.assertTrue(x(1.).is_nan())
|
|
120
|
+
|
|
121
|
+
# SampledTraj, derivative
|
|
122
|
+
|
|
123
|
+
t = ScalarVar()
|
|
124
|
+
f = AnalyticFunction([t], sqr(t)*exp(sin(t)))
|
|
125
|
+
x = AnalyticTraj(f,[0,10]).sampled(1e-3)
|
|
126
|
+
s = AnalyticTraj(AnalyticFunction([t],exp(sin(t))*(2*t+sqr(t)*cos(t))),[0,10]).sampled(1e-2)
|
|
127
|
+
|
|
128
|
+
d = x.derivative()
|
|
129
|
+
p = d.primitive()
|
|
130
|
+
|
|
131
|
+
for i in np.arange(0, 10, 1e-1):
|
|
132
|
+
self.assertTrue(Approx(p(i),1e-2) == x(i))
|
|
133
|
+
|
|
134
|
+
if __name__ == '__main__':
|
|
135
|
+
unittest.main()
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
|
|
3
|
+
# Codac tests
|
|
4
|
+
# ----------------------------------------------------------------------------
|
|
5
|
+
# \date 2024
|
|
6
|
+
# \author Simon Rohou
|
|
7
|
+
# \copyright Copyright 2024 Codac Team
|
|
8
|
+
# \license GNU Lesser General Public License (LGPL)
|
|
9
|
+
|
|
10
|
+
import unittest
|
|
11
|
+
from codac import *
|
|
12
|
+
|
|
13
|
+
def hull(x):
|
|
14
|
+
if x == -oo:
|
|
15
|
+
return Interval(-oo, next_float(-oo))
|
|
16
|
+
if x == oo:
|
|
17
|
+
return Interval(prev_float(oo), oo)
|
|
18
|
+
else:
|
|
19
|
+
return Interval(x)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class TestSegment(unittest.TestCase):
|
|
23
|
+
|
|
24
|
+
def test_contains(self):
|
|
25
|
+
|
|
26
|
+
p1 = Vector([0,-10])
|
|
27
|
+
p2 = Vector([-10,-10])
|
|
28
|
+
p3 = Vector([-11,-10])
|
|
29
|
+
e1 = Segment(Vector([-10,-10]), Vector([10,-10]))
|
|
30
|
+
self.assertTrue(e1.contains(p1) == BoolInterval.TRUE)
|
|
31
|
+
self.assertTrue(e1.contains(p2) == BoolInterval.TRUE)
|
|
32
|
+
self.assertTrue(e1.contains(p3) == BoolInterval.FALSE)
|
|
33
|
+
|
|
34
|
+
def test_intersects(self):
|
|
35
|
+
|
|
36
|
+
self.assertTrue(Segment([[0,0],[10,0]]).intersects(Segment([[4,0],[6,0]])) == BoolInterval.TRUE)
|
|
37
|
+
self.assertTrue(Segment([[0,0],[10,0]]).intersects(Segment([[5,0],[15,0]])) == BoolInterval.TRUE)
|
|
38
|
+
self.assertTrue(Segment([[0,0],[10,0]]).intersects(Segment([[5,-5],[5,10]])) == BoolInterval.TRUE)
|
|
39
|
+
self.assertTrue(Segment([[0,0],[10,0]]).intersects(Segment([[15,-5],[15,10]])) == BoolInterval.FALSE)
|
|
40
|
+
self.assertTrue(Segment([[0,0],[10,10]]).intersects(Segment([[1,1],[9,9]])) == BoolInterval.TRUE)
|
|
41
|
+
self.assertTrue(Segment([[1,1],[9,9]]).intersects(Segment([[0,0],[10,10]])) == BoolInterval.TRUE)
|
|
42
|
+
|
|
43
|
+
self.assertTrue(Segment(IntervalVector([hull(-oo),2]),Vector([0,2])).intersects(Segment(Vector([0,0]),Vector([0,1]))) == BoolInterval.FALSE)
|
|
44
|
+
self.assertTrue(Segment(IntervalVector([hull(-oo),2]),Vector([0,2])).intersects(Segment(Vector([0,0]),Vector([0,2]))) == BoolInterval.TRUE)
|
|
45
|
+
|
|
46
|
+
def test_contains(self):
|
|
47
|
+
|
|
48
|
+
p1,p2,p3 = Vector([0.,0.]), Vector([1.5,3.]), Vector([0.,2.])
|
|
49
|
+
e1 = Segment(Vector([-10.,-10.]), Vector([10.,10.]))
|
|
50
|
+
e2 = Segment(Vector([1.,1.]), Vector([10.,10.]))
|
|
51
|
+
e3 = Segment(Vector([0.,0.]), Vector([2.,4.]))
|
|
52
|
+
|
|
53
|
+
self.assertTrue(e1.contains(p1) != BoolInterval.FALSE)
|
|
54
|
+
self.assertTrue(e2.contains(p1) == BoolInterval.FALSE)
|
|
55
|
+
self.assertTrue(e3.contains(p2) != BoolInterval.FALSE)
|
|
56
|
+
self.assertTrue(e3.contains(p3) == BoolInterval.FALSE)
|
|
57
|
+
|
|
58
|
+
def test_proj_intersection(self):
|
|
59
|
+
|
|
60
|
+
self.assertTrue(proj_intersection([[0,0],[1,1]], [[3,3],[4,4]])
|
|
61
|
+
== IntervalVector(2))
|
|
62
|
+
|
|
63
|
+
self.assertTrue(proj_intersection([[0,0],[1,0]], [[0,2],[1,2]])
|
|
64
|
+
== IntervalVector.empty(2))
|
|
65
|
+
|
|
66
|
+
self.assertTrue(proj_intersection([[2,0],[6,4]],[[6,5],[5,6]])
|
|
67
|
+
== Approx(IntervalVector([6.5,4.5])))
|
|
68
|
+
|
|
69
|
+
self.assertTrue(proj_intersection([[-0.7,0.7],[0,1]], [[-1,0],[-0.7,-0.7]])
|
|
70
|
+
== Approx(IntervalVector([-1.2069,0.4828]), 1e-4))
|
|
71
|
+
|
|
72
|
+
self.assertTrue(proj_intersection([[1,2],[2,3]], [[8,4],[7,4]])
|
|
73
|
+
== IntervalVector([3,4]))
|
|
74
|
+
|
|
75
|
+
self.assertTrue(proj_intersection([[4,11],[8,11]], [[12,12],[12,16]])
|
|
76
|
+
== IntervalVector([12,11]))
|
|
77
|
+
|
|
78
|
+
self.assertTrue(proj_intersection([[1,2],[1,2]], [[8,4],[7,4]])
|
|
79
|
+
== IntervalVector(2))
|
|
80
|
+
|
|
81
|
+
self.assertTrue(proj_intersection([[0,1],[0,2]], [[2,1],[2,2]])
|
|
82
|
+
== IntervalVector.empty(2))
|
|
83
|
+
|
|
84
|
+
self.assertTrue(proj_intersection([[-4,4],[0,0]], [[0,0],[4,4]])
|
|
85
|
+
== IntervalVector([0,0]))
|
|
86
|
+
|
|
87
|
+
self.assertTrue(proj_intersection([[-4,4],[0,0]], [[4,4],[0,0]])
|
|
88
|
+
== IntervalVector([0,0]))
|
|
89
|
+
|
|
90
|
+
self.assertTrue(proj_intersection([[0,4],[4,0]], [[4,4],[0,0]])
|
|
91
|
+
== IntervalVector([2,2]))
|
|
92
|
+
|
|
93
|
+
def test_intersection(self):
|
|
94
|
+
|
|
95
|
+
self.assertTrue((Segment([0,0],[0,0]) & Segment([0,0],[5,0])) == IntervalVector([0,0])) # degenerate line, horizontal edge line
|
|
96
|
+
self.assertTrue((Segment([0,0],[0,0]) & Segment([0,0],[0,5])) == IntervalVector([0,0])) # degenerate line, vertical edge line
|
|
97
|
+
|
|
98
|
+
self.assertTrue((Segment([0,0],[0,1]) & Segment([0,0],[0,5.0])) == IntervalVector([0,[0,1.]])) # vertical edge line (colinear)
|
|
99
|
+
self.assertTrue((Segment([0,0],[0,1]) & Segment([0,0],[0,0.5])) == IntervalVector([0,[0,0.5]])) # vertical edge line (colinear)
|
|
100
|
+
self.assertTrue((Segment([0,0],[1,0]) & Segment([0,0],[5.0,0])) == IntervalVector([[0,1.],0])) # horizontal edge line (colinear)
|
|
101
|
+
self.assertTrue((Segment([0,0],[1,0]) & Segment([0,0],[0.5,0])) == IntervalVector([[0,0.5],0])) # horizontal edge line (colinear)
|
|
102
|
+
|
|
103
|
+
self.assertTrue((Segment([7,4],[7,5]) & Segment([7,6],[7,8])) == IntervalVector.empty(2)) # vertical edge line (colinear), no intersection
|
|
104
|
+
self.assertTrue((Segment([4,7],[5,7]) & Segment([6,7],[8,7])) == IntervalVector.empty(2)) # horizontal edge line (colinear), no intersection
|
|
105
|
+
|
|
106
|
+
self.assertTrue((Segment([0,0],[3,0]) & Segment([1,2],[1,-999])) == IntervalVector([1,0])) # perpendicular intersection
|
|
107
|
+
self.assertTrue((Segment([0.5,-1],[0.5,5]) & Segment([-3,2],[5,2])) == IntervalVector([0.5,2])) # perpendicular intersection
|
|
108
|
+
|
|
109
|
+
self.assertTrue((Segment([0,0],[3,0]) & Segment([1,-10],[1,-999])) == IntervalVector.empty(2)) # perpendicular lines, no intersection
|
|
110
|
+
self.assertTrue((Segment([0.5,-1],[0.5,5]) & Segment([-3,-2],[5,-2])) == IntervalVector.empty(2)) # perpendicular lines, no intersection
|
|
111
|
+
|
|
112
|
+
self.assertTrue((Segment([8,4],[9,2]) & Segment([7,3],[9,3])) == IntervalVector([8.5,3])) # perpendicular oblique lines
|
|
113
|
+
self.assertTrue((Segment([8,4],[9,2]) & Segment([8.5,8],[8.5,0])) == IntervalVector([8.5,3])) # perpendicular oblique lines
|
|
114
|
+
|
|
115
|
+
self.assertTrue((Segment([8,4],[9,2]) & Segment([7.,3],[7.5,3])) == IntervalVector.empty(2)) # secant oblique lines, no intersection
|
|
116
|
+
self.assertTrue((Segment([8,4],[9,2]) & Segment([8.5,8],[8.5,7])) == IntervalVector.empty(2)) # secant oblique lines, no intersection
|
|
117
|
+
self.assertTrue((Segment([6,-1],[8,1]) & Segment([7.5,0],[9,0])) == IntervalVector.empty(2)) # secant oblique lines, no intersection
|
|
118
|
+
self.assertTrue((Segment([6,-1],[8,1]) & Segment([6.5,0.5],[6.5,2])) == IntervalVector.empty(2)) # secant oblique lines, no intersection
|
|
119
|
+
|
|
120
|
+
# Other tests
|
|
121
|
+
self.assertTrue((Segment([8,14],[6,13]) & Segment([1,1],[1,14])) == IntervalVector.empty(2))
|
|
122
|
+
self.assertTrue((Segment([hull(-oo),0],[1,0]) & Segment([0,1],[0,-1])) == IntervalVector.zero(2))
|
|
123
|
+
self.assertTrue((Segment([0,0],[1,2]) & Segment([0.5,0],[0.5,2])) == IntervalVector([0.5,1]))
|
|
124
|
+
self.assertTrue((Segment([-1,-1],[0,0]) & Segment([9,3],[0,0])) == IntervalVector([0,0]))
|
|
125
|
+
self.assertTrue((Segment([0,0],[10,0]) & Segment([2,0],[8,0])) == IntervalVector([[2,8],[0]])) # colinear case
|
|
126
|
+
self.assertTrue((Segment([0,0],[10,10]) & Segment([2,2],[8,8])) == IntervalVector([[2,8],[2,8]])) # colinear case
|
|
127
|
+
self.assertTrue((Segment([0,0],[10,0]) & Segment([2,1],[8,1])) == IntervalVector.empty(2)) # parallel case
|
|
128
|
+
|
|
129
|
+
self.assertTrue((Segment([2,0],[6,4]) & Segment([6,5],[5,6])) == IntervalVector.empty(2))
|
|
130
|
+
self.assertTrue(proj_intersection(Segment([2,0],[6,4]), Segment([6,5],[5,6])) == IntervalVector([6.5,4.5]))
|
|
131
|
+
|
|
132
|
+
# Near infinite cases
|
|
133
|
+
e1 = Segment([-1,6],[-1,next_float(-oo)])
|
|
134
|
+
e2 = Segment([-1,-1],[3,-6])
|
|
135
|
+
self.assertTrue((e1 & e2) == IntervalVector([-1,-1]))
|
|
136
|
+
|
|
137
|
+
if __name__ == '__main__':
|
|
138
|
+
unittest.main()
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
|
|
3
|
+
# Codac tests
|
|
4
|
+
# ----------------------------------------------------------------------------
|
|
5
|
+
# \date 2024
|
|
6
|
+
# \author Simon Rohou
|
|
7
|
+
# \copyright Copyright 2024 Codac Team
|
|
8
|
+
# \license GNU Lesser General Public License (LGPL)
|
|
9
|
+
|
|
10
|
+
import unittest
|
|
11
|
+
from codac import *
|
|
12
|
+
|
|
13
|
+
class TestSepCartProd(unittest.TestCase):
|
|
14
|
+
|
|
15
|
+
def test_SepCartProd(self):
|
|
16
|
+
|
|
17
|
+
v = VectorVar(1)
|
|
18
|
+
s1 = SepInverse(AnalyticFunction([v], v), IntervalVector([[-1,1]]))
|
|
19
|
+
s2 = SepInverse(AnalyticFunction([v], v), IntervalVector([[5,6]]))
|
|
20
|
+
|
|
21
|
+
x = IntervalVector([[0,8],[5.5,oo]])
|
|
22
|
+
s3 = SepCartProd(s1,s2)
|
|
23
|
+
inner,outer = s3.separate(x)
|
|
24
|
+
self.assertTrue(inner == IntervalVector([[1,8],[6,oo]]))
|
|
25
|
+
self.assertTrue(outer == IntervalVector([[0,1],[5.5,6]]))
|
|
26
|
+
|
|
27
|
+
x = IntervalVector([[0,8],[5.5,oo]])
|
|
28
|
+
s4 = cart_prod(s1,s2)
|
|
29
|
+
inner,outer = s4.separate(x)
|
|
30
|
+
self.assertTrue(inner == IntervalVector([[1,8],[6,oo]]))
|
|
31
|
+
self.assertTrue(outer == IntervalVector([[0,1],[5.5,6]]))
|
|
32
|
+
|
|
33
|
+
if __name__ == '__main__':
|
|
34
|
+
unittest.main()
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
|
|
3
|
+
# Codac tests
|
|
4
|
+
# ----------------------------------------------------------------------------
|
|
5
|
+
# \date 2024
|
|
6
|
+
# \author Simon Rohou
|
|
7
|
+
# \copyright Copyright 2024 Codac Team
|
|
8
|
+
# \license GNU Lesser General Public License (LGPL)
|
|
9
|
+
|
|
10
|
+
import unittest
|
|
11
|
+
from codac import *
|
|
12
|
+
|
|
13
|
+
def test_inside_diamond(x):
|
|
14
|
+
if (x[1] < x[0]+1) and (x[1] > x[0]-1) and (x[1] < -x[0]+1) and (x[1] > -x[0]-1):
|
|
15
|
+
return BoolInterval.TRUE
|
|
16
|
+
elif not(x[1] < x[0]+1) or not(x[1] > x[0]-1) or not(x[1] < -x[0]+1) or not(x[1] > -x[0]-1):
|
|
17
|
+
return BoolInterval.FALSE
|
|
18
|
+
else:
|
|
19
|
+
return BoolInterval.UNKNOWN
|
|
20
|
+
|
|
21
|
+
class TestSepCtcBoundary(unittest.TestCase):
|
|
22
|
+
|
|
23
|
+
def test_SepCtcBoundary(self):
|
|
24
|
+
|
|
25
|
+
ctc_bound_diamond = CtcSegment([[-1],[0]], [[0],[-1]]) | CtcSegment([[0],[-1]], [[1],[0]]) \
|
|
26
|
+
| CtcSegment([[1],[0]], [[0],[1]]) | CtcSegment([[0],[1]], [[-1],[0]])
|
|
27
|
+
|
|
28
|
+
sep_diamond = SepCtcBoundary(ctc_bound_diamond,test_inside_diamond)
|
|
29
|
+
#DefaultFigure.pave(IntervalVector([[-2,2],[-2,2]]), sep_diamond, 0.1)
|
|
30
|
+
|
|
31
|
+
x = IntervalVector(2)
|
|
32
|
+
inner,outer = sep_diamond.separate(IntervalVector(2))
|
|
33
|
+
self.assertTrue(inner == IntervalVector(2))
|
|
34
|
+
self.assertTrue(outer == IntervalVector([[-1,1],[-1,1]]))
|
|
35
|
+
|
|
36
|
+
x = IntervalVector([[0,10],[0,10]])
|
|
37
|
+
inner,outer = sep_diamond.separate(x)
|
|
38
|
+
self.assertTrue(inner == x)
|
|
39
|
+
self.assertTrue(outer == IntervalVector([[0,1],[0,1]]))
|
|
40
|
+
|
|
41
|
+
x = IntervalVector([[0.2,10],[0.2,10]])
|
|
42
|
+
inner,outer = sep_diamond.separate(x)
|
|
43
|
+
self.assertTrue(inner == x)
|
|
44
|
+
self.assertTrue(outer == IntervalVector([[0.2,0.8],[0.2,0.8]]))
|
|
45
|
+
|
|
46
|
+
x = IntervalVector([[0.5,10],[0.5,10]])
|
|
47
|
+
inner,outer = sep_diamond.separate(x)
|
|
48
|
+
self.assertTrue(inner == x)
|
|
49
|
+
self.assertTrue(outer == IntervalVector([[0.5],[0.5]]))
|
|
50
|
+
|
|
51
|
+
if __name__ == '__main__':
|
|
52
|
+
unittest.main()
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
|
|
3
|
+
# Codac tests
|
|
4
|
+
# ----------------------------------------------------------------------------
|
|
5
|
+
# \date 2024
|
|
6
|
+
# \author Simon Rohou
|
|
7
|
+
# \copyright Copyright 2024 Codac Team
|
|
8
|
+
# \license GNU Lesser General Public License (LGPL)
|
|
9
|
+
|
|
10
|
+
import unittest
|
|
11
|
+
from codac import *
|
|
12
|
+
|
|
13
|
+
class TestSepInverse(unittest.TestCase):
|
|
14
|
+
|
|
15
|
+
def test_SepInverse_box(self):
|
|
16
|
+
|
|
17
|
+
x = VectorVar(2)
|
|
18
|
+
f = AnalyticFunction([x], [
|
|
19
|
+
x[0],
|
|
20
|
+
sqr(x[0]/7.)+sqr(x[1]/3.)
|
|
21
|
+
])
|
|
22
|
+
s = SepInverse(f, [[0,oo],[-oo,1]])
|
|
23
|
+
|
|
24
|
+
b = IntervalVector([[0,0.8],[-2.28,-1.56]])
|
|
25
|
+
inner,outer = s.separate(b)
|
|
26
|
+
self.assertTrue(inner == IntervalVector([[0],[-2.28,-1.56]]))
|
|
27
|
+
self.assertTrue(outer == b)
|
|
28
|
+
|
|
29
|
+
b = IntervalVector([[4,5.4],[-0.05,2.45]])
|
|
30
|
+
inner,outer = s.separate(b)
|
|
31
|
+
self.assertTrue(Approx(inner,1e-2) == IntervalVector([[4.039,5.40],[1.908,2.45]]))
|
|
32
|
+
self.assertTrue(outer == b)
|
|
33
|
+
|
|
34
|
+
b = IntervalVector([[6.25,6.7],[0.9,1.85]])
|
|
35
|
+
inner,outer = s.separate(b)
|
|
36
|
+
self.assertTrue(Approx(inner,1e-2) == IntervalVector([[6.25,6.70],[0.9, 1.85]]))
|
|
37
|
+
self.assertTrue(Approx(inner,1e-2) == IntervalVector([[6.25,6.70],[0.9, 1.85]]))
|
|
38
|
+
|
|
39
|
+
b = IntervalVector([[-6,-5],[0,2]])
|
|
40
|
+
inner,outer = s.separate(b)
|
|
41
|
+
self.assertTrue(inner == b)
|
|
42
|
+
self.assertTrue(outer == IntervalVector.empty(2))
|
|
43
|
+
|
|
44
|
+
b = IntervalVector([[2,3],[-1,1]])
|
|
45
|
+
inner,outer = s.separate(b)
|
|
46
|
+
self.assertTrue(inner == IntervalVector.empty(2))
|
|
47
|
+
self.assertTrue(outer == b)
|
|
48
|
+
|
|
49
|
+
def test_SepInverse_sep(self):
|
|
50
|
+
|
|
51
|
+
x = VectorVar(2)
|
|
52
|
+
f = AnalyticFunction([x], [
|
|
53
|
+
x[0],
|
|
54
|
+
sqr(x[0]/7.)+sqr(x[1]/3.)
|
|
55
|
+
])
|
|
56
|
+
s = SepInverse(f, SepWrapper_IntervalVector([[0,oo],[-oo,1]]))
|
|
57
|
+
|
|
58
|
+
b = IntervalVector([[0,0.8],[-2.28,-1.56]])
|
|
59
|
+
inner,outer = s.separate(b)
|
|
60
|
+
self.assertTrue(inner == IntervalVector([[0],[-2.28,-1.56]]))
|
|
61
|
+
self.assertTrue(outer == b)
|
|
62
|
+
|
|
63
|
+
b = IntervalVector([[4,5.4],[-0.05,2.45]])
|
|
64
|
+
inner,outer = s.separate(b)
|
|
65
|
+
self.assertTrue(Approx(inner,1e-2) == IntervalVector([[4.039,5.40],[1.908,2.45]]))
|
|
66
|
+
self.assertTrue(outer == b)
|
|
67
|
+
|
|
68
|
+
b = IntervalVector([[6.25,6.7],[0.9,1.85]])
|
|
69
|
+
inner,outer = s.separate(b)
|
|
70
|
+
self.assertTrue(Approx(inner,1e-2) == IntervalVector([[6.25,6.70],[0.9, 1.85]]))
|
|
71
|
+
self.assertTrue(Approx(inner,1e-2) == IntervalVector([[6.25,6.70],[0.9, 1.85]]))
|
|
72
|
+
|
|
73
|
+
b = IntervalVector([[-6,-5],[0,2]])
|
|
74
|
+
inner,outer = s.separate(b)
|
|
75
|
+
self.assertTrue(inner == b)
|
|
76
|
+
self.assertTrue(outer == IntervalVector.empty(2))
|
|
77
|
+
|
|
78
|
+
b = IntervalVector([[2,3],[-1,1]])
|
|
79
|
+
inner,outer = s.separate(b)
|
|
80
|
+
self.assertTrue(inner == IntervalVector.empty(2))
|
|
81
|
+
self.assertTrue(outer == b)
|
|
82
|
+
|
|
83
|
+
def test_SepInverse_other_test(self):
|
|
84
|
+
|
|
85
|
+
x = VectorVar(2)
|
|
86
|
+
f = AnalyticFunction([x], vec(sqr(x[0])+sqr(x[1])))
|
|
87
|
+
s = SepInverse(f, [[0,1]])
|
|
88
|
+
|
|
89
|
+
#pave([[-5,5],[-5,5]], s, 0.01);
|
|
90
|
+
|
|
91
|
+
inner,outer = s.separate(IntervalVector([[0.1,0.2],[0.1,0.2]])) # fully inside
|
|
92
|
+
self.assertTrue(inner.is_empty())
|
|
93
|
+
self.assertTrue(outer == IntervalVector([[0.1,0.2],[0.1,0.2]]))
|
|
94
|
+
|
|
95
|
+
inner,outer = s.separate(IntervalVector([[-0.2,0.2],[-0.2,0.2]])) # fully inside
|
|
96
|
+
self.assertTrue(inner.is_empty())
|
|
97
|
+
self.assertTrue(outer == IntervalVector([[-0.2,0.2],[-0.2,0.2]]))
|
|
98
|
+
|
|
99
|
+
inner,outer = s.separate(IntervalVector(2))
|
|
100
|
+
self.assertTrue(inner == IntervalVector(2))
|
|
101
|
+
self.assertTrue(outer == IntervalVector([[-1,1],[-1,1]]))
|
|
102
|
+
|
|
103
|
+
if __name__ == '__main__':
|
|
104
|
+
unittest.main()
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
|
|
3
|
+
# Codac tests
|
|
4
|
+
# ----------------------------------------------------------------------------
|
|
5
|
+
# \date 2024
|
|
6
|
+
# \author Simon Rohou
|
|
7
|
+
# \copyright Copyright 2024 Codac Team
|
|
8
|
+
# \license GNU Lesser General Public License (LGPL)
|
|
9
|
+
|
|
10
|
+
import unittest
|
|
11
|
+
from codac import *
|
|
12
|
+
|
|
13
|
+
class TestSepPolygon(unittest.TestCase):
|
|
14
|
+
|
|
15
|
+
def test_SepPolygon(self):
|
|
16
|
+
|
|
17
|
+
# Polygon, defined as a list of vertices
|
|
18
|
+
p = Polygon([[3,-1],[3,4],[5,6],[-1,1]])
|
|
19
|
+
s = SepPolygon(p)
|
|
20
|
+
c = CtcPolygon(p)
|
|
21
|
+
|
|
22
|
+
x = IntervalVector(2)
|
|
23
|
+
inner,outer = s.separate(IntervalVector(2))
|
|
24
|
+
self.assertTrue(inner == IntervalVector(2))
|
|
25
|
+
self.assertTrue(outer == IntervalVector([[-1,5],[-1,6]]))
|
|
26
|
+
|
|
27
|
+
y = IntervalVector(2)
|
|
28
|
+
c.contract(y)
|
|
29
|
+
self.assertTrue(y == IntervalVector([[-1,5],[-1,6]]))
|
|
30
|
+
|
|
31
|
+
x = IntervalVector([[3.02,3.16],[2.5,3.2]]) # possible bug
|
|
32
|
+
inner,outer = s.separate(x)
|
|
33
|
+
self.assertTrue(inner == x)
|
|
34
|
+
self.assertTrue(outer.is_empty())
|
|
35
|
+
|
|
36
|
+
def test_SepPolygon_fromCodac1(self):
|
|
37
|
+
|
|
38
|
+
# Polygone with hole, defined as a list of edges
|
|
39
|
+
|
|
40
|
+
s = SepPolygon([
|
|
41
|
+
# external border
|
|
42
|
+
[[6,-6], [7,9]],
|
|
43
|
+
[[7,9], [0,5]],
|
|
44
|
+
[[0,5], [-9,8]],
|
|
45
|
+
[[-9,8], [-8,-9]],
|
|
46
|
+
[[-8,-9], [6,-6]],
|
|
47
|
+
# hole
|
|
48
|
+
[[-2,3], [3.5,2]],
|
|
49
|
+
[[3.5,2], [1.5,0.5]],
|
|
50
|
+
[[1.5,0.5], [3,-4]],
|
|
51
|
+
[[3,-4], [-3,-3]],
|
|
52
|
+
[[-3,-3], [-2,3]]
|
|
53
|
+
])
|
|
54
|
+
|
|
55
|
+
#DefaultFigure.pave(IntervalVector([[-10,10],[-10,10]]), s, 0.1)
|
|
56
|
+
|
|
57
|
+
# Check a box inside the hole
|
|
58
|
+
|
|
59
|
+
x = IntervalVector([[0],[0]]).inflate(0.5)
|
|
60
|
+
#DefaultFigure.draw_box(x,Color::purple())
|
|
61
|
+
inner,outer = s.separate(x)
|
|
62
|
+
self.assertTrue(inner == x)
|
|
63
|
+
self.assertTrue(outer.is_empty())
|
|
64
|
+
|
|
65
|
+
# Check a box inside the polygon
|
|
66
|
+
|
|
67
|
+
x = IntervalVector([[5],[-5]]).inflate(0.5)
|
|
68
|
+
#DefaultFigure.draw_box(x,Color::purple())
|
|
69
|
+
inner,outer = s.separate(x)
|
|
70
|
+
self.assertTrue(inner.is_empty())
|
|
71
|
+
self.assertTrue(outer == x)
|
|
72
|
+
|
|
73
|
+
# Check a box outside the polygon
|
|
74
|
+
|
|
75
|
+
x = IntervalVector([[-1],[8]]).inflate(0.5)
|
|
76
|
+
#DefaultFigure.draw_box(x,Color::purple())
|
|
77
|
+
inner,outer = s.separate(x)
|
|
78
|
+
self.assertTrue(inner == x)
|
|
79
|
+
self.assertTrue(outer.is_empty())
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
# Other polygon, defined as a list of vertices
|
|
83
|
+
|
|
84
|
+
s = SepPolygon([[6,-6],[7,9],[0,5],[-9,8],[-8,-9]])
|
|
85
|
+
|
|
86
|
+
# Check a box inside the polygon
|
|
87
|
+
|
|
88
|
+
x = IntervalVector([[5],[-5]]).inflate(0.5)
|
|
89
|
+
inner,outer = s.separate(x)
|
|
90
|
+
self.assertTrue(inner.is_empty())
|
|
91
|
+
self.assertTrue(outer == x)
|
|
92
|
+
|
|
93
|
+
# Check a box outside the polygon
|
|
94
|
+
|
|
95
|
+
x = IntervalVector([[-1],[8]]).inflate(0.5)
|
|
96
|
+
inner,outer = s.separate(x)
|
|
97
|
+
self.assertTrue(inner == x)
|
|
98
|
+
self.assertTrue(outer.is_empty())
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
if __name__ == '__main__':
|
|
102
|
+
unittest.main()
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
|
|
3
|
+
# Codac tests
|
|
4
|
+
# ----------------------------------------------------------------------------
|
|
5
|
+
# \date 2024
|
|
6
|
+
# \author Simon Rohou
|
|
7
|
+
# \copyright Copyright 2024 Codac Team
|
|
8
|
+
# \license GNU Lesser General Public License (LGPL)
|
|
9
|
+
|
|
10
|
+
import unittest
|
|
11
|
+
from codac import *
|
|
12
|
+
|
|
13
|
+
class TestSepProj(unittest.TestCase):
|
|
14
|
+
|
|
15
|
+
def test_SepProj(self):
|
|
16
|
+
|
|
17
|
+
x = VectorVar(3)
|
|
18
|
+
f_ellipsoid = AnalyticFunction([x], 2*sqr(x[0])+x[0]*x[1]+x[0]*x[2]+sqr(x[1])+sqr(x[2]))
|
|
19
|
+
sep_ellipsoid = SepInverse(f_ellipsoid, [0.7,1])
|
|
20
|
+
sep_proj = SepProj(sep_ellipsoid, [0,1], [[0.1,0.2]])
|
|
21
|
+
|
|
22
|
+
# todo: test with SepProj sep_proj(sep_ellipsoid, {0,1}, [[-oo,oo]])
|
|
23
|
+
|
|
24
|
+
#pave(IntervalVector([[-2,2],[-2,2]]), sep_proj, 0.1)
|
|
25
|
+
|
|
26
|
+
b = IntervalVector([[0.2,0.4],[0.0,1]])
|
|
27
|
+
inner,outer = sep_proj.separate(b,1e-3)
|
|
28
|
+
self.assertTrue(Approx(outer,1e-2) == IntervalVector([[0.2,0.4],[0,0.94]]))
|
|
29
|
+
|
|
30
|
+
b = IntervalVector([[-0.4,-0.2],[0.95,1.5]])
|
|
31
|
+
inner,outer = sep_proj.separate(b,1e-3)
|
|
32
|
+
self.assertTrue(Approx(outer,1e-2) == IntervalVector([[-0.4,-0.2],[0.95,1.12421]]))
|
|
33
|
+
|
|
34
|
+
b = IntervalVector([[0.65],[-0.5,-0.4]])
|
|
35
|
+
inner,outer = sep_proj.separate(b,1e-3)
|
|
36
|
+
self.assertTrue(inner.is_empty())
|
|
37
|
+
|
|
38
|
+
if __name__ == '__main__':
|
|
39
|
+
unittest.main()
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
|
|
3
|
+
# Codac tests
|
|
4
|
+
# ----------------------------------------------------------------------------
|
|
5
|
+
# \date 2024
|
|
6
|
+
# \author Simon Rohou
|
|
7
|
+
# \copyright Copyright 2024 Codac Team
|
|
8
|
+
# \license GNU Lesser General Public License (LGPL)
|
|
9
|
+
|
|
10
|
+
import unittest
|
|
11
|
+
from codac import *
|
|
12
|
+
|
|
13
|
+
class TestSepTransform(unittest.TestCase):
|
|
14
|
+
|
|
15
|
+
def test_SepTransform(self):
|
|
16
|
+
|
|
17
|
+
x = VectorVar(2)
|
|
18
|
+
s1 = SepInverse(AnalyticFunction([x], sqr(x[0])+sqr(x[1])), [0,1])
|
|
19
|
+
s2 = SepTransform(s1,
|
|
20
|
+
AnalyticFunction([x], x-Vector([2,2])),
|
|
21
|
+
AnalyticFunction([x], x+Vector([2,2])))
|
|
22
|
+
|
|
23
|
+
#DefaultFigure.pave([[-5,5],[-5,5]], s2, 0.01)
|
|
24
|
+
|
|
25
|
+
inner,outer = s2.separate(IntervalVector(2))
|
|
26
|
+
self.assertTrue(inner == IntervalVector(2))
|
|
27
|
+
self.assertTrue(Approx(outer,1e-1) == IntervalVector([[-3,-1],[-3,-1]]))
|
|
28
|
+
|
|
29
|
+
inner,outer = s2.separate(IntervalVector([[-2.2,-1.8],[-2.2,-1.8]]))
|
|
30
|
+
self.assertTrue(inner.is_empty())
|
|
31
|
+
self.assertTrue(outer == IntervalVector([[-2.2,-1.8],[-2.2,-1.8]]))
|
|
32
|
+
|
|
33
|
+
b = IntervalVector([[-2.5,-1.5],[-2,10]])
|
|
34
|
+
#DefaultFigure.draw_box(b,[Color.purple(),Color.purple(0.3)])
|
|
35
|
+
inner,outer = s2.separate(b)
|
|
36
|
+
#DefaultFigure.draw_box(xs.inner,[Color.green(),Color.green(0.3)])
|
|
37
|
+
self.assertTrue(Approx(inner,1e-1) == IntervalVector([[-2.5,-1.5],[-1.134,10]]))
|
|
38
|
+
self.assertTrue(Approx(outer,1e-1) == IntervalVector([[-2.5,-1.5],[-2,-1]]))
|
|
39
|
+
|
|
40
|
+
if __name__ == '__main__':
|
|
41
|
+
unittest.main()
|