boustrophedon_order_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):
11  assert pytest.approx(a) == pytest.approx(b)
12 
13 
15  n = 5;
16  swaths = f2c.Swaths();
17  for i in range(1, n):
18  swaths.push_back(f2c.Swath(f2c.LineString(f2c.VectorPoint( \
19  [f2c.Point(i, 0), f2c.Point(i, 1)])), i, i));
20 
21  swath_sorter = f2c.RP_Boustrophedon();
22  objective = f2c.OBJ_DirectDistPathObj();
23 
24  swaths = swath_sorter.genSortedSwaths(swaths);
25  near(swaths.size(), n - 1);
26  near(swaths[0].startPoint().getY(), 0);
27  for i in range(1, n):
28  near(swaths[i - 1].getWidth(), i);
29  near(objective.computeCost(swaths), 2*(n-1)-1);
30  swaths = swath_sorter.genSortedSwaths(swaths, 1);
31  near(swaths[0].startPoint().getY(), 0);
32  near(swaths[0].getWidth(), n-1);
33  near(swaths[1].getWidth(), n-2);
34  near(swaths[2].getWidth(), n-3);
35  near(objective.computeCost(swaths), 2*(n-1)-1);
36  swaths = swath_sorter.genSortedSwaths(swaths, 2);
37  near(swaths[0].startPoint().getY(), 1);
38  near(swaths[0].getWidth(), 1);
39  near(swaths[1].getWidth(), 2);
40  near(swaths[2].getWidth(), 3);
41  near(objective.computeCost(swaths), 2*(n-1)-1);
42  swaths = swath_sorter.genSortedSwaths(swaths, 3);
43  near(swaths[0].startPoint().getY(), 1);
44  near(swaths[0].getWidth(), n-1);
45  near(swaths[1].getWidth(), n-2);
46  near(swaths[2].getWidth(), n-3);
47  near(objective.computeCost(swaths), 2*(n-1)-1);
boustrophedon_order_test.near
def near(a, b)
Definition: boustrophedon_order_test.py:10
boustrophedon_order_test.test_fields2cover_route_boustrophedon_genSortedSwaths
def test_fields2cover_route_boustrophedon_genSortedSwaths()
Definition: boustrophedon_order_test.py:14


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