8 import fields2cover
as f2c
12 def near(a, b, error = 1e-7):
13 assert abs(a - b) < error
17 ring = f2c.LinearRing(f2c.VectorPoint([f2c.Point(-10,0), f2c.Point(-10,20), \
18 f2c.Point(10,20), f2c.Point(10,0), f2c.Point(-10,0)]));
23 near(polys[0].getDimMinX(), -10);
24 near(polys[0].getDimMinY(), 0);
25 near(polys[0].getDimMaxX(), 10);
26 near(polys[0].getDimMaxY(), 20);
27 near(polys[0].getHeight(), 20);
28 near(polys[0].getWidth(), 20);
29 near(polys[0].getMinSafeLength(), 40);
35 two_pi = 2.0 * math.pi;
36 for i
in range(10000):
37 rand_val = rand.getAngleRandom();
38 assert (rand_val < two_pi);
39 assert (rand_val >= 0.0);
46 rand_val = rand.getRandomDouble();
47 assert (rand_val < 1.0);
48 assert (rand_val > 0.0);
50 near(sum_val, N/2, N/10);
55 for i
in range(10000):
56 max_rand = rand.getRandomDouble();
57 min_rand = rand.getRandomDouble() - 1.0;
58 rand_val = rand.getRandomLinear(min_rand, max_rand);
59 assert (rand_val < max_rand);
60 assert (rand_val >= min_rand);
66 max_rand = rand.getRandomDouble() + 1.5;
67 min_rand = rand.getRandomDouble() + 0.5;
68 rand_val = rand.getRandomExp(min_rand, max_rand);
69 assert (rand_val < max_rand);
70 assert (rand_val >= min_rand);
79 for i
in range(steps):
80 mean += rand.getRandomExpDist(lambda_param);
83 assert (mean < (1/lambda_param) + epsilon);
84 assert (mean >= (1/lambda_param) - epsilon);
90 a = rand.getAngleRandom();
91 b = a + 2.0 * pi * math.floor(1000.0 * rand.getRandomDouble() - 500.0);
94 near(f2c.Point.getAngleDiffAbs(a, b), 0, 1e-7);
95 near(f2c.Point.getAngleDiffAbs(b, a), f2c.Point.getAngleDiffAbs(b, a), 1e-7);
96 near(f2c.Point.getAngleDiffAbs(a, c), pi/7, 1e-7);
97 near(f2c.Point.getAngleDiffAbs(c, a), f2c.Point.getAngleDiffAbs(c, a), 1e-7);
98 near(f2c.Point.getAngleDiffAbs(a, d), pi/9, 1e-7);
99 near(f2c.Point.getAngleDiffAbs(d, a), f2c.Point.getAngleDiffAbs(d, a), 1e-7);
101 ang1 = rand.getAngleRandom();
102 ang2 = rand.getAngleRandom();
103 near(f2c.Point.getAngleDiffAbs(ang1, ang2), f2c.Point.getAngleDiffAbs(ang2, ang1), 1e-7);
109 p1 = f2c.Point(1.0, 0.0);
110 p2 = f2c.Point(0.0, 1.0);
111 p3 = f2c.Point(1.0, 1.0);
112 p4 = f2c.Point(-1.0, 0.0);
113 p5 = f2c.Point(math.cos(20 * degree), math.sin(20 * degree));
114 near(p1.getAngleFromPoints(p1, p1), 0, 0.01);
115 near(p1.getAngleFromPoints(p1, p4), pi, 0.01);
116 near(p1.getAngleFromPoints(p1, p3), pi / 4.0, 0.01);
117 near(p1.getAngleFromPoints(p1, p2), pi / 2.0, 0.01);
118 near(p2.getAngleFromPoints(p2, p1), 3 * pi / 2.0, 0.01);
119 near(p1.getAngleFromPoints(p1, p5), 20.0 * degree, 0.01);
123 p = f2c.Point(0.0, 1.0);
124 ref = f2c.Point(1.0, 1.0);
125 res = p.getPointFromAngle(pi/4.0, math.sqrt(2.0));
126 near(res.getX(), ref.getX(), 0.01);
131 polygon = f2c.Cell();
132 polygon.addRing(ring);
133 polys.addGeometry(polygon);
134 line = f2c.LineString();
135 line.addPoint(-20, -10);
136 line.addPoint(-5, 5);
138 lines = f2c.MultiLineString();
139 lines.addGeometry(line);
141 reduced_line = polygon.getLinesInside(line);
142 assert (polys.crosses(line));
143 near(reduced_line.length(), math.sqrt(2.0)*5, 0.01);
145 reduced_line = polygon.getLinesInside(lines);
146 assert (polygon.crosses(lines));
147 near(reduced_line.length(), math.sqrt(2.0)*5, 0.01);
149 path = polys.getLinesInside(line);
150 near(path.length(), math.sqrt(2.0)*5, 0.01);
151 line.addPoint(20, 30);
152 reduced_line = polys.getLinesInside(line);
153 near(reduced_line.length(), math.sqrt(2.0)*20, 0.01);
155 lines2 = f2c.MultiLineString();
156 lines2.addGeometry(line);
157 reduced_line = polys.getLinesInside(lines2);
158 near(reduced_line.length(), math.sqrt(2.0)*20, 0.01);
161 for i
in np.arange(0.01, 100.0, 0.1):
163 near((ang % (2.0 * math.pi)), f2c.Point.mod_2pi(ang), 1e-3);
165 near(((1e5 * 2.0 * math.pi - i) % (2.0 * math.pi)), f2c.Point.mod_2pi(-i), 1e-3);
171 field = rand.generateRandField(1e2, 3);
172 poly = field.getField().getCell(0);
174 non_convex_fields = 0;
176 field = rand.genConvexField(1e2);
177 if (field.getField().isConvex()):
179 assert (convex_fields/n > 0.9999);
182 field = rand.genNonConvexField(1e2);
183 if (
not field.getField().isConvex()):
184 non_convex_fields += 1;
185 assert (non_convex_fields/n > 0.9999);
187 assert not (f2c.Cell().isConvex());
190 p_in = f2c.Point(1, 0);
191 p_out = f2c.Point(1, 0);
193 p_out = f2c.Point(0,0).rotateFromPoint(pi/2.0, p_out);
194 near(p_out.getX(), 0, 1e-7);
195 near(p_out.getY(), 1, 1e-7);
196 p_out = f2c.Point(0,0).rotateFromPoint(pi/2.0, p_out);
197 near(p_out.getX(), -1, 1e-7);
198 near(p_out.getY(), 0, 1e-7);
199 p_out = f2c.Point(0,0).rotateFromPoint(pi/2.0, p_out);
200 near(p_out.getX(), 0, 1e-7);
201 near(p_out.getY(), -1, 1e-7);
202 p_out = f2c.Point(0,0).rotateFromPoint(pi/2.0, p_out);
203 near(p_out.getX(), 1, 1e-7);
204 near(p_out.getY(), 0, 1e-7);
205 p_out = p_in.rotateFromPoint(pi/2.0, p_out);
206 near(p_out.getX(), 1, 1e-7);
207 near(p_out.getY(), 0, 1e-7);
208 p_out = f2c.Point(0.5, 0).rotateFromPoint(pi/2.0, p_out);
209 near(p_out.getX(), 0.5, 1e-7);
210 near(p_out.getY(), 0.5, 1e-7);
212 line = f2c.LineString();
215 p_center = f2c.Point(5, 6)
216 line = p_center.rotateFromPoint(pi, line);
217 p_out = line.startPoint();
218 near(p_out.getX(), 9, 1e-7);
219 near(p_out.getY(), 10, 1e-7);
220 p_out = line.endPoint();
221 near(p_out.getX(), 7, 1e-7);
222 near(p_out.getY(), 8, 1e-7);