diff --git a/areas.cpp b/areas.cpp index ea8c8f0..c557b53 100644 --- a/areas.cpp +++ b/areas.cpp @@ -69,7 +69,9 @@ Unit get_area_union(std::vector 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 diff --git a/main.cpp b/main.cpp index 2e4afe2..6e4a85f 100644 --- a/main.cpp +++ b/main.cpp @@ -10,12 +10,12 @@ int main() { std::vector 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 inst1 = get_random_instance(10,100); area = get_area_union(inst1);