codac4matlab 2.0.0.dev20__cp39-cp39-win_amd64.whl → 2.0.0.dev25__cp39-cp39-win_amd64.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.
Files changed (36) hide show
  1. codac4matlab/_core.cp39-win_amd64.pyd +0 -0
  2. codac4matlab/_graphics.cp39-win_amd64.pyd +0 -0
  3. codac4matlab/_unsupported.cp39-win_amd64.pyd +0 -0
  4. codac4matlab/core/__init__.py +39 -14
  5. codac4matlab/tests/test_AnalyticTraj.py +3 -4
  6. codac4matlab/tests/test_BoolInterval.py +57 -1
  7. codac4matlab/tests/test_ConvexPolygon.py +111 -18
  8. codac4matlab/tests/test_CtcCtcBoundary.py +1 -1
  9. codac4matlab/tests/test_CtcDeriv.py +434 -0
  10. codac4matlab/tests/test_CtcEval.py +214 -0
  11. codac4matlab/tests/test_CtcInverse.py +13 -4
  12. codac4matlab/tests/test_CtcPolygon.py +1 -1
  13. codac4matlab/tests/test_GaussJordan.py +34 -0
  14. codac4matlab/tests/test_IntFullPivLU.py +27 -0
  15. codac4matlab/tests/test_Interval.py +30 -6
  16. codac4matlab/tests/test_Interval_operations.py +6 -6
  17. codac4matlab/tests/test_OctaSym.py +9 -0
  18. codac4matlab/tests/test_Parallelepiped.py +35 -0
  19. codac4matlab/tests/test_Parallelepiped_eval.py +62 -0
  20. codac4matlab/tests/test_Polygon.py +14 -2
  21. codac4matlab/tests/test_SampledTraj.py +14 -1
  22. codac4matlab/tests/test_Segment.py +17 -2
  23. codac4matlab/tests/test_SepCtcBoundary.py +1 -1
  24. codac4matlab/tests/test_SepPolygon.py +1 -1
  25. codac4matlab/tests/test_SepTransform.py +5 -5
  26. codac4matlab/tests/test_Slice.py +78 -0
  27. codac4matlab/tests/test_Slice_polygon.py +208 -0
  28. codac4matlab/tests/test_SlicedTube.py +263 -5
  29. codac4matlab/tests/test_cart_prod.py +1 -0
  30. codac4matlab/tests/test_peibos.py +83 -0
  31. codac4matlab/tests/test_predefined_tubes.py +6 -6
  32. codac4matlab/tests/test_trunc.py +95 -0
  33. {codac4matlab-2.0.0.dev20.dist-info → codac4matlab-2.0.0.dev25.dist-info}/METADATA +1 -1
  34. {codac4matlab-2.0.0.dev20.dist-info → codac4matlab-2.0.0.dev25.dist-info}/RECORD +36 -27
  35. {codac4matlab-2.0.0.dev20.dist-info → codac4matlab-2.0.0.dev25.dist-info}/WHEEL +1 -1
  36. {codac4matlab-2.0.0.dev20.dist-info → codac4matlab-2.0.0.dev25.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/env python
2
+
3
+ # Codac tests
4
+ # ----------------------------------------------------------------------------
5
+ # \date 2025
6
+ # \author Damien Massé
7
+ # \copyright Copyright 2025 Codac Team
8
+ # \license GNU Lesser General Public License (LGPL)
9
+
10
+ import unittest
11
+ from codac import *
12
+
13
+ class TestGaussJordan(unittest.TestCase):
14
+
15
+ def test_GaussJordan(self):
16
+
17
+ M = Matrix([
18
+ [ 1, -4, 6, 7, 6 ],
19
+ [ 2, 1, 3, 6, -2 ],
20
+ [ 5, 2, 2, 9, -1 ] ])
21
+ pre = gauss_jordan(M)
22
+ # check that pre*M is "band matrix" */
23
+ P = pre*M
24
+ mx = 0.0
25
+ for i in range(1,M.rows()-1):
26
+ for j in range(0,i-1):
27
+ mx = max(mx,abs(P(i,j)))
28
+ mx = max(mx,abs(P(M.rows()-1-i,M.cols()-1-j)))
29
+ self.assertTrue(mx<1e-10)
30
+
31
+
32
+ if __name__ == '__main__':
33
+ unittest.main()
34
+
@@ -49,9 +49,36 @@ class TestIntvFullPivLU(unittest.TestCase):
49
49
  K = LUdec.kernel()
50
50
  self.assertTrue(K.cols()==1)
51
51
  self.assertTrue((M*K).norm().ub()<1e-10)
52
+ coK = LUdec.cokernel()
53
+ self.assertTrue(coK.rows()==1)
54
+ self.assertTrue((coK*M).norm().ub()<1e-10)
52
55
  Im = LUdec.image(M)
53
56
  self.assertTrue(Im.cols()==3)
57
+ coIm = LUdec.coimage(M)
58
+ self.assertTrue(coIm.rows()==3)
54
59
 
60
+ def test_IntvFullPivLU_3(self):
61
+ M = Matrix([
62
+ [ 1, -4, 6, 7, 6 ],
63
+ [ 2, 1, 3, 6, -2 ],
64
+ [ 5, 2, 8 , 9, -1 ]
65
+ ])
66
+ LUdec = IntvFullPivLU(M)
67
+ self.assertTrue(LUdec.is_injective()==BoolInterval.FALSE)
68
+ self.assertTrue(LUdec.is_surjective()==BoolInterval.TRUE)
69
+ self.assertTrue(LUdec.rank()==Interval(3))
70
+ self.assertTrue((LUdec.reconstructed_matrix()-M).norm().ub()<=1e-10)
71
+ K = LUdec.kernel()
72
+ self.assertTrue(K.cols()==2)
73
+ self.assertTrue((M*K).norm().ub()<1e-10)
74
+ Im = LUdec.image(M)
75
+ self.assertTrue(Im.cols()==3)
76
+ I1 = LUdec.solve(IntervalMatrix.eye(3,3));
77
+ self.assertTrue((M*I1-Matrix.eye(3,3)).norm().ub()<1e-10)
78
+ A = IntervalMatrix([ [1], [[-20,20]], [2], [[-20,20]], [[-20,20]] ])
79
+ B = IntervalMatrix([ [2.0], [1.0], [4.0] ])
80
+ LUdec.solve(B,A)
81
+ self.assertTrue((M*A-B).norm().ub()<=1e-10)
55
82
 
56
83
  if __name__ == '__main__':
57
84
  unittest.main()
@@ -97,6 +97,10 @@ class TestInterval(unittest.TestCase):
97
97
  self.assertTrue(x.mid() == 1)
98
98
  self.assertTrue(x.rad() == 1)
99
99
  self.assertTrue(x.diam() == 2)
100
+ self.assertTrue(x.mag() == 2)
101
+ self.assertTrue(x.mig() == 0)
102
+ self.assertTrue(x.smag() == 2)
103
+ self.assertTrue(x.smig() == 0)
100
104
 
101
105
  x = Interval(-3,-1)
102
106
 
@@ -105,6 +109,10 @@ class TestInterval(unittest.TestCase):
105
109
  self.assertTrue(x.mid() == -2)
106
110
  self.assertTrue(x.rad() == 1)
107
111
  self.assertTrue(x.diam() == 2)
112
+ self.assertTrue(x.mag() == 3)
113
+ self.assertTrue(x.mig() == 1)
114
+ self.assertTrue(x.smag() == -3)
115
+ self.assertTrue(x.smig() == -1)
108
116
 
109
117
  x = Interval(-3,1)
110
118
 
@@ -113,6 +121,10 @@ class TestInterval(unittest.TestCase):
113
121
  self.assertTrue(x.mid() == -1)
114
122
  self.assertTrue(x.rad() == 2)
115
123
  self.assertTrue(x.diam() == 4)
124
+ self.assertTrue(x.mag() == 3)
125
+ self.assertTrue(x.mig() == 0)
126
+ self.assertTrue(x.smag() == -3)
127
+ self.assertTrue(x.smig() == 0)
116
128
 
117
129
  x = Interval(-oo,0)
118
130
 
@@ -121,6 +133,10 @@ class TestInterval(unittest.TestCase):
121
133
  self.assertTrue(x.mid() == -sys.float_info.max)
122
134
  self.assertTrue(x.rad() == oo)
123
135
  self.assertTrue(x.diam() == oo)
136
+ self.assertTrue(x.mag() == oo)
137
+ self.assertTrue(x.mig() == 0)
138
+ self.assertTrue(x.smag() == -oo)
139
+ self.assertTrue(x.smig() == 0)
124
140
 
125
141
  x = Interval(-oo,oo)
126
142
 
@@ -129,6 +145,10 @@ class TestInterval(unittest.TestCase):
129
145
  self.assertTrue(x.mid() == 0)
130
146
  self.assertTrue(x.rad() == oo)
131
147
  self.assertTrue(x.diam() == oo)
148
+ self.assertTrue(x.mag() == oo)
149
+ self.assertTrue(x.mig() == 0)
150
+ self.assertTrue(x.smag() == oo)
151
+ self.assertTrue(x.smig() == 0)
132
152
 
133
153
  x = Interval(sys.float_info.max,oo)
134
154
 
@@ -137,17 +157,21 @@ class TestInterval(unittest.TestCase):
137
157
  self.assertTrue(x.mid() == sys.float_info.max)
138
158
  self.assertTrue(x.rad() == oo)
139
159
  self.assertTrue(x.diam() == oo)
160
+ self.assertTrue(x.mag() == oo)
161
+ self.assertTrue(x.mig() == sys.float_info.max)
162
+ self.assertTrue(x.smag() == oo)
163
+ self.assertTrue(x.smig() == sys.float_info.max)
140
164
 
141
165
  x = Interval(-1,1)
142
166
  for i in range(10):
143
167
  self.assertTrue(x.contains(x.rand()))
144
- x = Interval(-oo,0);
168
+ x = Interval(-oo,0)
145
169
  for i in range(10):
146
170
  self.assertTrue(x.contains(x.rand()))
147
- x = Interval(0,oo);
171
+ x = Interval(0,oo)
148
172
  for i in range(10):
149
173
  self.assertTrue(x.contains(x.rand()))
150
- x = Interval(-oo,oo);
174
+ x = Interval(-oo,oo)
151
175
  for i in range(10):
152
176
  self.assertTrue(x.contains(x.rand()))
153
177
  x = Interval.empty()
@@ -183,10 +207,10 @@ class TestInterval(unittest.TestCase):
183
207
  self.assertTrue(not Interval(0,next_float(0)).is_bisectable())
184
208
  self.assertTrue(Interval(0,next_float(next_float(0))).is_bisectable())
185
209
  self.assertTrue(Interval(10,next_float(next_float(10))).is_bisectable())
186
- self.assertTrue(Interval(previous_float(previous_float(0)),0).is_bisectable())
187
- self.assertTrue(Interval(previous_float(previous_float(10)),10).is_bisectable())
210
+ self.assertTrue(Interval(prev_float(prev_float(0)),0).is_bisectable())
211
+ self.assertTrue(Interval(prev_float(prev_float(10)),10).is_bisectable())
188
212
  self.assertTrue(not Interval(10,next_float(10)).is_bisectable())
189
- self.assertTrue(not Interval(previous_float(0),0).is_bisectable())
213
+ self.assertTrue(not Interval(prev_float(0),0).is_bisectable())
190
214
 
191
215
  self.assertTrue(Interval(0,2).mid() == 1.0)
192
216
  self.assertTrue(Interval(-oo,oo).mid() == 0)
@@ -88,13 +88,13 @@ class TestInterval_operations(unittest.TestCase):
88
88
  def test_interval_operations(self):
89
89
 
90
90
  self.assertTrue(0 < next_float(0))
91
- self.assertTrue(0 > previous_float(0))
91
+ self.assertTrue(0 > prev_float(0))
92
92
  self.assertTrue(1 < next_float(1))
93
- self.assertTrue(1 > previous_float(1))
93
+ self.assertTrue(1 > prev_float(1))
94
94
  self.assertTrue(oo == next_float(oo))
95
- self.assertTrue(-oo == previous_float(-oo))
95
+ self.assertTrue(-oo == prev_float(-oo))
96
96
  self.assertTrue(-MAX_DOUBLE >= next_float(-oo))
97
- self.assertTrue(MAX_DOUBLE <= previous_float(oo))
97
+ self.assertTrue(MAX_DOUBLE <= prev_float(oo))
98
98
  self.assertTrue(oo > MAX_DOUBLE)
99
99
  self.assertTrue(-oo < -MAX_DOUBLE)
100
100
  self.assertTrue(-Interval(0,1) == Interval(-1,0))
@@ -108,7 +108,7 @@ class TestInterval_operations(unittest.TestCase):
108
108
  self.CHECK_add(Interval(1,oo), Interval(0,1), Interval(1,oo))
109
109
  self.CHECK_add(Interval(-oo,oo), Interval(0,1), Interval(-oo,oo))
110
110
  self.CHECK_add(Interval(MAX_DOUBLE,oo), 1, Interval(MAX_DOUBLE,oo))
111
- self.CHECK_add(Interval(MAX_DOUBLE,oo), -1, Interval(previous_float(MAX_DOUBLE),oo))
111
+ self.CHECK_add(Interval(MAX_DOUBLE,oo), -1, Interval(prev_float(MAX_DOUBLE),oo))
112
112
  self.CHECK_add(Interval(MAX_DOUBLE,oo), Interval(MAX_DOUBLE,oo), Interval(MAX_DOUBLE,oo))
113
113
  self.CHECK_add(Interval(MAX_DOUBLE,oo), -oo, Interval.empty())
114
114
  self.CHECK_add(Interval(MAX_DOUBLE,oo), oo, Interval.empty())
@@ -260,7 +260,7 @@ class TestInterval_operations(unittest.TestCase):
260
260
  self.assertTrue(Approx(atan2(Interval(-1),1)) == -Interval.pi()/4.0)
261
261
  self.assertTrue(Approx(atan2(Interval(1),-1)) == 3*Interval.pi()/4.0)
262
262
  self.assertTrue(Approx(atan2(Interval(0,oo),Interval(0,oo))) == Interval(0,1)*Interval.half_pi())
263
- self.assertTrue(Approx(atan2(Interval(-oo,previous_float(0.0)),Interval(-oo,0))) == -(Interval.half_pi() | Interval.pi()))
263
+ self.assertTrue(Approx(atan2(Interval(-oo,prev_float(0.0)),Interval(-oo,0))) == -(Interval.half_pi() | Interval.pi()))
264
264
  self.assertTrue(Approx(atan2(Interval(-oo,0),Interval(0,oo))) == Interval(-1,0)*Interval.half_pi())
265
265
  self.assertTrue(Approx(atan2(Interval(0,oo),Interval(-oo,0))) == (Interval.half_pi() | Interval.pi()))
266
266
  self.assertTrue(Approx(atan2(Interval(1,oo),Interval(-1,1))) == (Interval.pi()/4.0 | 3*Interval.pi()/4.0))
@@ -28,5 +28,14 @@ class TestOctaSym(unittest.TestCase):
28
28
  c = OctaSym([-2,1,3])
29
29
  self.assertTrue(c.permutation_matrix() == Matrix([[0,-1,0],[1,0,0],[0,0,1]]))
30
30
 
31
+ def test_OctaSym_as_operator(self):
32
+
33
+ a = OctaSym([3,1,-2])
34
+ x = VectorVar(3)
35
+ f = AnalyticFunction([x], a(2*x))
36
+ self.assertTrue(f.eval(IntervalVector([[1],[2],[3]])) == IntervalVector([[6],[2],[-4]]))
37
+ self.assertTrue(f.eval(IntervalVector([[-oo,oo],[-oo,oo],[-oo,oo]])) == IntervalVector(3))
38
+ self.assertTrue(f.eval(IntervalVector.empty(3)) == IntervalVector.empty(3))
39
+
31
40
  if __name__ == '__main__':
32
41
  unittest.main()
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/env python
2
+
3
+ # Codac tests
4
+ # ----------------------------------------------------------------------------
5
+ # \date 2025
6
+ # \author Maël Godard
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
13
+ import math
14
+
15
+ class TestParallelepiped(unittest.TestCase):
16
+
17
+ def test_parallelepiped(self):
18
+
19
+ p = Parallelepiped(Vector([0,2,4]), Matrix([[0.5,0,0],[0,1,0],[0,1,1]]))
20
+
21
+ self.assertTrue(p.box() == IntervalVector([[-0.5,0.5],[1,3],[2,6]]))
22
+ self.assertTrue((p.contains(Vector([0.1,2.1,4.1])))==BoolInterval.TRUE)
23
+ self.assertTrue((p.contains(Vector([20.,20.,20.])))==BoolInterval.FALSE)
24
+
25
+ self.assertTrue((p.is_superset(IntervalVector([[0.,0.1],[2.,2.1],[4.,4.1]])))==BoolInterval.TRUE)
26
+ self.assertTrue((p.is_superset(IntervalVector([[-10.,-9.],[15.,16.],[12.,13.]])))==BoolInterval.FALSE)
27
+ self.assertTrue((p.is_superset(IntervalVector([[0.,5.],[2.,7.],[4.,9.]])))==BoolInterval.UNKNOWN)
28
+
29
+ z = p.proj([2,1,0])
30
+ self.assertTrue(z.z == Vector([4,2,0]))
31
+ self.assertTrue(z.A == Matrix([[0,1,1],[0,1,0],[0.5,0,0]]))
32
+ self.assertTrue(z.box() == IntervalVector([[2,6],[1,3],[-0.5,0.5]]))
33
+
34
+ if __name__ == '__main__':
35
+ unittest.main()
@@ -0,0 +1,62 @@
1
+ #!/usr/bin/env python
2
+
3
+ # Codac tests
4
+ # ----------------------------------------------------------------------------
5
+ # \date 2025
6
+ # \author Maël Godard
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
13
+ import math
14
+
15
+ class TestParallelepipedEval(unittest.TestCase):
16
+
17
+ def test_parallelepiped_eval(self):
18
+ x1 = ScalarVar()
19
+ x2 = ScalarVar()
20
+ x = VectorVar(2)
21
+
22
+ f1 = AnalyticFunction([x1], [x1,sqr(x1)])
23
+
24
+ f2 = AnalyticFunction([x1,x2], [x1, x2, sqr(x1)+sqr(x2)])
25
+ f3 = AnalyticFunction([x], [x[0], x[1], sqr(x[0])+sqr(x[1])])
26
+
27
+ p1a = f1.parallelepiped_eval(Interval(-0.1,0.1))
28
+ p1b = f1.parallelepiped_eval(1.0)
29
+
30
+ self.assertTrue(Approx(p1a.z,1e-6)==Vector([0.0,0.0]))
31
+ self.assertTrue(Approx(p1a.A,1e-6)==Matrix([[0.12,0.0],[0.0,0.02]]))
32
+ self.assertTrue(Approx(p1b.z,1e-6)==Vector([1.0,1.0]))
33
+ self.assertTrue(Approx(p1b.A,1e-6)==Matrix([[0.0,0.0],[0.0,0.0]]))
34
+
35
+ pa = f2.parallelepiped_eval(Interval(-0.1,0.1), Interval(-0.1,0.1))
36
+ pb = f2.parallelepiped_eval(1.0,Interval(-1,1))
37
+
38
+ self.assertTrue(Approx(pa.z,1e-6)==Vector([0,0,0]))
39
+ self.assertTrue(Approx(pa.A,1e-6)==Matrix([[0.14,0,0],[0,0.14,0],[0,0,0.04]]))
40
+ self.assertTrue(Approx(pb.z,1e-6)==Vector([1,0,1]))
41
+ self.assertTrue(Approx(pb.A,1e-5)==Matrix([[0.894428,0,1.78886],[0,3,0],[1.78886,0,-0.894427]]))
42
+
43
+
44
+ dx = 0.4
45
+ x0 = -2.0
46
+ while x0<2.0:
47
+ X0 = Interval(x0,x0+dx)
48
+ y0 = -2.0
49
+ while y0<2.0:
50
+ Y0 = Interval(y0,y0+dx)
51
+
52
+ p2 = f2.parallelepiped_eval(X0,Y0)
53
+ p3 = f3.parallelepiped_eval(IntervalVector([X0,Y0]))
54
+
55
+ self.assertTrue(Approx(p2.z,1e-6)==p3.z)
56
+ self.assertTrue(Approx(p2.A,1e-6)==p3.A)
57
+ y0 += dx
58
+ x0 += dx
59
+
60
+
61
+ if __name__ == '__main__':
62
+ unittest.main()
@@ -34,8 +34,7 @@ class TestPolygon(unittest.TestCase):
34
34
  self.assertTrue(p1.contains(IntervalVector(2)) == BoolInterval.FALSE)
35
35
  self.assertTrue(p1.is_empty())
36
36
  self.assertTrue(len(p1.edges()) == 0)
37
- self.assertTrue(len(p1.unsorted_vertices()) == 0)
38
- self.assertTrue(len(p1.sorted_vertices()) == 0)
37
+ self.assertTrue(len(p1.vertices()) == 0)
39
38
 
40
39
  def test_Polygon(self):
41
40
 
@@ -104,5 +103,18 @@ class TestPolygon(unittest.TestCase):
104
103
  self.assertTrue(p4.contains(IntervalVector([1,3])) == BoolInterval.TRUE)
105
104
  self.assertTrue(p4.contains(IntervalVector([1,2])) == BoolInterval.TRUE)
106
105
 
106
+ def test_Polygon_limit_case(self):
107
+
108
+ x = Vector([5,3.5])
109
+ p = Polygon([[4,3.5],[5,4],[4,4.5]])
110
+ self.assertTrue(p.contains(x) == BoolInterval.FALSE)
111
+
112
+ p1 = ConvexPolygon([[4,3.5],[5,4],[4.5,4.25],[4,4]])
113
+ self.assertTrue(p1.contains([4.5,4.25]) == BoolInterval.TRUE)
114
+ p2 = ConvexPolygon([[4,4.25],[5,4.25]])
115
+ i = p1 & p2
116
+ self.assertTrue(i == ConvexPolygon(IntervalVector([4.5,4.25])))
117
+ self.assertTrue(len(i.vertices()) == 1)
118
+
107
119
  if __name__ == '__main__':
108
120
  unittest.main()
@@ -9,7 +9,7 @@
9
9
 
10
10
  import unittest
11
11
  from codac import *
12
- import sys, math
12
+ import sys, math, numpy as np
13
13
 
14
14
  class TestSampledTraj(unittest.TestCase):
15
15
 
@@ -118,5 +118,18 @@ class TestSampledTraj(unittest.TestCase):
118
118
  x.set(Vector([0,float("nan")]),0.)
119
119
  self.assertTrue(x(1.).is_nan())
120
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
+
121
134
  if __name__ == '__main__':
122
135
  unittest.main()
@@ -14,13 +14,23 @@ def hull(x):
14
14
  if x == -oo:
15
15
  return Interval(-oo, next_float(-oo))
16
16
  if x == oo:
17
- return Interval(previous_float(oo), oo)
17
+ return Interval(prev_float(oo), oo)
18
18
  else:
19
- return INterval(x)
19
+ return Interval(x)
20
20
 
21
21
 
22
22
  class TestSegment(unittest.TestCase):
23
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
+
24
34
  def test_intersects(self):
25
35
 
26
36
  self.assertTrue(Segment([[0,0],[10,0]]).intersects(Segment([[4,0],[6,0]])) == BoolInterval.TRUE)
@@ -119,5 +129,10 @@ class TestSegment(unittest.TestCase):
119
129
  self.assertTrue((Segment([2,0],[6,4]) & Segment([6,5],[5,6])) == IntervalVector.empty(2))
120
130
  self.assertTrue(proj_intersection(Segment([2,0],[6,4]), Segment([6,5],[5,6])) == IntervalVector([6.5,4.5]))
121
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
+
122
137
  if __name__ == '__main__':
123
138
  unittest.main()
@@ -26,7 +26,7 @@ class TestSepCtcBoundary(unittest.TestCase):
26
26
  | CtcSegment([[1],[0]], [[0],[1]]) | CtcSegment([[0],[1]], [[-1],[0]])
27
27
 
28
28
  sep_diamond = SepCtcBoundary(ctc_bound_diamond,test_inside_diamond)
29
- #draw_while_paving(IntervalVector([[-2,2],[-2,2]]), sep_diamond, 0.1)
29
+ #DefaultFigure.pave(IntervalVector([[-2,2],[-2,2]]), sep_diamond, 0.1)
30
30
 
31
31
  x = IntervalVector(2)
32
32
  inner,outer = sep_diamond.separate(IntervalVector(2))
@@ -52,7 +52,7 @@ class TestSepPolygon(unittest.TestCase):
52
52
  [[-3,-3], [-2,3]]
53
53
  ])
54
54
 
55
- #draw_while_paving(IntervalVector([[-10,10],[-10,10]]), s, 0.1)
55
+ #DefaultFigure.pave(IntervalVector([[-10,10],[-10,10]]), s, 0.1)
56
56
 
57
57
  # Check a box inside the hole
58
58
 
@@ -17,10 +17,10 @@ class TestSepTransform(unittest.TestCase):
17
17
  x = VectorVar(2)
18
18
  s1 = SepInverse(AnalyticFunction([x], sqr(x[0])+sqr(x[1])), [0,1])
19
19
  s2 = SepTransform(s1,
20
- AnalyticFunction([x], vec(x[0]+2,x[1]+2)),
21
- AnalyticFunction([x], vec(x[0]-2,x[1]-2)))
20
+ AnalyticFunction([x], x-Vector([2,2])),
21
+ AnalyticFunction([x], x+Vector([2,2])))
22
22
 
23
- #pave([[-5,5],[-5,5]], s2, 0.01)
23
+ #DefaultFigure.pave([[-5,5],[-5,5]], s2, 0.01)
24
24
 
25
25
  inner,outer = s2.separate(IntervalVector(2))
26
26
  self.assertTrue(inner == IntervalVector(2))
@@ -31,9 +31,9 @@ class TestSepTransform(unittest.TestCase):
31
31
  self.assertTrue(outer == IntervalVector([[-2.2,-1.8],[-2.2,-1.8]]))
32
32
 
33
33
  b = IntervalVector([[-2.5,-1.5],[-2,10]])
34
- #DefaultFigure.draw_box(b,Color.purple())
34
+ #DefaultFigure.draw_box(b,[Color.purple(),Color.purple(0.3)])
35
35
  inner,outer = s2.separate(b)
36
- #DefaultFigure.draw_box(xs.inner,Color.green())
36
+ #DefaultFigure.draw_box(xs.inner,[Color.green(),Color.green(0.3)])
37
37
  self.assertTrue(Approx(inner,1e-1) == IntervalVector([[-2.5,-1.5],[-1.134,10]]))
38
38
  self.assertTrue(Approx(outer,1e-1) == IntervalVector([[-2.5,-1.5],[-2,-1]]))
39
39
 
@@ -0,0 +1,78 @@
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
13
+ import math
14
+
15
+ class TestSlice(unittest.TestCase):
16
+
17
+ def test_slice_inversion(self):
18
+
19
+ tdomain = create_tdomain([0,1])
20
+ x = SlicedTube(tdomain, Interval(0,10))
21
+ sx = x.first_slice()
22
+ x.set([2,3],0)
23
+ x.set([5,6],1)
24
+ self.assertTrue(sx.invert([4,6], 0) == Interval.empty())
25
+ self.assertTrue(sx.invert([2.5,6], 0) == 0.)
26
+ self.assertTrue(sx.invert([0,1], 1) == Interval.empty())
27
+ self.assertTrue(sx.invert([2.5,6], 1) == 1.)
28
+ self.assertTrue(sx.invert([2.5,6], [0.2,0.5]) == Interval(0.2,0.5))
29
+ self.assertTrue(sx.invert([2.5,6], 0.2) == Interval(0.2))
30
+
31
+ def test_slice_inversion_unbounded_derivative(self):
32
+
33
+ tdomain = create_tdomain([0,1])
34
+ x = SlicedTube(tdomain, Interval(0,10))
35
+ v = SlicedTube(tdomain, Interval())
36
+ sx = x.first_slice()
37
+ sv = v.first_slice()
38
+ self.assertTrue(sx.invert(5., sv, sx.t0_tf()) == Interval(0,1))
39
+ self.assertTrue(sx.invert(15., sv, sx.t0_tf()) == Interval.empty())
40
+
41
+ def test_slice_inversion_other_case(self):
42
+
43
+ tdomain = create_tdomain([6.4,6.5])
44
+ x = SlicedTube(tdomain, Interval(0.759,1.205))
45
+ v = SlicedTube(tdomain, Interval(-0.216,-0.115))
46
+ sx = x.first_slice()
47
+ sv = v.first_slice()
48
+
49
+ x.set([0.781,1.205],6.4)
50
+ x.set([0.759,1.194],6.5)
51
+
52
+ ctc_deriv = CtcDeriv()
53
+ ctc_deriv.contract(x,v)
54
+
55
+ self.assertTrue(not sx.codomain().is_empty())
56
+ self.assertTrue(Approx(sx.codomain(),1e-4) == Interval(0.7594, 1.20501))
57
+ self.assertTrue(Approx(sx.output_gate(),1e-4) == Interval(0.7594, 1.19351))
58
+
59
+ p = sx.polygon_slice(sv)
60
+
61
+ self.assertTrue(Approx(p,1e-4) == ConvexPolygon([
62
+ [[6.49999, 6.5],[0.7594, 0.759401]],
63
+ [[6.49999, 6.5],[1.1935, 1.19351]],
64
+ [[6.4, 6.40001],[1.20499, 1.20501]],
65
+ [[6.4, 6.40001],[0.780999, 0.781001]]
66
+ ]))
67
+
68
+ pt = IntervalVector([sx.t0_tf().ub(),1])
69
+
70
+ self.assertTrue(p.contains(pt) == BoolInterval.UNKNOWN)
71
+ self.assertTrue(p.box()[0].ub() == sx.t0_tf().ub())
72
+
73
+ p_inter = (p&ConvexPolygon(pt))
74
+ self.assertTrue(p_inter == ConvexPolygon(pt))
75
+
76
+
77
+ if __name__ == '__main__':
78
+ unittest.main()