// 多个区间的集合
class IntervalSet
{
public:
std::vector intervals;
code
Assistant
Yes, there is a critical problem in src/maxemptyrects.cpp in the findMaxEmptyRects function.
The lines topToRects.reserve(ys.size()); and bottomToRects.reserve(ys.size()); are incorrect. std::vector::reserve allocates memory but does not change the size of the vector. The subsequent accesses using operator[] (e.g., topToRects[0]) and back() are on an empty vector, which leads to undefined behavior and will likely crash your program.
You should use resize or initialize the vector with a size. I'll fix this by initializing the vectors with the correct size.
This change corrects the memory allocation issue.
Assistant
The fix has been applied.
Additionally, the algorithm's logic in findMaxEmptyRects seems quite complex and may have other issues. For example, the line outRects.push_back({limit.min, limit.max, top, bottom}); might not be correct, as it creates a rectangle with the full width of the limit interval, without considering the exact horizontal position of the obstacle that may have terminated the empty space. This could result in rectangles that are not truly empty. You may want to review the algorithm's logic.
User
Assistant
You're right to double-check. As I mentioned, the logic for finding the rectangles is complex, and it does contain another significant flaw.
The problem is in how the empty rectangles are created. When an empty space (limit) is blocked by an obstacle below (rectsBottomIntervals), the code creates a new rectangle with the full width of the original empty space:
Is there any other problem in @src/maxemptyrects.cpp ?
--- Content from referenced files ---
Content from @C:\routenodes\src\maxemptyrects.cpp:
// 极大空矩形