diff --git a/UnitTests/DataStructures/BinaryHeapTest.cpp b/UnitTests/DataStructures/BinaryHeapTest.cpp index f4b200a1d..dc2b21b30 100644 --- a/UnitTests/DataStructures/BinaryHeapTest.cpp +++ b/UnitTests/DataStructures/BinaryHeapTest.cpp @@ -15,22 +15,20 @@ struct TestData }; typedef NodeID TestNodeID; -typedef int TestKey; -typedef int TestWeight; +typedef int TestKey; +typedef int TestWeight; typedef boost::mpl::list, MapStorage, UnorderedMapStorage> storage_types; - -template -struct RandomDataFixture +template struct RandomDataFixture { RandomDataFixture() { for (unsigned i = 0; i < NUM_ELEM; i++) { - data.push_back(TestData {i*3}); - weights.push_back((i+1)*100); + data.push_back(TestData{i * 3}); + weights.push_back((i + 1) * 100); ids.push_back(i); order.push_back(i); } @@ -41,10 +39,10 @@ struct RandomDataFixture std::shuffle(order.begin(), order.end(), g); } - std::vector data; + std::vector data; std::vector weights; std::vector ids; - std::vector order; + std::vector order; }; constexpr unsigned NUM_NODES = 100; @@ -74,10 +72,10 @@ BOOST_FIXTURE_TEST_CASE_TEMPLATE(insert_test, T, storage_types, RandomDataFixtur for (auto id : ids) { - const auto& d = heap.GetData(id); + const auto &d = heap.GetData(id); BOOST_CHECK_EQUAL(d.value, data[id].value); - const auto& w = heap.GetKey(id); + const auto &w = heap.GetKey(id); BOOST_CHECK_EQUAL(w, weights[id]); } } @@ -97,8 +95,8 @@ BOOST_FIXTURE_TEST_CASE_TEMPLATE(delete_min_test, T, storage_types, RandomDataFi BOOST_CHECK_EQUAL(heap.Min(), id); BOOST_CHECK_EQUAL(id, heap.DeleteMin()); - if (id+1 < NUM_NODES) - BOOST_CHECK_EQUAL(heap.Min(), id+1); + if (id + 1 < NUM_NODES) + BOOST_CHECK_EQUAL(heap.Min(), id + 1); BOOST_CHECK(heap.WasRemoved(id)); } @@ -151,4 +149,3 @@ BOOST_FIXTURE_TEST_CASE_TEMPLATE(decrease_key_test, T, storage_types, RandomData } BOOST_AUTO_TEST_SUITE_END() - diff --git a/UnitTests/DataStructures/RangeTableTest.cpp b/UnitTests/DataStructures/RangeTableTest.cpp index 311c77ec3..c439badbf 100644 --- a/UnitTests/DataStructures/RangeTableTest.cpp +++ b/UnitTests/DataStructures/RangeTableTest.cpp @@ -21,17 +21,18 @@ void ConstructionTest(std::vector lengths, std::vector offse { auto range = table.GetRange(i); BOOST_CHECK_EQUAL(range.front(), offsets[i]); - BOOST_CHECK_EQUAL(range.back()+1, offsets[i+1]); + BOOST_CHECK_EQUAL(range.back() + 1, offsets[i + 1]); } } -void ComputeLengthsOffsets(std::vector& lengths, std::vector& offsets, unsigned num) +void +ComputeLengthsOffsets(std::vector &lengths, std::vector &offsets, unsigned num) { lengths.resize(num); - offsets.resize(num+1); + offsets.resize(num + 1); std::iota(lengths.begin(), lengths.end(), 1); offsets[0] = 0; - std::partial_sum(lengths.begin(), lengths.end(), offsets.begin()+1); + std::partial_sum(lengths.begin(), lengths.end(), offsets.begin() + 1); std::stringstream l_ss; l_ss << "Lengths: "; @@ -49,7 +50,7 @@ BOOST_AUTO_TEST_CASE(serialization_test) { std::vector lengths; std::vector offsets; - ComputeLengthsOffsets(lengths, offsets, (BLOCK_SIZE+1)*10); + ComputeLengthsOffsets(lengths, offsets, (BLOCK_SIZE + 1) * 10); TestRangeTable in_table(lengths); TestRangeTable out_table; @@ -62,7 +63,7 @@ BOOST_AUTO_TEST_CASE(serialization_test) { auto range = out_table.GetRange(i); BOOST_CHECK_EQUAL(range.front(), offsets[i]); - BOOST_CHECK_EQUAL(range.back()+1, offsets[i+1]); + BOOST_CHECK_EQUAL(range.back() + 1, offsets[i + 1]); } } @@ -82,7 +83,7 @@ BOOST_AUTO_TEST_CASE(construction_test) // [(153)] {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} std::vector full_lengths; std::vector full_offsets; - ComputeLengthsOffsets(full_lengths, full_offsets, BLOCK_SIZE+1); + ComputeLengthsOffsets(full_lengths, full_offsets, BLOCK_SIZE + 1); ConstructionTest(full_lengths, full_offsets); // first block full and offset of next block not sentinel, but the first differential value @@ -90,13 +91,13 @@ BOOST_AUTO_TEST_CASE(construction_test) // [153] {(17), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} std::vector over_full_lengths; std::vector over_full_offsets; - ComputeLengthsOffsets(over_full_lengths, over_full_offsets, BLOCK_SIZE+2); + ComputeLengthsOffsets(over_full_lengths, over_full_offsets, BLOCK_SIZE + 2); ConstructionTest(over_full_lengths, over_full_offsets); // test multiple blocks std::vector multiple_lengths; std::vector multiple_offsets; - ComputeLengthsOffsets(multiple_lengths, multiple_offsets, (BLOCK_SIZE+1)*10); + ComputeLengthsOffsets(multiple_lengths, multiple_offsets, (BLOCK_SIZE + 1) * 10); ConstructionTest(multiple_lengths, multiple_offsets); } diff --git a/UnitTests/DataStructures/StaticGraphTest.cpp b/UnitTests/DataStructures/StaticGraphTest.cpp index 9434a3703..db2fddefa 100644 --- a/UnitTests/DataStructures/StaticGraphTest.cpp +++ b/UnitTests/DataStructures/StaticGraphTest.cpp @@ -24,24 +24,23 @@ struct TestEdge unsigned distance; }; -typedef StaticGraph TestStaticGraph; +typedef StaticGraph TestStaticGraph; typedef TestStaticGraph::NodeArrayEntry TestNodeArrayEntry; typedef TestStaticGraph::EdgeArrayEntry TestEdgeArrayEntry; -typedef TestStaticGraph::InputEdge TestInputEdge; +typedef TestStaticGraph::InputEdge TestInputEdge; constexpr unsigned TEST_NUM_NODES = 100; constexpr unsigned TEST_NUM_EDGES = 500; // Choosen by a fair W20 dice roll (this value is completely arbitrary) constexpr unsigned RANDOM_SEED = 15; -template -struct RandomArrayEntryFixture +template struct RandomArrayEntryFixture { RandomArrayEntryFixture() { std::mt19937 g(RANDOM_SEED); - std::uniform_int_distribution<> edge_udist(0, NUM_EDGES-1); + std::uniform_int_distribution<> edge_udist(0, NUM_EDGES - 1); std::vector offsets; for (unsigned i = 0; i < NUM_NODES; i++) { @@ -52,27 +51,24 @@ struct RandomArrayEntryFixture offsets.push_back(offsets.back()); // extract interval lengths - for(unsigned i = 0; i < offsets.size()-1; i++) + for (unsigned i = 0; i < offsets.size() - 1; i++) { - lengths.push_back(offsets[i+1] - offsets[i]); + lengths.push_back(offsets[i + 1] - offsets[i]); } - lengths.push_back(NUM_EDGES - offsets[NUM_NODES-1]); + lengths.push_back(NUM_EDGES - offsets[NUM_NODES - 1]); for (auto offset : offsets) { - nodes.emplace_back(TestNodeArrayEntry {offset}); + nodes.emplace_back(TestNodeArrayEntry{offset}); } std::uniform_int_distribution<> lengths_udist(0, 100000); - std::uniform_int_distribution<> node_udist(0, NUM_NODES-1); + std::uniform_int_distribution<> node_udist(0, NUM_NODES - 1); for (unsigned i = 0; i < NUM_EDGES; i++) { edges.emplace_back( - TestEdgeArrayEntry { - static_cast(node_udist(g)), - TestData {i, false, static_cast(lengths_udist(g))} - } - ); + TestEdgeArrayEntry{static_cast(node_udist(g)), + TestData{i, false, static_cast(lengths_udist(g))}}); } for (unsigned i = 0; i < NUM_NODES; i++) @@ -99,24 +95,20 @@ BOOST_FIXTURE_TEST_CASE(array_test, TestRandomArrayEntryFixture) for (auto idx : order) { - BOOST_CHECK_EQUAL(graph.BeginEdges((NodeID) idx), nodes_copy[idx].first_edge); - BOOST_CHECK_EQUAL(graph.EndEdges((NodeID) idx), nodes_copy[idx+1].first_edge); - BOOST_CHECK_EQUAL(graph.GetOutDegree((NodeID) idx), lengths[idx]); + BOOST_CHECK_EQUAL(graph.BeginEdges((NodeID)idx), nodes_copy[idx].first_edge); + BOOST_CHECK_EQUAL(graph.EndEdges((NodeID)idx), nodes_copy[idx + 1].first_edge); + BOOST_CHECK_EQUAL(graph.GetOutDegree((NodeID)idx), lengths[idx]); } } -TestStaticGraph GraphFromEdgeList(const std::vector& edges) +TestStaticGraph GraphFromEdgeList(const std::vector &edges) { std::vector input_edges; unsigned i = 0; unsigned num_nodes = 0; - for (const auto& e : edges) + for (const auto &e : edges) { - input_edges.push_back(TestInputEdge { - e.source, - e.target, - TestData {i++, false, e.distance} - }); + input_edges.push_back(TestInputEdge{e.source, e.target, TestData{i++, false, e.distance}}); num_nodes = std::max(num_nodes, std::max(e.source, e.target)); } @@ -134,13 +126,11 @@ BOOST_AUTO_TEST_CASE(find_test) * (3) -4-> (4) * <-3- */ - TestStaticGraph simple_graph = GraphFromEdgeList({ - TestEdge {0, 1, 1}, - TestEdge {3, 0, 2}, - TestEdge {3, 4, 4}, - TestEdge {4, 3, 3}, - TestEdge {3, 0, 1} - }); + TestStaticGraph simple_graph = GraphFromEdgeList({TestEdge{0, 1, 1}, + TestEdge{3, 0, 2}, + TestEdge{3, 4, 4}, + TestEdge{4, 3, 3}, + TestEdge{3, 0, 1}}); auto eit = simple_graph.FindEdge(0, 1); BOOST_CHECK_EQUAL(simple_graph.GetEdgeData(eit).id, 0); @@ -172,4 +162,3 @@ BOOST_AUTO_TEST_CASE(find_test) } BOOST_AUTO_TEST_SUITE_END() - diff --git a/UnitTests/DataStructures/StaticRTreeTest.cpp b/UnitTests/DataStructures/StaticRTreeTest.cpp index df0f0e8c0..8e7511daa 100644 --- a/UnitTests/DataStructures/StaticRTreeTest.cpp +++ b/UnitTests/DataStructures/StaticRTreeTest.cpp @@ -16,31 +16,30 @@ BOOST_AUTO_TEST_SUITE(static_rtree) constexpr uint32_t TEST_BRANCHING_FACTOR = 8; -constexpr uint32_t TEST_LEAF_NODE_SIZE = 64; +constexpr uint32_t TEST_LEAF_NODE_SIZE = 64; typedef EdgeBasedNode TestData; typedef StaticRTree, false, TEST_BRANCHING_FACTOR, - TEST_LEAF_NODE_SIZE> - TestStaticRTree; + TEST_LEAF_NODE_SIZE> TestStaticRTree; // Choosen by a fair W20 dice roll (this value is completely arbitrary) constexpr unsigned RANDOM_SEED = 15; -static const int32_t WORLD_MIN_LAT = -90*COORDINATE_PRECISION; -static const int32_t WORLD_MAX_LAT = 90*COORDINATE_PRECISION; -static const int32_t WORLD_MIN_LON = -180*COORDINATE_PRECISION; -static const int32_t WORLD_MAX_LON = 180*COORDINATE_PRECISION; +static const int32_t WORLD_MIN_LAT = -90 * COORDINATE_PRECISION; +static const int32_t WORLD_MAX_LAT = 90 * COORDINATE_PRECISION; +static const int32_t WORLD_MIN_LON = -180 * COORDINATE_PRECISION; +static const int32_t WORLD_MAX_LON = 180 * COORDINATE_PRECISION; class LinearSearchNN { -public: - LinearSearchNN(const std::shared_ptr>& coords, - const std::vector& edges) - : coords(coords) - , edges(edges) - { } + public: + LinearSearchNN(const std::shared_ptr> &coords, + const std::vector &edges) + : coords(coords), edges(edges) + { + } bool LocateClosestEndPointForCoordinate(const FixedPointCoordinate &input_coordinate, FixedPointCoordinate &result_coordinate, @@ -50,18 +49,15 @@ public: float min_dist = std::numeric_limits::max(); FixedPointCoordinate min_coord; - for (const TestData& e : edges) + for (const TestData &e : edges) { if (ignore_tiny_components && e.is_in_tiny_cc) continue; - const FixedPointCoordinate& start = coords->at(e.u); - const FixedPointCoordinate& end = coords->at(e.v); + const FixedPointCoordinate &start = coords->at(e.u); + const FixedPointCoordinate &end = coords->at(e.v); float distance = FixedPointCoordinate::ApproximateEuclideanDistance( - input_coordinate.lat, - input_coordinate.lon, - start.lat, - start.lon); + input_coordinate.lat, input_coordinate.lon, start.lat, start.lon); if (distance < min_dist) { min_coord = start; @@ -69,10 +65,7 @@ public: } distance = FixedPointCoordinate::ApproximateEuclideanDistance( - input_coordinate.lat, - input_coordinate.lon, - end.lat, - end.lon); + input_coordinate.lat, input_coordinate.lon, end.lat, end.lon); if (distance < min_dist) { min_coord = end; @@ -92,7 +85,7 @@ public: float min_dist = std::numeric_limits::max(); TestData nearest_edge; - for (const TestData& e : edges) + for (const TestData &e : edges) { if (ignore_tiny_components && e.is_in_tiny_cc) continue; @@ -101,26 +94,22 @@ public: FixedPointCoordinate nearest; const float current_perpendicular_distance = FixedPointCoordinate::ComputePerpendicularDistance( - coords->at(e.u), - coords->at(e.v), - input_coordinate, - nearest, - current_ratio); + coords->at(e.u), coords->at(e.v), input_coordinate, nearest, current_ratio); if ((current_perpendicular_distance < min_dist) && !EpsilonCompare(current_perpendicular_distance, min_dist)) { // found a new minimum min_dist = current_perpendicular_distance; - result_phantom_node = { e.forward_edge_based_node_id, - e.reverse_edge_based_node_id, - e.name_id, - e.forward_weight, - e.reverse_weight, - e.forward_offset, - e.reverse_offset, - e.packed_geometry_id, - nearest, - e.fwd_segment_position}; + result_phantom_node = {e.forward_edge_based_node_id, + e.reverse_edge_based_node_id, + e.name_id, + e.forward_weight, + e.reverse_weight, + e.forward_offset, + e.reverse_offset, + e.packed_geometry_id, + nearest, + e.fwd_segment_position}; nearest_edge = e; } } @@ -138,11 +127,9 @@ public: } const float distance_1 = FixedPointCoordinate::ApproximateEuclideanDistance( - coords->at(nearest_edge.u), - result_phantom_node.location); + coords->at(nearest_edge.u), result_phantom_node.location); const float distance_2 = FixedPointCoordinate::ApproximateEuclideanDistance( - coords->at(nearest_edge.u), - coords->at(nearest_edge.v)); + coords->at(nearest_edge.u), coords->at(nearest_edge.v)); const float ratio = std::min(1.f, distance_1 / distance_2); if (SPECIAL_NODEID != result_phantom_node.forward_node_id) @@ -158,31 +145,28 @@ public: return result_phantom_node.location.isValid(); } -private: - const std::shared_ptr>& coords; - const std::vector& edges; + private: + const std::shared_ptr> &coords; + const std::vector &edges; }; - -template -struct RandomGraphFixture +template struct RandomGraphFixture { struct TupleHash { - typedef std::pair argument_type; - typedef std::size_t result_type; + typedef std::pair argument_type; + typedef std::size_t result_type; - result_type operator()(const argument_type & t) const + result_type operator()(const argument_type &t) const { - std::size_t val { 0 }; + std::size_t val{0}; boost::hash_combine(val, t.first); boost::hash_combine(val, t.second); return val; } }; - RandomGraphFixture() - : coords(std::make_shared>()) + RandomGraphFixture() : coords(std::make_shared>()) { BOOST_TEST_MESSAGE("Constructing " << NUM_NODES << " nodes and " << NUM_EDGES << " edges."); @@ -203,19 +187,19 @@ struct RandomGraphFixture std::unordered_set, TupleHash> used_edges; - while(edges.size() < NUM_EDGES) + while (edges.size() < NUM_EDGES) { TestData data; data.u = edge_udist(g); data.v = edge_udist(g); - if (used_edges.find(std::pair(std::min(data.u, data.v), std::max(data.u, data.v))) == used_edges.end()) + if (used_edges.find(std::pair( + std::min(data.u, data.v), std::max(data.u, data.v))) == used_edges.end()) { data.is_in_tiny_cc = false; edges.emplace_back(data); used_edges.emplace(std::min(data.u, data.v), std::max(data.u, data.v)); } } - } std::vector nodes; @@ -225,26 +209,26 @@ struct RandomGraphFixture struct GraphFixture { - GraphFixture(const std::vector>& input_coords, - const std::vector>& input_edges) - : coords(std::make_shared>()) + GraphFixture(const std::vector> &input_coords, + const std::vector> &input_edges) + : coords(std::make_shared>()) { for (unsigned i = 0; i < input_coords.size(); i++) { - FixedPointCoordinate c(input_coords[i].first * COORDINATE_PRECISION, input_coords[i].second * COORDINATE_PRECISION); + FixedPointCoordinate c(input_coords[i].first * COORDINATE_PRECISION, + input_coords[i].second * COORDINATE_PRECISION); coords->emplace_back(c); nodes.emplace_back(NodeInfo(c.lat, c.lon, i)); } - for (const auto& pair : input_edges) + for (const auto &pair : input_edges) { TestData d; d.u = pair.first; d.v = pair.second; edges.emplace_back(d); } - } std::vector nodes; @@ -252,44 +236,44 @@ struct GraphFixture std::vector edges; }; +typedef RandomGraphFixture +TestRandomGraphFixture_LeafHalfFull; +typedef RandomGraphFixture +TestRandomGraphFixture_LeafFull; +typedef RandomGraphFixture +TestRandomGraphFixture_TwoLeaves; +typedef RandomGraphFixture +TestRandomGraphFixture_Branch; +typedef RandomGraphFixture +TestRandomGraphFixture_MultipleLevels; -typedef RandomGraphFixture TestRandomGraphFixture_LeafHalfFull; -typedef RandomGraphFixture TestRandomGraphFixture_LeafFull; -typedef RandomGraphFixture TestRandomGraphFixture_TwoLeaves; -typedef RandomGraphFixture TestRandomGraphFixture_Branch; -typedef RandomGraphFixture TestRandomGraphFixture_MultipleLevels; - -template -void simple_verify_rtree(RTreeT& rtree, const std::shared_ptr>& coords, const std::vector& edges) +template +void simple_verify_rtree(RTreeT &rtree, + const std::shared_ptr> &coords, + const std::vector &edges) { BOOST_TEST_MESSAGE("Verify end points"); - for (const auto& e : edges) + for (const auto &e : edges) { FixedPointCoordinate result_u, result_v; - const FixedPointCoordinate& pu = coords->at(e.u); - const FixedPointCoordinate& pv = coords->at(e.v); + const FixedPointCoordinate &pu = coords->at(e.u); + const FixedPointCoordinate &pv = coords->at(e.v); bool found_u = rtree.LocateClosestEndPointForCoordinate(pu, result_u, 1); bool found_v = rtree.LocateClosestEndPointForCoordinate(pv, result_v, 1); BOOST_CHECK(found_u && found_v); float dist_u = FixedPointCoordinate::ApproximateEuclideanDistance( - result_u.lat, - result_u.lon, - pu.lat, - pu.lon); + result_u.lat, result_u.lon, pu.lat, pu.lon); BOOST_CHECK_LE(dist_u, std::numeric_limits::epsilon()); float dist_v = FixedPointCoordinate::ApproximateEuclideanDistance( - result_v.lat, - result_v.lon, - pv.lat, - pv.lon); + result_v.lat, result_v.lon, pv.lat, pv.lon); BOOST_CHECK_LE(dist_v, std::numeric_limits::epsilon()); } } -template -void sampling_verify_rtree(RTreeT& rtree, LinearSearchNN& lsnn, unsigned num_samples) +template +void sampling_verify_rtree(RTreeT &rtree, LinearSearchNN &lsnn, unsigned num_samples) { std::mt19937 g(RANDOM_SEED); std::uniform_int_distribution<> lat_udist(WORLD_MIN_LAT, WORLD_MAX_LAT); @@ -297,13 +281,11 @@ void sampling_verify_rtree(RTreeT& rtree, LinearSearchNN& lsnn, unsigned num_sam std::vector queries; for (unsigned i = 0; i < num_samples; i++) { - queries.emplace_back( - FixedPointCoordinate(lat_udist(g), lon_udist(g)) - ); + queries.emplace_back(FixedPointCoordinate(lat_udist(g), lon_udist(g))); } BOOST_TEST_MESSAGE("Sampling queries"); - for (const auto& q : queries) + for (const auto &q : queries) { FixedPointCoordinate result_rtree; rtree.LocateClosestEndPointForCoordinate(q, result_rtree, 1); @@ -319,8 +301,11 @@ void sampling_verify_rtree(RTreeT& rtree, LinearSearchNN& lsnn, unsigned num_sam } } -template -void build_rtree(const std::string& prefix, FixtureT* fixture, std::string& leaves_path, std::string& nodes_path) +template +void build_rtree(const std::string &prefix, + FixtureT *fixture, + std::string &leaves_path, + std::string &nodes_path) { nodes_path = prefix + ".ramIndex"; leaves_path = prefix + ".fileIndex"; @@ -335,8 +320,8 @@ void build_rtree(const std::string& prefix, FixtureT* fixture, std::string& leav RTreeT r(fixture->edges, nodes_path, leaves_path, fixture->nodes); } -template -void construction_test(const std::string& prefix, FixtureT* fixture) +template +void construction_test(const std::string &prefix, FixtureT *fixture) { std::string leaves_path; std::string nodes_path; @@ -382,39 +367,29 @@ BOOST_AUTO_TEST_CASE(regression_test) typedef std::pair Coord; typedef std::pair Edge; GraphFixture fixture({ - Coord(40.0, 0.0), - Coord(35.0, 5.0), + Coord(40.0, 0.0), + Coord(35.0, 5.0), - Coord(5.0, 5.0), - Coord(0.0, 10.0), + Coord(5.0, 5.0), + Coord(0.0, 10.0), - Coord(20.0, 10.0), - Coord(20.0, 5.0), + Coord(20.0, 10.0), + Coord(20.0, 5.0), - Coord(40.0, 100.0), - Coord(35.0, 105.0), + Coord(40.0, 100.0), + Coord(35.0, 105.0), - Coord(5.0, 105.0), - Coord(0.0, 110.0), - }, - { - Edge(0, 1), - Edge(2, 3), - Edge(4, 5), - Edge(6, 7), - Edge(8, 9) - } - ); + Coord(5.0, 105.0), + Coord(0.0, 110.0), + }, + {Edge(0, 1), Edge(2, 3), Edge(4, 5), Edge(6, 7), Edge(8, 9)}); - typedef StaticRTree, - false, - 2, - 3> MiniStaticRTree; + typedef StaticRTree, false, 2, 3> MiniStaticRTree; std::string leaves_path; std::string nodes_path; - build_rtree("test_regression", &fixture, leaves_path, nodes_path); + build_rtree( + "test_regression", &fixture, leaves_path, nodes_path); MiniStaticRTree rtree(nodes_path, leaves_path, fixture.coords); // query a node just right of the center of the gap @@ -430,15 +405,16 @@ BOOST_AUTO_TEST_CASE(regression_test) void TestRectangle(double width, double height, double center_lat, double center_lon) { - FixedPointCoordinate center(center_lat*COORDINATE_PRECISION, center_lon*COORDINATE_PRECISION); + FixedPointCoordinate center(center_lat * COORDINATE_PRECISION, + center_lon * COORDINATE_PRECISION); TestStaticRTree::RectangleT rect; - rect.min_lat = center.lat - height/2.0 * COORDINATE_PRECISION; - rect.max_lat = center.lat + height/2.0 * COORDINATE_PRECISION; - rect.min_lon = center.lon - width/2.0 * COORDINATE_PRECISION; - rect.max_lon = center.lon + width/2.0 * COORDINATE_PRECISION; + rect.min_lat = center.lat - height / 2.0 * COORDINATE_PRECISION; + rect.max_lat = center.lat + height / 2.0 * COORDINATE_PRECISION; + rect.min_lon = center.lon - width / 2.0 * COORDINATE_PRECISION; + rect.max_lon = center.lon + width / 2.0 * COORDINATE_PRECISION; - unsigned offset = 5*COORDINATE_PRECISION; + unsigned offset = 5 * COORDINATE_PRECISION; FixedPointCoordinate north(rect.max_lat + offset, center.lon); FixedPointCoordinate south(rect.min_lat - offset, center.lon); FixedPointCoordinate west(center.lat, rect.min_lon - offset); @@ -448,42 +424,33 @@ void TestRectangle(double width, double height, double center_lat, double center FixedPointCoordinate south_east(rect.min_lat - offset, rect.max_lon + offset); FixedPointCoordinate south_west(rect.min_lat - offset, rect.min_lon - offset); - /* Distance to line segments of rectangle */ - BOOST_CHECK_EQUAL( - rect.GetMinDist(north), - FixedPointCoordinate::ApproximateEuclideanDistance(north, FixedPointCoordinate(rect.max_lat, north.lon)) - ); - BOOST_CHECK_EQUAL( - rect.GetMinDist(south), - FixedPointCoordinate::ApproximateEuclideanDistance(south, FixedPointCoordinate(rect.min_lat, south.lon)) - ); - BOOST_CHECK_EQUAL( - rect.GetMinDist(west), - FixedPointCoordinate::ApproximateEuclideanDistance(west, FixedPointCoordinate(west.lat, rect.min_lon)) - ); - BOOST_CHECK_EQUAL( - rect.GetMinDist(east), - FixedPointCoordinate::ApproximateEuclideanDistance(east, FixedPointCoordinate(east.lat, rect.max_lon)) - ); + BOOST_CHECK_EQUAL(rect.GetMinDist(north), + FixedPointCoordinate::ApproximateEuclideanDistance( + north, FixedPointCoordinate(rect.max_lat, north.lon))); + BOOST_CHECK_EQUAL(rect.GetMinDist(south), + FixedPointCoordinate::ApproximateEuclideanDistance( + south, FixedPointCoordinate(rect.min_lat, south.lon))); + BOOST_CHECK_EQUAL(rect.GetMinDist(west), + FixedPointCoordinate::ApproximateEuclideanDistance( + west, FixedPointCoordinate(west.lat, rect.min_lon))); + BOOST_CHECK_EQUAL(rect.GetMinDist(east), + FixedPointCoordinate::ApproximateEuclideanDistance( + east, FixedPointCoordinate(east.lat, rect.max_lon))); /* Distance to corner points */ - BOOST_CHECK_EQUAL( - rect.GetMinDist(north_east), - FixedPointCoordinate::ApproximateEuclideanDistance(north_east, FixedPointCoordinate(rect.max_lat, rect.max_lon)) - ); - BOOST_CHECK_EQUAL( - rect.GetMinDist(north_west), - FixedPointCoordinate::ApproximateEuclideanDistance(north_west, FixedPointCoordinate(rect.max_lat, rect.min_lon)) - ); - BOOST_CHECK_EQUAL( - rect.GetMinDist(south_east), - FixedPointCoordinate::ApproximateEuclideanDistance(south_east, FixedPointCoordinate(rect.min_lat, rect.max_lon)) - ); - BOOST_CHECK_EQUAL( - rect.GetMinDist(south_west), - FixedPointCoordinate::ApproximateEuclideanDistance(south_west, FixedPointCoordinate(rect.min_lat, rect.min_lon)) - ); + BOOST_CHECK_EQUAL(rect.GetMinDist(north_east), + FixedPointCoordinate::ApproximateEuclideanDistance( + north_east, FixedPointCoordinate(rect.max_lat, rect.max_lon))); + BOOST_CHECK_EQUAL(rect.GetMinDist(north_west), + FixedPointCoordinate::ApproximateEuclideanDistance( + north_west, FixedPointCoordinate(rect.max_lat, rect.min_lon))); + BOOST_CHECK_EQUAL(rect.GetMinDist(south_east), + FixedPointCoordinate::ApproximateEuclideanDistance( + south_east, FixedPointCoordinate(rect.min_lat, rect.max_lon))); + BOOST_CHECK_EQUAL(rect.GetMinDist(south_west), + FixedPointCoordinate::ApproximateEuclideanDistance( + south_west, FixedPointCoordinate(rect.min_lat, rect.min_lon))); } BOOST_AUTO_TEST_CASE(rectangle_test) @@ -496,4 +463,3 @@ BOOST_AUTO_TEST_CASE(rectangle_test) } BOOST_AUTO_TEST_SUITE_END() - diff --git a/UnitTests/datastructure_tests.cpp b/UnitTests/datastructure_tests.cpp index 2f7f6593b..d451a91c7 100644 --- a/UnitTests/datastructure_tests.cpp +++ b/UnitTests/datastructure_tests.cpp @@ -5,4 +5,3 @@ /* * This file will contain an automatically generated main function. */ -