Route_test.cpp
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 #include <gtest/gtest.h>
8 #include "fields2cover/types.h"
9 
10 TEST(fields2cover_types_route, init) {
11  EXPECT_TRUE(F2CRoute().asLineString().isEmpty());
13 
14  EXPECT_EQ(route.startPoint(), F2CPoint());
15  route.addConnection(F2CMultiPoint({F2CPoint(-2, -1), F2CPoint(0, -1), F2CPoint(0, 0)}));
16  EXPECT_EQ(route.getLastConnection().size(), 3);
17  EXPECT_EQ(route.startPoint(), F2CPoint(-2, -1));
19  swaths1.emplace_back(F2CLineString({F2CPoint(0, 0), F2CPoint(1, 0)}), 4);
20  swaths1.emplace_back(F2CLineString({F2CPoint(1, 1), F2CPoint(0, 1)}), 4);
21  route.addSwaths(swaths1);
22  EXPECT_EQ(route.getLastSwaths().size(), 2);
23  route.addConnection(F2CMultiPoint({F2CPoint(0, 1), F2CPoint(0, 2)}));
24  EXPECT_EQ(route.getLastConnection().size(), 2);
25  F2CSwaths swaths2;
26  swaths2.emplace_back(F2CLineString({F2CPoint(0, 2), F2CPoint(1, 2)}), 6);
27  swaths2.emplace_back(F2CLineString({F2CPoint(1, 3), F2CPoint(0, 3)}), 6);
28  swaths2.emplace_back(F2CLineString({F2CPoint(0, 4), F2CPoint(1, 4)}), 6);
29  swaths2.emplace_back(F2CLineString({F2CPoint(1, 5), F2CPoint(0, 5)}), 6);
30  route.addSwaths(swaths2);
31 
32  const F2CRoute c_route {route};
33  EXPECT_EQ(c_route.getLastSwaths().size(), 4);
34  EXPECT_EQ(c_route.getLastConnection().size(), 2);
35 
36  route.addConnection();
37  EXPECT_FALSE(route.isEmpty());
38  EXPECT_FALSE(route.asLineString().isEmpty());
39  EXPECT_EQ(route.sizeVectorSwaths(), 2);
40  EXPECT_EQ(route.sizeConnections(), 3);
41  EXPECT_EQ(route.asLineString().length(), 14);
42  EXPECT_EQ(route.length(), 14);
43  EXPECT_EQ(route.clone().length(), 14);
44  EXPECT_EQ(route.getSwaths(0).size(), 2);
45  EXPECT_EQ(route.getSwaths(1).size(), 4);
46 
47  route.addConnection(F2CMultiPoint({F2CPoint(0, 5), F2CPoint(0, 6)}));
48  route.addConnection(F2CMultiPoint({F2CPoint(0, 8), F2CPoint(5, 8)}));
49  route.addConnection(F2CMultiPoint({F2CPoint(5, 10), F2CPoint(10, 10)}));
50  EXPECT_EQ(route.sizeVectorSwaths(), 2);
51  EXPECT_EQ(route.sizeConnections(), 3);
53  swaths3.emplace_back(F2CLineString({F2CPoint(20, 20), F2CPoint(21, 20)}), 6);
54 
55  route.addConnectedSwaths(F2CMultiPoint({F2CPoint(10, 10), F2CPoint(20, 10)}), swaths3);
56  EXPECT_EQ(route.sizeVectorSwaths(), 3);
57  EXPECT_EQ(route.sizeConnections(), 3);
58  EXPECT_EQ(route.length(), 50);
59 
60  EXPECT_EQ(route.getConnection(0).size(), 3);
61  EXPECT_EQ(route.getSwaths(0).size(), 2);
62  EXPECT_EQ(route.getConnection(1).size(), 2);
63  EXPECT_EQ(route.getSwaths(1).size(), 4);
64  EXPECT_EQ(route.getConnection(2).size(), 8);
65  EXPECT_EQ(route.getSwaths(2).size(), 1);
66 
67  EXPECT_EQ(route.getLastConnection().size(), 8);
68  EXPECT_EQ(route.getLastSwaths().size(), 1);
69  EXPECT_EQ(route.getLastConnection().back(), F2CPoint(20, 10));
70  EXPECT_EQ(route.getLastSwaths().back().getPath().endPoint(), F2CPoint(21, 20));
71  F2CPoint p_rand1 (33, 44), p_rand2 (-22, 11), p_rand3(5, 6);
72  route.getLastSwaths().back().setPath(F2CLineString(p_rand1, p_rand2));
73  size_t n = route.getLastConnection().size();
74  route.getLastConnection().setGeometry(n-1, p_rand3);
75  EXPECT_EQ(route.getLastSwaths().back().getPath().endPoint(), p_rand2);
76  EXPECT_EQ(route.getLastConnection().back(), p_rand3);
77 
78  EXPECT_EQ(route.startPoint(), F2CPoint(-2, -1));
79 
80 
81  F2CRoute route2;
82  route2.addSwaths(c_route.getLastSwaths());
83  route2.addConnection(route.getLastConnection());
84  EXPECT_EQ(route2.startPoint(), F2CPoint(0, 2));
85  EXPECT_EQ(route2.endPoint(), p_rand3);
86 
87 
88 }
89 
90 
f2c::types::Swaths::emplace_back
void emplace_back(const Swath &s)
Definition: Swaths.cpp:29
F2CRoute
f2c::types::Route F2CRoute
Definition: types.h:49
types.h
f2c::types::Route::startPoint
Point startPoint() const
Definition: Route.cpp:123
TEST
TEST(fields2cover_types_route, init)
Definition: Route_test.cpp:10
2_objective_functions.swaths1
swaths1
Definition: 2_objective_functions.py:37
5_route_planning.route
route
Definition: 5_route_planning.py:29
f2c::types::Route::addSwaths
void addSwaths(const Swaths &s={})
Definition: Route.cpp:27
f2c::types::Route::addConnection
void addConnection()
Definition: Route.cpp:63
F2CLineString
f2c::types::LineString F2CLineString
Definition: types.h:40
f2c::types::Route
Definition: Route.h:23
f2c::types::Point
Definition: Point.h:21
2_objective_functions.swaths3
swaths3
Definition: 2_objective_functions.py:39
f2c::types::Swaths
Definition: Swaths.h:20
F2CMultiPoint
f2c::types::MultiPoint F2CMultiPoint
Definition: types.h:39
F2CPoint
f2c::types::Point F2CPoint
Definition: types.h:38
f2c::types::Route::endPoint
Point endPoint() const
Definition: Route.cpp:132


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