Skip to content

Improve rasterization - #44

Merged
fontanf merged 2 commits into
mainfrom
feature/rasterization-dense-grid
Jul 22, 2026
Merged

Improve rasterization#44
fontanf merged 2 commits into
mainfrom
feature/rasterization-dense-grid

Conversation

@fontanf

@fontanf fontanf commented Jul 22, 2026

Copy link
Copy Markdown
Owner

No description provided.

fontanf added 2 commits July 22, 2026 07:38
RasterizedGrid replaces the sparse std::vector<IntersectedCell>: a dense,
column-major std::vector<CellState> (Empty/Full/Border) plus a
column/row offset and an at(column, row) accessor. rasterization()'s sweep
now writes into grid slots instead of push_back-ing sparse entries, so
untouched cells default to Empty rather than simply being absent.

cells_to_shapes(const RasterizedGrid&, ...) replaces the
vector<IntersectedCell> overload.

This is prep for storing each cell's clipped shape part and coverage ratio
alongside its state.
Splits the former Cell struct in two: CellId (column/row, used by
find_cell/cell_to_shape/the vector<CellId> cells_to_shapes overload) and a
new Cell (coverage in [0.0, 1.0] plus a MultiShapeWithHoles holding the
part of the shape within that cell), stored densely in RasterizedGrid.

Full cells get coverage = 1.0 with no stored shape, since it is trivially
the cell's own rectangle. Border cells are batched and clipped in a single
pass: their rectangles are grouped into one MultiShapeWithHoles and
intersected against the original shape via the new
compute_intersection_faces (a boolean_operations addition that returns the
individual intersection faces instead of merging them with compute_union,
so each face's cell can still be recovered via find_point_strictly_inside
+ find_cell -- safe because cell edges are part of the arrangement, so no
face straddles two cells). Each border cell's coverage is then its
accumulated face area over the cell area.

cells_to_shapes(const RasterizedGrid&, ...) takes a CellsToShapesMode
(Outer/Exact/Inner) instead of a bool, controlling how partially covered
cells are handled; Exact (the new per-cell precise shape) is the default.

Strengthened the rasterization test's final check from "union doesn't
grow when combined with the original shape" to an exact equality between
the reconstructed union and the original shape, and added coverage-range
and coverage/stored-area consistency checks.
@fontanf
fontanf merged commit 20cf454 into main Jul 22, 2026
3 checks passed
@fontanf
fontanf deleted the feature/rasterization-dense-grid branch July 22, 2026 06:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant