fix missing update of covered length on removal

This commit is contained in:
Maximilian Keßler 2022-04-16 12:47:39 +02:00
parent 66137ac27b
commit 3df8c5095d
2 changed files with 20 additions and 12 deletions

View file

@ -4,22 +4,29 @@
#include "areas.h" #include "areas.h"
static std::vector<Rectangle> rects;
void add_rect(Coordinate x1, Coordinate y1, Coordinate x2, Coordinate y2) {
rects.push_back({{x1,y1}, {x2,y2}, 0, 0});
}
void check_area(Unit area) {
Unit computed = get_area_union(rects);
std::cout << "Computed area is " << computed << std::endl;
assert(computed == area);
}
int main() { int main() {
srand(987192345); srand(987192345);
std::vector<Rectangle> rects; add_rect(0,0,5,4);
rects.push_back({{0,0},{10,10},0,0}); check_area(20);
Unit area = get_area_union(rects);
assert(area == 100);
rects.push_back({{2,3},{4,12},0,0}); add_rect(3,2,6,6);
area = get_area_union(rects); check_area(28);
std::cout << "Area is " << area << std::endl;
assert(area == 104);
std::vector<Rectangle> inst1 = get_random_instance(10,100); std::cout << "All checks passed" << std::endl;
area = get_area_union(inst1);
std::cout << "Area is " << area << "." << std::endl;
assert(area == 6559);
return 0; return 0;
} }

View file

@ -59,6 +59,7 @@ void SegmentTree::remove_interval(Interval interval, Index node_idx) {
if(right_child(node_idx).left_coord < interval.right) { if(right_child(node_idx).left_coord < interval.right) {
remove_interval(interval, right_child_idx(node_idx)); remove_interval(interval, right_child_idx(node_idx));
} }
update_covered_length(node_idx);
} }
} }