feat(costmap_2d): background reference graph, shared keys under root:

- ReferenceGraph / ReferenceGraphWorker: Voronoi ridges and one-way lanes are
  computed on a low-priority thread when the map changes (reference_graph_*
  keys, off with rolling_window), with unit tests.
- Shared costmap keys can live in a root: map or flat at the top of the YAML;
  costmap_common_root_test covers both layouts.
- Static and directional layers report map changes to the layered costmap.
This commit is contained in:
2026-11-10 16:37:55 +07:00
parent f5d190a3d0
commit 5034029c6e
25 changed files with 3445 additions and 21 deletions

View File

@@ -0,0 +1,569 @@
#include <robot_costmap_2d/reference_graph.h>
#include <algorithm>
#include <atomic>
#include <chrono>
#include <cmath>
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <iterator>
#include <limits>
#include <set>
#include <stdexcept>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#include <gtest/gtest.h>
#include <robot_costmap_2d/cost_values.h>
using namespace robot_costmap_2d;
namespace
{
constexpr double kExactM = 1e-9;
/** Expected output written by the Python prototype, oneway_eval/r12_export_cpp_text.py. */
struct Fixture
{
DirectionGeometry geometry{};
ReferenceGraphParams params;
double half_x = 0.0, half_y = 0.0;
std::vector<uint8_t> cost, direction;
std::vector<int64_t> skeleton;
std::vector<ReferencePoint> nodes;
struct Edge
{
uint32_t from, to;
std::vector<ReferencePoint> points;
};
std::vector<Edge> edges;
std::vector<ReferenceLane> lanes;
};
std::vector<uint8_t> readRuns(std::istream& in, const std::string& name)
{
std::string key;
std::size_t runs = 0;
in >> key >> runs;
if (key != name)
throw std::runtime_error("expected " + name + ", got " + key);
std::vector<uint8_t> out;
for (std::size_t i = 0; i < runs; ++i)
{
int value = 0;
std::size_t count = 0;
in >> value >> count;
out.insert(out.end(), count, static_cast<uint8_t>(value));
}
return out;
}
Fixture loadFixture(const std::string& path)
{
std::ifstream in(path);
if (!in)
throw std::runtime_error("cannot open " + path);
Fixture f;
std::string key;
int version = 0;
in >> key >> version;
if (key != "reference_graph_fixture" || version != 1)
throw std::runtime_error("bad fixture header in " + path);
f.geometry.frame_id = "map";
in >> key >> f.geometry.width >> f.geometry.height;
in >> key >> f.geometry.resolution;
in >> key >> f.geometry.origin_x >> f.geometry.origin_y;
in >> key >> f.params.min_clearance_m >> f.params.ridge_min_separation_m >> f.params.spur_min_length_m >>
f.params.lane_offset_step_m >> f.half_x >> f.half_y;
f.cost = readRuns(in, "cost");
f.direction = readRuns(in, "direction");
std::size_t count = 0;
in >> key >> count;
f.skeleton.resize(count);
for (int64_t& cell : f.skeleton)
in >> cell;
in >> key >> count;
f.nodes.resize(count);
for (ReferencePoint& node : f.nodes)
in >> node.x >> node.y;
in >> key >> count;
f.edges.resize(count);
for (Fixture::Edge& edge : f.edges)
{
std::size_t points = 0;
in >> edge.from >> edge.to >> points;
edge.points.resize(points);
for (ReferencePoint& point : edge.points)
in >> point.x >> point.y;
}
in >> key >> count;
f.lanes.resize(count);
for (ReferenceLane& lane : f.lanes)
{
int direction = 0;
in >> direction >> lane.entry.x >> lane.entry.y >> lane.exit.x >> lane.exit.y >> lane.length_m >>
lane.offset_from_centre_m;
lane.direction_index = static_cast<uint8_t>(direction);
}
if (!in)
throw std::runtime_error("truncated fixture " + path);
return f;
}
std::vector<robot_geometry_msgs::Point> rectangle(double half_x, double half_y)
{
std::vector<robot_geometry_msgs::Point> out(4);
out[0].x = half_x, out[0].y = half_y;
out[1].x = -half_x, out[1].y = half_y;
out[2].x = -half_x, out[2].y = -half_y;
out[3].x = half_x, out[3].y = -half_y;
return out;
}
ReferenceGridView viewOf(const Fixture& f)
{
ReferenceGridView view;
view.cost = f.cost.data();
view.geometry = f.geometry;
const bool zones = std::any_of(f.direction.begin(), f.direction.end(), [](uint8_t code) { return code != 0; });
view.direction_codes = zones ? f.direction.data() : nullptr;
return view;
}
double pointToSegment(const ReferencePoint& p, const ReferencePoint& a, const ReferencePoint& b)
{
const double dx = b.x - a.x, dy = b.y - a.y;
const double squared = dx * dx + dy * dy;
const double t = squared <= 0.0 ? 0.0 : std::min(1.0, std::max(0.0, ((p.x - a.x) * dx + (p.y - a.y) * dy) / squared));
return std::hypot(p.x - a.x - t * dx, p.y - a.y - t * dy);
}
double pointToPolyline(const ReferencePoint& p, const std::vector<ReferencePoint>& line)
{
double best = std::numeric_limits<double>::infinity();
for (std::size_t i = 0; i + 1 < line.size(); ++i)
best = std::min(best, pointToSegment(p, line[i], line[i + 1]));
return best;
}
double polylineLength(const std::vector<ReferencePoint>& line)
{
double total = 0.0;
for (std::size_t i = 0; i + 1 < line.size(); ++i)
total += std::hypot(line[i + 1].x - line[i].x, line[i + 1].y - line[i].y);
return total;
}
std::vector<std::pair<double, double>> sortedPoints(const std::vector<ReferencePoint>& points)
{
std::vector<std::pair<double, double>> out;
out.reserve(points.size());
for (const ReferencePoint& point : points)
out.emplace_back(point.x, point.y);
std::sort(out.begin(), out.end());
return out;
}
/** Both sides read the same chain of cells, but a walk from the other end keeps different cells.
* So edges are matched by end nodes and compared as polylines, within one and a half cells. */
void expectEdgesMatch(const Fixture& f, const ReferenceGraph& graph)
{
using Ends = std::tuple<double, double, double, double>;
const auto ends = [](const ReferencePoint& a, const ReferencePoint& b) {
return a.x < b.x || (a.x == b.x && a.y < b.y) ? Ends(a.x, a.y, b.x, b.y) : Ends(b.x, b.y, a.x, a.y);
};
std::vector<std::pair<Ends, std::size_t>> expected, actual;
for (std::size_t i = 0; i < f.edges.size(); ++i)
expected.emplace_back(ends(f.nodes[f.edges[i].from], f.nodes[f.edges[i].to]), i);
for (std::size_t i = 0; i < graph.edges.size(); ++i)
actual.emplace_back(ends(graph.nodes[graph.edges[i].from], graph.nodes[graph.edges[i].to]), i);
std::sort(expected.begin(), expected.end());
std::sort(actual.begin(), actual.end());
ASSERT_EQ(expected.size(), actual.size());
const double tolerance = 1.5 * f.geometry.resolution;
for (std::size_t i = 0; i < expected.size(); ++i)
{
ASSERT_EQ(expected[i].first, actual[i].first) << "edge end nodes differ at sorted position " << i;
// Parallel edges share their end nodes: pick the closest one among them.
const Fixture::Edge& python = f.edges[expected[i].second];
double best = std::numeric_limits<double>::infinity();
for (std::size_t j = i; j < actual.size() && actual[j].first == expected[i].first; ++j)
{
double worst = 0.0;
for (const ReferencePoint& point : graph.edges[actual[j].second].points)
worst = std::max(worst, pointToPolyline(point, python.points));
best = std::min(best, worst);
}
EXPECT_LE(best, tolerance) << "edge " << i << " leaves the Python polyline";
const VoronoiEdge& edge = graph.edges[actual[i].second];
EXPECT_NEAR(edge.length_m, polylineLength(edge.points), kExactM);
}
}
void expectLanesMatch(const Fixture& f, const ReferenceGraph& graph)
{
const auto order = [](const ReferenceLane& a, const ReferenceLane& b) {
return std::make_tuple(a.direction_index, a.entry.x, a.entry.y) < std::make_tuple(b.direction_index, b.entry.x, b.entry.y);
};
std::vector<ReferenceLane> expected = f.lanes, actual = graph.lanes;
std::sort(expected.begin(), expected.end(), order);
std::sort(actual.begin(), actual.end(), order);
ASSERT_EQ(expected.size(), actual.size());
for (std::size_t i = 0; i < expected.size(); ++i)
{
EXPECT_EQ(expected[i].direction_index, actual[i].direction_index);
EXPECT_NEAR(expected[i].entry.x, actual[i].entry.x, kExactM);
EXPECT_NEAR(expected[i].entry.y, actual[i].entry.y, kExactM);
EXPECT_NEAR(expected[i].exit.x, actual[i].exit.x, kExactM);
EXPECT_NEAR(expected[i].exit.y, actual[i].exit.y, kExactM);
EXPECT_NEAR(expected[i].length_m, actual[i].length_m, kExactM);
EXPECT_NEAR(expected[i].offset_from_centre_m, actual[i].offset_from_centre_m, kExactM);
}
}
/** Run steps 1 and 2 on a fixture and compare every stage. Returns step times [ms] for the timing test. */
std::pair<double, double> expectParity(const Fixture& f)
{
const ReferenceGridView view = viewOf(f);
const auto t0 = std::chrono::steady_clock::now();
const VoronoiSkeleton skeleton = computeVoronoiSkeleton(view, f.params);
const auto t1 = std::chrono::steady_clock::now();
const ReferenceGraph graph = buildReferenceGraph(view, skeleton, rectangle(f.half_x, f.half_y), f.params);
const auto t2 = std::chrono::steady_clock::now();
std::vector<int64_t> cells;
for (std::size_t i = 0; i < skeleton.mask.size(); ++i)
if (skeleton.mask[i] != 0)
cells.push_back(static_cast<int64_t>(i));
std::vector<int64_t> only_cpp, only_python;
std::set_difference(cells.begin(), cells.end(), f.skeleton.begin(), f.skeleton.end(), std::back_inserter(only_cpp));
std::set_difference(f.skeleton.begin(), f.skeleton.end(), cells.begin(), cells.end(), std::back_inserter(only_python));
EXPECT_TRUE(only_cpp.empty()) << only_cpp.size() << " skeleton cells only in C++";
EXPECT_TRUE(only_python.empty()) << only_python.size() << " skeleton cells only in Python";
const std::vector<std::pair<double, double>> expected_nodes = sortedPoints(f.nodes), actual_nodes = sortedPoints(graph.nodes);
EXPECT_EQ(expected_nodes.size(), actual_nodes.size());
for (std::size_t i = 0; i < std::min(expected_nodes.size(), actual_nodes.size()); ++i)
{
EXPECT_NEAR(expected_nodes[i].first, actual_nodes[i].first, kExactM);
EXPECT_NEAR(expected_nodes[i].second, actual_nodes[i].second, kExactM);
}
expectEdgesMatch(f, graph);
expectLanesMatch(f, graph);
EXPECT_EQ(graph.static_cost, f.cost);
EXPECT_EQ(graph.clearance_mm, skeleton.clearance_mm);
const auto ms = [](std::chrono::steady_clock::time_point a, std::chrono::steady_clock::time_point b) {
return std::chrono::duration<double, std::milli>(b - a).count();
};
return { ms(t0, t1), ms(t1, t2) };
}
std::string packagedFixture(const std::string& name)
{
return std::string(ROBOT_COSTMAP_2D_DIR) + "/test/data/reference_graph/" + name + ".fixture";
}
DirectionGeometry geometryOf(uint32_t width, uint32_t height)
{
return { width, height, 0.05, 0.0, 0.0, "map" };
}
/** Free corridor 2 m wide between two lethal walls, as in the corridor fixture. */
std::vector<uint8_t> corridorCost(uint32_t width, uint32_t height)
{
std::vector<uint8_t> cost(static_cast<std::size_t>(width) * height, FREE_SPACE);
for (uint32_t y = 0; y < height; ++y)
if (y < 10 || y >= height - 10)
std::fill_n(cost.begin() + static_cast<std::ptrdiff_t>(y * width), width, LETHAL_OBSTACLE);
return cost;
}
} // namespace
// Exact answers from the Python prototype, one scene per behaviour.
TEST(ReferenceGraphParity, Corridor)
{
const Fixture f = loadFixture(packagedFixture("corridor"));
expectParity(f);
EXPECT_EQ(f.nodes.size(), 2u);
EXPECT_EQ(f.edges.size(), 1u);
}
TEST(ReferenceGraphParity, TJunction)
{
const Fixture f = loadFixture(packagedFixture("t_junction"));
expectParity(f);
EXPECT_EQ(f.nodes.size(), 4u);
EXPECT_EQ(f.edges.size(), 3u);
}
TEST(ReferenceGraphParity, ClosedRingHasNoNode)
{
const Fixture f = loadFixture(packagedFixture("ring"));
expectParity(f);
EXPECT_FALSE(f.skeleton.empty());
EXPECT_TRUE(f.nodes.empty());
}
TEST(ReferenceGraphParity, UnknownCellsSplitTheRidge)
{
const Fixture f = loadFixture(packagedFixture("unknown_block"));
expectParity(f);
EXPECT_EQ(f.edges.size(), 2u);
for (int64_t cell : f.skeleton)
EXPECT_NE(f.cost[static_cast<std::size_t>(cell)], NO_INFORMATION);
}
TEST(ReferenceGraphParity, OneZoneSplitsEdgesAndAddsLanes)
{
const Fixture f = loadFixture(packagedFixture("one_zone"));
expectParity(f);
EXPECT_EQ(f.edges.size(), 5u);
ASSERT_EQ(f.lanes.size(), 3u);
for (const ReferenceLane& lane : f.lanes)
{
EXPECT_EQ(lane.direction_index, 0);
EXPECT_GT(lane.exit.x, lane.entry.x);
}
}
TEST(ReferenceGraphParity, TwoZones)
{
expectParity(loadFixture(packagedFixture("two_zones")));
}
TEST(ReferenceGraphParity, ZoneCutByObstacle)
{
expectParity(loadFixture(packagedFixture("cut_zone")));
}
TEST(ReferenceGraphParity, MapCropWithZones)
{
expectParity(loadFixture(packagedFixture("crop")));
}
// The whole-map fixtures stay outside the repo. Point REFERENCE_GRAPH_FIXTURE_DIR at them to run these.
TEST(ReferenceGraphParity, WholeMaps)
{
const char* directory = std::getenv("REFERENCE_GRAPH_FIXTURE_DIR");
if (directory == nullptr)
{
// The installed gtest predates GTEST_SKIP.
std::cout << "[ SKIPPED ] REFERENCE_GRAPH_FIXTURE_DIR is not set" << std::endl;
return;
}
for (const char* name : { "kit", "sehc" })
{
SCOPED_TRACE(name);
const std::pair<double, double> times = expectParity(loadFixture(std::string(directory) + "/" + name + ".fixture"));
std::cout << "[ TIMING ] " << name << " step 1 " << times.first << " ms, step 2 " << times.second << " ms" << std::endl;
#ifdef NDEBUG
// Pass condition of the plan on the dev machine. The workspace builds Debug by default, where it means nothing.
EXPECT_LT(times.first + times.second, 5000.0);
#endif
}
}
TEST(ReferenceGraphGrid, EmptyGridHasNoSkeleton)
{
const DirectionGeometry geometry = geometryOf(40, 30);
const std::vector<uint8_t> cost(1200, FREE_SPACE);
ReferenceGridView view;
view.cost = cost.data();
view.geometry = geometry;
const ReferenceGraphParams params;
const VoronoiSkeleton skeleton = computeVoronoiSkeleton(view, params);
ASSERT_EQ(skeleton.mask.size(), 1200u);
EXPECT_EQ(std::count(skeleton.mask.begin(), skeleton.mask.end(), 1), 0);
EXPECT_EQ(skeleton.clearance_mm, std::vector<uint16_t>(1200, 65535));
const ReferenceGraph graph = buildReferenceGraph(view, skeleton, {}, params);
EXPECT_TRUE(graph.nodes.empty());
EXPECT_TRUE(graph.edges.empty());
EXPECT_TRUE(graph.lanes.empty());
}
TEST(ReferenceGraphGrid, AllLethalHasNoSkeleton)
{
const std::vector<uint8_t> cost(1200, LETHAL_OBSTACLE);
ReferenceGridView view;
view.cost = cost.data();
view.geometry = geometryOf(40, 30);
const VoronoiSkeleton skeleton = computeVoronoiSkeleton(view, ReferenceGraphParams());
EXPECT_EQ(std::count(skeleton.mask.begin(), skeleton.mask.end(), 1), 0);
EXPECT_EQ(skeleton.clearance_mm, std::vector<uint16_t>(1200, 0));
}
TEST(ReferenceGraphGrid, ClearanceIsInMillimetres)
{
const std::vector<uint8_t> cost = corridorCost(100, 60);
ReferenceGridView view;
view.cost = cost.data();
view.geometry = geometryOf(100, 60);
const VoronoiSkeleton skeleton = computeVoronoiSkeleton(view, ReferenceGraphParams());
// Row 10 touches the wall at row 9, one cell away. Row 29 is 20 cells from the wall at row 9.
EXPECT_EQ(skeleton.clearance_mm[10 * 100 + 50], 50);
EXPECT_EQ(skeleton.clearance_mm[29 * 100 + 50], 1000);
EXPECT_EQ(skeleton.clearance_mm[5 * 100 + 50], 0);
}
TEST(ReferenceGraphGrid, InflatedCellsNeverJoinTheSkeleton)
{
std::vector<uint8_t> cost = corridorCost(100, 60);
// A band of inflation across the middle of the corridor, as a master costmap crop would hold.
for (uint32_t y = 25; y < 35; ++y)
std::fill_n(cost.begin() + y * 100, 100, INSCRIBED_INFLATED_OBSTACLE);
ReferenceGridView view;
view.cost = cost.data();
view.geometry = geometryOf(100, 60);
const VoronoiSkeleton skeleton = computeVoronoiSkeleton(view, ReferenceGraphParams());
for (std::size_t i = 0; i < cost.size(); ++i)
if (skeleton.mask[i] != 0)
EXPECT_LT(cost[i], INSCRIBED_INFLATED_OBSTACLE) << "cell " << i;
}
TEST(ReferenceGraphGrid, SuppliedClearanceReplacesTheComputedOne)
{
const std::vector<uint8_t> cost = corridorCost(100, 60);
ReferenceGridView view;
view.cost = cost.data();
view.geometry = geometryOf(100, 60);
// An obstacle just outside a window crop: clearance from the full map rules out every cell.
const std::vector<uint16_t> tight(6000, 100);
view.clearance_mm = tight.data();
VoronoiSkeleton skeleton = computeVoronoiSkeleton(view, ReferenceGraphParams());
EXPECT_EQ(std::count(skeleton.mask.begin(), skeleton.mask.end(), 1), 0);
EXPECT_EQ(skeleton.clearance_mm, tight);
const std::vector<uint16_t> wide(6000, 2000);
view.clearance_mm = wide.data();
skeleton = computeVoronoiSkeleton(view, ReferenceGraphParams());
EXPECT_GT(std::count(skeleton.mask.begin(), skeleton.mask.end(), 1), 0);
EXPECT_EQ(skeleton.clearance_mm, wide);
}
TEST(ReferenceGraphGrid, RepeatedRunsGiveTheSameGraph)
{
const Fixture f = loadFixture(packagedFixture("two_zones"));
const ReferenceGridView view = viewOf(f);
const VoronoiSkeleton a = computeVoronoiSkeleton(view, f.params);
const VoronoiSkeleton b = computeVoronoiSkeleton(view, f.params);
EXPECT_EQ(a.mask, b.mask);
const ReferenceGraph first = buildReferenceGraph(view, a, rectangle(f.half_x, f.half_y), f.params);
const ReferenceGraph second = buildReferenceGraph(view, b, rectangle(f.half_x, f.half_y), f.params);
ASSERT_EQ(first.nodes.size(), second.nodes.size());
ASSERT_EQ(first.edges.size(), second.edges.size());
ASSERT_EQ(first.lanes.size(), second.lanes.size());
for (std::size_t i = 0; i < first.edges.size(); ++i)
EXPECT_EQ(first.edges[i].points.size(), second.edges[i].points.size());
}
TEST(ReferenceGraphGrid, BiggerFootprintDropsLanes)
{
const Fixture f = loadFixture(packagedFixture("one_zone"));
const ReferenceGridView view = viewOf(f);
const VoronoiSkeleton skeleton = computeVoronoiSkeleton(view, f.params);
const ReferenceGraph fits = buildReferenceGraph(view, skeleton, rectangle(f.half_x, f.half_y), f.params);
// Half width 1.1 m does not fit the 2 m corridor.
const ReferenceGraph blocked = buildReferenceGraph(view, skeleton, rectangle(f.half_x, 1.1), f.params);
EXPECT_FALSE(fits.lanes.empty());
EXPECT_TRUE(blocked.lanes.empty());
EXPECT_EQ(fits.edges.size(), blocked.edges.size());
}
TEST(ReferenceGraphGrid, RegionCentreLineMatchesPython)
{
const DirectionGeometry geometry = geometryOf(100, 40);
std::vector<uint8_t> mask(4000, 0);
for (uint32_t y = 16; y < 24; ++y)
std::fill_n(mask.begin() + y * 100 + 10, 80, 1);
const std::vector<uint8_t> line = computeRegionCentreLine(mask, geometry, ReferenceGraphParams());
EXPECT_EQ(std::count(line.begin(), line.end(), 1), 81);
uint32_t x_min = 100, x_max = 0;
for (uint32_t y = 0; y < 40; ++y)
{
for (uint32_t x = 0; x < 100; ++x)
{
if (line[y * 100 + x] == 0)
continue;
EXPECT_NE(mask[y * 100 + x], 0) << "centre line left the region";
x_min = std::min(x_min, x);
x_max = std::max(x_max, x);
}
}
EXPECT_EQ(x_min, 10u);
EXPECT_EQ(x_max, 89u);
const std::vector<uint8_t> nothing(4000, 0);
const std::vector<uint8_t> empty_line = computeRegionCentreLine(nothing, geometry, ReferenceGraphParams());
EXPECT_EQ(std::count(empty_line.begin(), empty_line.end(), 1), 0);
}
TEST(ReferenceGraphInput, BadParametersAreRefused)
{
const std::vector<uint8_t> cost(100, FREE_SPACE);
ReferenceGridView view;
view.cost = cost.data();
view.geometry = geometryOf(10, 10);
ReferenceGraphParams params;
params.min_clearance_m = -0.1;
EXPECT_FALSE(validateReferenceGraphParams(params).empty());
EXPECT_THROW(computeVoronoiSkeleton(view, params), std::invalid_argument);
params = ReferenceGraphParams();
params.ridge_min_separation_m = 0.0;
EXPECT_THROW(computeVoronoiSkeleton(view, params), std::invalid_argument);
params = ReferenceGraphParams();
params.spur_min_length_m = std::numeric_limits<double>::quiet_NaN();
EXPECT_THROW(computeVoronoiSkeleton(view, params), std::invalid_argument);
params = ReferenceGraphParams();
params.lane_offset_step_m = -1.0;
EXPECT_THROW(computeVoronoiSkeleton(view, params), std::invalid_argument);
EXPECT_TRUE(validateReferenceGraphParams(ReferenceGraphParams()).empty());
}
TEST(ReferenceGraphInput, BadGridsAreRefused)
{
const std::vector<uint8_t> cost(100, FREE_SPACE);
ReferenceGridView view;
view.geometry = geometryOf(10, 10);
EXPECT_THROW(computeVoronoiSkeleton(view, ReferenceGraphParams()), std::invalid_argument);
view.cost = cost.data();
view.geometry.resolution = 0.0;
EXPECT_THROW(computeVoronoiSkeleton(view, ReferenceGraphParams()), std::invalid_argument);
view.geometry = geometryOf(0, 10);
EXPECT_THROW(computeVoronoiSkeleton(view, ReferenceGraphParams()), std::invalid_argument);
view.geometry = geometryOf(10, 10);
VoronoiSkeleton wrong_size;
EXPECT_THROW(buildReferenceGraph(view, wrong_size, {}, ReferenceGraphParams()), std::invalid_argument);
}
TEST(ReferenceGraphInput, ZonesNeedAFootprint)
{
const Fixture f = loadFixture(packagedFixture("one_zone"));
const ReferenceGridView view = viewOf(f);
const VoronoiSkeleton skeleton = computeVoronoiSkeleton(view, f.params);
EXPECT_THROW(buildReferenceGraph(view, skeleton, {}, f.params), std::invalid_argument);
EXPECT_THROW(buildReferenceGraph(view, skeleton, rectangle(0.0, 0.0), f.params), std::invalid_argument);
}
TEST(ReferenceGraphCancel, CancelGivesAnEmptyResult)
{
const Fixture f = loadFixture(packagedFixture("one_zone"));
const ReferenceGridView view = viewOf(f);
const VoronoiSkeleton skeleton = computeVoronoiSkeleton(view, f.params);
std::atomic<bool> cancel(true);
EXPECT_TRUE(computeVoronoiSkeleton(view, f.params, &cancel).mask.empty());
const ReferenceGraph graph = buildReferenceGraph(view, skeleton, rectangle(f.half_x, f.half_y), f.params, &cancel);
EXPECT_TRUE(graph.static_cost.empty());
EXPECT_TRUE(graph.nodes.empty());
EXPECT_TRUE(graph.edges.empty());
EXPECT_TRUE(graph.lanes.empty());
}