fix bug: multipliy area with distance up to next y point

This commit is contained in:
Maximilian Keßler 2022-04-16 12:36:25 +02:00
parent a4c035b6dc
commit 66137ac27b
2 changed files with 5 additions and 3 deletions

View file

@ -69,7 +69,9 @@ Unit get_area_union(std::vector<Rectangle> rectangles) {
//cross section is now up to date
if(y_index + 1 < y_points.size()) {
// add area up to next y point
total_area += segmentTree.length_covered_intervals();
total_area +=
(y_points[y_index +1].coord - y_points[y_index].coord) *
segmentTree.length_covered_intervals();
}
}
// TODO: sanity check that nothing is covered when arriving at the end

View file

@ -10,12 +10,12 @@ int main() {
std::vector<Rectangle> rects;
rects.push_back({{0,0},{10,10},0,0});
Unit area = get_area_union(rects);
assert(area == 10);
assert(area == 100);
rects.push_back({{2,3},{4,12},0,0});
area = get_area_union(rects);
std::cout << "Area is " << area << std::endl;
assert(area == 14);
assert(area == 104);
std::vector<Rectangle> inst1 = get_random_instance(10,100);
area = get_area_union(inst1);