reformatting code according to guidelines

This commit is contained in:
Dennis Luxen 2014-07-23 19:28:04 +02:00
parent a87cf60dfc
commit 85eb38e755
5 changed files with 170 additions and 218 deletions

View File

@ -21,9 +21,7 @@ typedef boost::mpl::list<ArrayStorage<TestNodeID, TestKey>,
MapStorage<TestNodeID, TestKey>,
UnorderedMapStorage<TestNodeID, TestKey>> storage_types;
template<unsigned NUM_ELEM>
struct RandomDataFixture
template <unsigned NUM_ELEM> struct RandomDataFixture
{
RandomDataFixture()
{
@ -151,4 +149,3 @@ BOOST_FIXTURE_TEST_CASE_TEMPLATE(decrease_key_test, T, storage_types, RandomData
}
BOOST_AUTO_TEST_SUITE_END()

View File

@ -25,7 +25,8 @@ void ConstructionTest(std::vector<unsigned> lengths, std::vector<unsigned> offse
}
}
void ComputeLengthsOffsets(std::vector<unsigned>& lengths, std::vector<unsigned>& offsets, unsigned num)
void
ComputeLengthsOffsets(std::vector<unsigned> &lengths, std::vector<unsigned> &offsets, unsigned num)
{
lengths.resize(num);
offsets.resize(num + 1);

View File

@ -34,8 +34,7 @@ constexpr unsigned TEST_NUM_EDGES = 500;
// Choosen by a fair W20 dice roll (this value is completely arbitrary)
constexpr unsigned RANDOM_SEED = 15;
template<unsigned NUM_NODES, unsigned NUM_EDGES>
struct RandomArrayEntryFixture
template <unsigned NUM_NODES, unsigned NUM_EDGES> struct RandomArrayEntryFixture
{
RandomArrayEntryFixture()
{
@ -68,11 +67,8 @@ struct RandomArrayEntryFixture
for (unsigned i = 0; i < NUM_EDGES; i++)
{
edges.emplace_back(
TestEdgeArrayEntry {
static_cast<unsigned>(node_udist(g)),
TestData {i, false, static_cast<unsigned>(lengths_udist(g))}
}
);
TestEdgeArrayEntry{static_cast<unsigned>(node_udist(g)),
TestData{i, false, static_cast<unsigned>(lengths_udist(g))}});
}
for (unsigned i = 0; i < NUM_NODES; i++)
@ -112,11 +108,7 @@ TestStaticGraph GraphFromEdgeList(const std::vector<TestEdge>& edges)
unsigned num_nodes = 0;
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},
TestStaticGraph simple_graph = GraphFromEdgeList({TestEdge{0, 1, 1},
TestEdge{3, 0, 2},
TestEdge{3, 4, 4},
TestEdge{4, 3, 3},
TestEdge {3, 0, 1}
});
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()

View File

@ -23,8 +23,7 @@ typedef StaticRTree<TestData,
std::vector<FixedPointCoordinate>,
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;
@ -38,9 +37,9 @@ class LinearSearchNN
public:
LinearSearchNN(const std::shared_ptr<std::vector<FixedPointCoordinate>> &coords,
const std::vector<TestData> &edges)
: coords(coords)
, edges(edges)
{ }
: coords(coords), edges(edges)
{
}
bool LocateClosestEndPointForCoordinate(const FixedPointCoordinate &input_coordinate,
FixedPointCoordinate &result_coordinate,
@ -58,10 +57,7 @@ public:
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;
@ -101,11 +94,7 @@ 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))
@ -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)
@ -163,9 +150,7 @@ private:
const std::vector<TestData> &edges;
};
template<unsigned NUM_NODES, unsigned NUM_EDGES>
struct RandomGraphFixture
template <unsigned NUM_NODES, unsigned NUM_EDGES> struct RandomGraphFixture
{
struct TupleHash
{
@ -181,8 +166,7 @@ struct RandomGraphFixture
}
};
RandomGraphFixture()
: coords(std::make_shared<std::vector<FixedPointCoordinate>>())
RandomGraphFixture() : coords(std::make_shared<std::vector<FixedPointCoordinate>>())
{
BOOST_TEST_MESSAGE("Constructing " << NUM_NODES << " nodes and " << NUM_EDGES << " edges.");
@ -208,14 +192,14 @@ struct RandomGraphFixture
TestData data;
data.u = edge_udist(g);
data.v = edge_udist(g);
if (used_edges.find(std::pair<unsigned, unsigned>(std::min(data.u, data.v), std::max(data.u, data.v))) == used_edges.end())
if (used_edges.find(std::pair<unsigned, unsigned>(
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<NodeInfo> nodes;
@ -232,7 +216,8 @@ struct GraphFixture
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));
}
@ -244,7 +229,6 @@ struct GraphFixture
d.v = pair.second;
edges.emplace_back(d);
}
}
std::vector<NodeInfo> nodes;
@ -252,17 +236,23 @@ struct GraphFixture
std::vector<TestData> edges;
};
typedef RandomGraphFixture<TEST_LEAF_NODE_SIZE*3, TEST_LEAF_NODE_SIZE/2> TestRandomGraphFixture_LeafHalfFull;
typedef RandomGraphFixture<TEST_LEAF_NODE_SIZE*5, TEST_LEAF_NODE_SIZE> TestRandomGraphFixture_LeafFull;
typedef RandomGraphFixture<TEST_LEAF_NODE_SIZE*10, TEST_LEAF_NODE_SIZE*2> TestRandomGraphFixture_TwoLeaves;
typedef RandomGraphFixture<TEST_LEAF_NODE_SIZE * 3, TEST_LEAF_NODE_SIZE / 2>
TestRandomGraphFixture_LeafHalfFull;
typedef RandomGraphFixture<TEST_LEAF_NODE_SIZE * 5, TEST_LEAF_NODE_SIZE>
TestRandomGraphFixture_LeafFull;
typedef RandomGraphFixture<TEST_LEAF_NODE_SIZE * 10, TEST_LEAF_NODE_SIZE * 2>
TestRandomGraphFixture_TwoLeaves;
typedef RandomGraphFixture<TEST_LEAF_NODE_SIZE * TEST_BRANCHING_FACTOR * 3,
TEST_LEAF_NODE_SIZE*TEST_BRANCHING_FACTOR> TestRandomGraphFixture_Branch;
TEST_LEAF_NODE_SIZE * TEST_BRANCHING_FACTOR>
TestRandomGraphFixture_Branch;
typedef RandomGraphFixture<TEST_LEAF_NODE_SIZE * TEST_BRANCHING_FACTOR * 3,
TEST_LEAF_NODE_SIZE*TEST_BRANCHING_FACTOR*2> TestRandomGraphFixture_MultipleLevels;
TEST_LEAF_NODE_SIZE * TEST_BRANCHING_FACTOR * 2>
TestRandomGraphFixture_MultipleLevels;
template <typename RTreeT>
void simple_verify_rtree(RTreeT& rtree, const std::shared_ptr<std::vector<FixedPointCoordinate>>& coords, const std::vector<TestData>& edges)
void simple_verify_rtree(RTreeT &rtree,
const std::shared_ptr<std::vector<FixedPointCoordinate>> &coords,
const std::vector<TestData> &edges)
{
BOOST_TEST_MESSAGE("Verify end points");
for (const auto &e : edges)
@ -274,16 +264,10 @@ void simple_verify_rtree(RTreeT& rtree, const std::shared_ptr<std::vector<FixedP
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<float>::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<float>::epsilon());
}
}
@ -297,9 +281,7 @@ void sampling_verify_rtree(RTreeT& rtree, LinearSearchNN& lsnn, unsigned num_sam
std::vector<FixedPointCoordinate> 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");
@ -320,7 +302,10 @@ void sampling_verify_rtree(RTreeT& rtree, LinearSearchNN& lsnn, unsigned num_sam
}
template <typename FixtureT, typename RTreeT = TestStaticRTree>
void build_rtree(const std::string& prefix, FixtureT* fixture, std::string& leaves_path, std::string& nodes_path)
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";
@ -397,24 +382,14 @@ BOOST_AUTO_TEST_CASE(regression_test)
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)
}
);
{Edge(0, 1), Edge(2, 3), Edge(4, 5), Edge(6, 7), Edge(8, 9)});
typedef StaticRTree<TestData,
std::vector<FixedPointCoordinate>,
false,
2,
3> MiniStaticRTree;
typedef StaticRTree<TestData, std::vector<FixedPointCoordinate>, false, 2, 3> MiniStaticRTree;
std::string leaves_path;
std::string nodes_path;
build_rtree<GraphFixture, MiniStaticRTree>("test_regression", &fixture, leaves_path, nodes_path);
build_rtree<GraphFixture, MiniStaticRTree>(
"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,7 +405,8 @@ 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;
@ -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()

View File

@ -5,4 +5,3 @@
/*
* This file will contain an automatically generated main function.
*/