1 #include <gtest/gtest.h>
2 #include <marnav/geo/cpa.hpp>
4 using namespace marnav::geo
;
9 class Test_geo_cpa
: public ::testing::Test
13 TEST_F(Test_geo_cpa
, collision_on_equator_eastwards_westwards
)
15 const vessel vessel1
= {{0.0, 1.0}, 1.0, 90.0}; // being west, going east
16 const vessel vessel2
= {{0.0, -1.0}, 1.0, 270.0}; // being east, going west
18 // 2 degrees appart = 120nm, closing in at each 1kn => 60h
19 const position expected_vessels_pos
{0.0, 0.0};
20 const std::chrono::seconds expected_time
{60 * 3600};
24 std::chrono::seconds tcpa
;
26 std::tie(p1
, p2
, tcpa
, cpa_exists
) = cpa(vessel1
, vessel2
);
28 EXPECT_NEAR(expected_vessels_pos
.lat(), p1
.lat(), 1e-5);
29 EXPECT_NEAR(expected_vessels_pos
.lon(), p1
.lon(), 1e-5);
30 EXPECT_NEAR(expected_vessels_pos
.lat(), p2
.lat(), 1e-5);
31 EXPECT_NEAR(expected_vessels_pos
.lon(), p2
.lon(), 1e-5);
32 EXPECT_NEAR(p1
.lat(), p2
.lat(), 1e-5);
33 EXPECT_NEAR(p1
.lon(), p2
.lon(), 1e-5);
34 EXPECT_EQ(expected_time
, tcpa
);
35 EXPECT_TRUE(cpa_exists
);
38 TEST_F(Test_geo_cpa
, collision_on_equator_eastwards_northwards
)
40 const vessel vessel1
= {{0.0, 1.0}, 1.0, 90.0}; // being west, going east
41 const vessel vessel2
= {{-1.0, 0.0}, 1.0, 0.0}; // being south, going north
43 // each vessel 1 degree appart from CPA = 60nm, closing in at 1kn => 60h
44 const position expected_vessels_pos
{0.0, 0.0};
45 const std::chrono::seconds expected_time
{60 * 3600};
49 std::chrono::seconds tcpa
;
51 std::tie(p1
, p2
, tcpa
, cpa_exists
) = cpa(vessel1
, vessel2
);
53 EXPECT_NEAR(expected_vessels_pos
.lat(), p1
.lat(), 1e-5);
54 EXPECT_NEAR(expected_vessels_pos
.lon(), p1
.lon(), 1e-5);
55 EXPECT_NEAR(expected_vessels_pos
.lat(), p2
.lat(), 1e-5);
56 EXPECT_NEAR(expected_vessels_pos
.lon(), p2
.lon(), 1e-5);
57 EXPECT_NEAR(p1
.lat(), p2
.lat(), 1e-5);
58 EXPECT_NEAR(p1
.lon(), p2
.lon(), 1e-5);
59 EXPECT_EQ(expected_time
, tcpa
);
60 EXPECT_EQ(std::chrono::minutes(60 * 60), tcpa
);
61 EXPECT_EQ(std::chrono::hours(60), tcpa
);
62 EXPECT_TRUE(cpa_exists
);