Centroid area calculation incorrect
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
lib2geom |
Invalid
|
Undecided
|
Unassigned |
Bug Description
The Geom::centroid function can be used to calculate the area of a Piecewise. The following code creates a bounded region with a hole in it. In this case the area returned is the sum of the areas of the hole and the bounding region. I would expect that the area returned was the area of the bounding region less the area of any holes.
In this particular case I've used circles to demonstrate as their area is easily calculated at pi*r^2. Note, I've used the auto keyword from C++11 so compile with -std=c++11
#include <iostream>
#include <2geom/path.h>
#include <2geom/circle.h>
#include <2geom/piecewise.h>
#include <2geom/d2.h>
#include <2geom/sbasis.h>
#include <2geom/
#include <2geom/
#include <2geom/
int main() {
// Circle with radius 10
Geom::Circle c(0, 0, 10);
Geom:
Geom:
pw.push_seg(d2);
double area;
Geom::Point p;
Geom:
// area should be around 3.14159 * 10 * 10
std::cout << "area: " << area << std::endl;
Geom::PathVector container = Geom::path_
// Circle with radius 5
Geom::Circle c2(0, 0, 5);
Geom:
cd.push_
Geom::PathVector contained = Geom::path_
Geom:
Geom::PathVector exclusion = pig.getAminusB();
auto ex = paths_to_
Geom:
// area should be around (3.14159 * 10 * 10) - (3.14159 * 5 * 5)
std::cout << "area: " << area << std::endl;
return 0;
}
Closing in favor of https:/ /gitlab. com/inkscape/ lib2geom/ issues/ 18