8 import fields2cover
as f2c
10 def near(a, b, error = 1e-7):
11 assert abs(a - b) < error
16 swath1 = f2c.Swath(f2c.LineString(f2c.VectorPoint(
17 [f2c.Point(0.0, 1.0), f2c.Point(4.0, 1.0)])), width);
18 swath2 = f2c.Swath(f2c.LineString(f2c.VectorPoint(
19 [f2c.Point(0.0, 3.0), f2c.Point(4.0, 3.0)])), width);
20 swath3 = f2c.Swath(f2c.LineString(f2c.VectorPoint(
21 [f2c.Point(0.0, 2.0), f2c.Point(4.0, 2.0)])), width);
23 swaths = f2c.Swaths();
24 [swaths.push_back(i)
for i
in [swath1]]
27 line = f2c.LinearRing();
34 fields = f2c.Cells(field);
36 obj = f2c.OBJ_FieldCoverage();
37 near(obj.computeCost(field, swaths), 0.5, 1e-5);
38 near(obj.computeCost(fields, swaths), 0.5, 1e-5);
40 swaths.push_back(swath3);
41 near(obj.computeCost(fields, swaths), 0.75, 1e-5);
43 swaths.push_back(swath2);
44 near(obj.computeCost(fields, swaths), 1.0, 1e-5);
48 path1 = f2c.LineString();
49 path2 = f2c.LineString();
50 path3 = f2c.LineString();
52 path1.addPoint( 0.0, 1.0);
53 path1.addPoint( 4.0, 1.0);
54 path2.addPoint( 0.0, 3.0);
55 path2.addPoint( 4.0, 3.0);
56 path3.addPoint( 0.0, 2.0);
57 path3.addPoint( 4.0, 2.0);
58 swath1 = f2c.Swath(path1, width);
59 swath2 = f2c.Swath(path2, width);
60 swath3 = f2c.Swath(path3, width);
62 swaths_full = f2c.Swaths();
63 [swaths_full.push_back(i)
for i
in [swath1,swath2]]
64 swaths_overlap = f2c.Swaths();
65 [swaths_overlap.push_back(i)
for i
in [swath1,swath3]]
66 swaths_half = f2c.Swaths();
67 [swaths_half.push_back(i)
for i
in [swath1]]
72 line = f2c.LinearRing();
79 fields.addGeometry(field);
81 coverage = f2c.OBJ_FieldCoverage();
83 near(coverage.computeCost(fields, swaths_full), 1.0);
84 near(coverage.computeCostWithMinimizingSign(fields, swaths_full), -1.0);
86 near(coverage.computeCost(fields, swaths_overlap), 0.75);
87 near(coverage.computeCostWithMinimizingSign(fields, swaths_overlap), -0.75);
89 near(coverage.computeCost(fields, swaths_half), 0.5);
90 near(coverage.computeCostWithMinimizingSign(fields, swaths_half), -0.5);
93 objective = f2c.OBJ_FieldCoverage();
94 assert (objective.isMaximizing());
95 assert not (objective.isMinimizing());