overlaps_test.py
Go to the documentation of this file.
1 #==============================================================================
2 # Copyright (C) 2021-2024 Wageningen University - All Rights Reserved
3 # Author: Gonzalo Mier
4 # BSD-3 License
5 #==============================================================================
6 
7 import pytest
8 import fields2cover as f2c
9 
10 def near(a, b, error = 1e-7):
11  assert abs(a - b) < error
12 
13 
15  path1 = f2c.LineString();
16  path2 = f2c.LineString();
17  path3 = f2c.LineString();
18  width = 2.0;
19  path1.addPoint( 0.0, 1.0);
20  path1.addPoint( 4.0, 1.0);
21  path2.addPoint( 0.0, 3.0);
22  path2.addPoint( 4.0, 3.0);
23  path3.addPoint( 0.0, 2.0);
24  path3.addPoint( 4.0, 2.0);
25  swath1 = f2c.Swath(path1, width);
26  swath2 = f2c.Swath(path2, width);
27  swath3 = f2c.Swath(path3, width);
28 
29  swaths_no_overlap = f2c.Swaths();
30  [swaths_no_overlap.push_back(i) for i in [swath1, swath2]]
31  swaths_overlap_025 = f2c.Swaths();
32  [swaths_overlap_025.push_back(i) for i in [swath1, swath3]]
33  swaths_overlap_050_1 = f2c.Swaths();
34  [swaths_overlap_050_1.push_back(i) for i in [swath1, swath2, swath3]]
35  swaths_overlap_050_2 = f2c.Swaths();
36  [swaths_overlap_050_2.push_back(i) for i in [swath2, swath1, swath3]]
37  swaths_overlap_050_3 = f2c.Swaths();
38  [swaths_overlap_050_3.push_back(i) for i in [swath2, swath2]]
39 
40  field = f2c.Cell();
41  fields = f2c.Cells();
42 
43  line = f2c.LinearRing();
44  line.addPoint(0, 0);
45  line.addPoint(4, 0);
46  line.addPoint(4, 4);
47  line.addPoint(0, 4);
48  line.addPoint(0, 0);
49  field.addRing(line);
50  fields.addGeometry(field);
51 
52  overlap = f2c.OBJ_Overlaps();
53 
54  near(overlap.computeCost(field, swaths_no_overlap), 0.0);
55  near(overlap.computeCost(fields, swaths_no_overlap), 0.0);
56  near(overlap.computeCostWithMinimizingSign(fields, swaths_no_overlap), 0.0);
57 
58  near(overlap.computeCost(fields, swaths_overlap_025), 0.25);
59  near(overlap.computeCostWithMinimizingSign(fields, swaths_overlap_025), 0.25);
60 
61  near(overlap.computeCost(fields, swaths_overlap_050_1), 0.5);
62  near(overlap.computeCostWithMinimizingSign(fields, swaths_overlap_050_1), 0.5);
63 
64  near(overlap.computeCost(fields, swaths_overlap_050_2), 0.5);
65  near(overlap.computeCostWithMinimizingSign(fields, swaths_overlap_050_2), 0.5);
66 
67  near(overlap.computeCost(fields, swaths_overlap_050_3), 0.5);
68  near(overlap.computeCostWithMinimizingSign(fields, swaths_overlap_050_3), 0.5);
69 
71  objective = f2c.OBJ_Overlaps();
72 
73  assert not (objective.isMaximizing());
74  assert (objective.isMinimizing());
75 
overlaps_test.near
def near(a, b, error=1e-7)
Definition: overlaps_test.py:10
overlaps_test.test_fields2cover_obj_overlaps_computeCost
def test_fields2cover_obj_overlaps_computeCost()
Definition: overlaps_test.py:14
overlaps_test.test_fields2cover_obj_overlaps_params_check
def test_fields2cover_obj_overlaps_params_check()
Definition: overlaps_test.py:70


fields2cover
Author(s):
autogenerated on Fri Apr 25 2025 02:18:31