13 !std::isfinite(grid.cellSize) || grid.cellSize <= 0.f || !std::isfinite(grid.originX) ||
14 !std::isfinite(grid.originY))
16 const double cell = grid.cellSize;
17 const double ax = (
static_cast<double>(
from.x) - grid.originX) /
cell;
18 const double ay = (
static_cast<double>(
from.y) - grid.originY) /
cell;
19 const double bx = (
static_cast<double>(
to.x) - grid.originX) /
cell;
20 const double by = (
static_cast<double>(
to.y) - grid.originY) /
cell;
21 const double reach =
static_cast<double>(
radius) /
cell + 0.5;
22 const double minX = std::ceil(std::min(ax, bx) - reach);
23 const double maxX = std::floor(std::max(ax, bx) + reach);
24 const double minY = std::ceil(std::min(ay, by) - reach);
25 const double maxY = std::floor(std::max(ay, by) + reach);
26 constexpr double minIndex =
static_cast<double>(std::numeric_limits<int>::min()) + 1.0;
27 constexpr double maxIndex =
static_cast<double>(std::numeric_limits<int>::max()) - 1.0;
28 if (minX < minIndex || maxX > maxIndex || minY < minIndex || maxY > maxIndex ||
29 (maxX - minX + 1.0) * (maxY - minY + 1.0) > 4096.0)
31 for (
int y =
static_cast<int>(minY); y <= static_cast<int>(maxY); ++
y) {
32 for (
int x =
static_cast<int>(minX); x <= static_cast<int>(maxX); ++
x) {
34 double enter = 0.0, leave = 1.0;
35 const auto intersectsSlab = [&](
double start,
double delta,
double low,
double high) {
36 if (delta == 0.0)
return start >= low &&
start <= high;
38 double last = (high -
start) / delta;
40 enter = std::max(enter,
first);
41 leave = std::min(leave, last);
42 return enter <= leave;
44 if (intersectsSlab(ax, bx - ax,
x - reach,
x + reach) && intersectsSlab(ay, by - ay,
y - reach,
y + reach))