Improve rasterization - #44
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.