16 : b_(bounds), cell_(std::max<
Coord>(cell, 1)), stamp_(max_ids, 0) {
17 nx_ =
static_cast<int>((b_.x1 - b_.x0) / cell_) + 1;
18 ny_ =
static_cast<int>((b_.y1 - b_.y0) / cell_) + 1;
19 cells_.resize(
static_cast<std::size_t
>(nx_) *
static_cast<std::size_t
>(ny_));
23 if (
static_cast<std::size_t
>(
id) >= stamp_.size()) stamp_.resize(
static_cast<std::size_t
>(
id) * 2 + 16, 0);
25 range(box, x0, y0, x1, y1);
26 for (
int y = y0; y <= y1; ++y)
27 for (
int x = x0; x <= x1; ++x) cells_[idx(x, y)].push_back(
id);
34 range(box, x0, y0, x1, y1);
35 for (
int y = y0; y <= y1; ++y)
36 for (
int x = x0; x <= x1; ++x) std::erase(cells_[idx(x, y)],
id);
42 std::fill(stamp_.begin(), stamp_.end(), 0u);
46 range(box, x0, y0, x1, y1);
47 for (
int y = y0; y <= y1; ++y)
48 for (
int x = x0; x <= x1; ++x)
49 for (
int id : cells_[idx(x, y)]) {
50 auto& s = stamp_[
static_cast<std::size_t
>(id)];
51 if (s == gen_)
continue;
58 std::size_t idx(
int x,
int y)
const {
return static_cast<std::size_t
>(y) *
static_cast<std::size_t
>(nx_) +
static_cast<std::size_t
>(x); }
59 void range(
const geom::Box& box,
int& x0,
int& y0,
int& x1,
int& y1)
const {
60 auto cx = [&](
Coord v) {
return std::clamp(
static_cast<int>((v - b_.
x0) / cell_), 0, nx_ - 1); };
61 auto cy = [&](
Coord v) {
return std::clamp(
static_cast<int>((v - b_.
y0) / cell_), 0, ny_ - 1); };
62 x0 = cx(box.
x0); x1 = cx(box.
x1); y0 = cy(box.
y0); y1 = cy(box.
y1);
68 std::vector<std::vector<int>> cells_;
69 std::vector<std::uint32_t> stamp_;
70 std::uint32_t gen_ = 0;
std::int64_t Coord
Engine coordinate: signed 64-bit nanometres.
Integer-nanometre points and KiCad-compatible rotation.
Coord y1
empty when x1 < x0