Repository navigation
Add outer_approximation_by_rectangles - #149
Merged
Merged
Conversation
Approximate shapes by axis-aligned rectangles whose union contains them, within a maximum waste shared by all the shapes, as simplify does with its maximum approximation area: the shapes are decomposed into trapezoids, each covered by its bounding box, then the rectangles are split while the waste is too large, and merged while it stays within the maximum waste.
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.
Adds
outer_approximation_by_rectangles(shape/rectangular_approximation.hpp): approximate shapes by axis-aligned rectangles whose union contains them, within a maximum waste shared by all the shapes, the waysimplifyshares its maximum approximation area.It is meant for algorithms which handle obstacles as rectangles: fontanf/packingsolver's periodic packing approximated the defects, borders and fixed items by their bounding boxes, so a fixed part with a hole covered its hole (fontanf/packingsolver#720).
Interface
The waste of a shape is the area of its rectangles minus its area, counted once per copy. Where rectangles of a shape overlap, the overlap counts several times, so this is an upper bound on the waste of their union.
Algorithm
approximate_by_line_segments), the shape is decomposed into trapezoids (trapezoidation), and each trapezoid is covered by its bounding box. Shapes whose edges are horizontal or vertical are covered exactly: a rectangular frame gives 4 rectangles and leaves its hole free.maximum_waste, split the rectangle whose split into two halves of a trapezoid removes the most waste, up tomaximum_number_of_rectanglesper shape (a budget of 0 can't be met with an oblique edge).maximum_waste, merge the two rectangles of a same shape whose bounding box adds the least waste.Both steps choose across all the shapes, weighted by their copies.
outer_approximation_by_rectangles_export_inputswrites the inputs for test fixtures, like the other algorithms.Tests
test/rectangular_approximation_test.cppchecks that the rectangles contain each shape (boolean difference), that the waste is within the budget, and the number of rectangles where it is known: rectangle, frame with a hole (4 rectangles, no waste), L shape merged or not depending on the budget, triangles, the maximum number of rectangles with a zero budget, a V notch (overlapping rectangles), a circle, a square with a circular hole, and shapes with copies sharing the budget. All the tests pass (707).