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