Fix for benchmark
This commit is contained in:
parent
3baf6f3450
commit
b48bf5f48e
2 changed files with 52 additions and 27 deletions
Binary file not shown.
Before Width: | Height: | Size: 8.4 KiB After Width: | Height: | Size: 8.5 KiB |
|
@ -306,6 +306,43 @@ public:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
inline void process_polynode_branch(ClipperLib::PolyNode* polynode,
|
||||||
|
mapnik::geometry::multi_polygon<double> & mp)
|
||||||
|
{
|
||||||
|
mapnik::geometry::polygon<double> polygon;
|
||||||
|
mapnik::geometry::linear_ring<double> outer;
|
||||||
|
for (auto const& pt : polynode->Contour)
|
||||||
|
{
|
||||||
|
outer.emplace_back(static_cast<double>(pt.x),static_cast<double>(pt.y));
|
||||||
|
}
|
||||||
|
if (outer.front() != outer.back())
|
||||||
|
{
|
||||||
|
outer.emplace_back(outer.front().x, outer.front().y);
|
||||||
|
}
|
||||||
|
polygon.set_exterior_ring(std::move(outer));
|
||||||
|
for (auto * ring : polynode->Childs)
|
||||||
|
{
|
||||||
|
mapnik::geometry::linear_ring<double> inner;
|
||||||
|
for (auto const& pt : ring->Contour)
|
||||||
|
{
|
||||||
|
inner.emplace_back(static_cast<double>(pt.x),static_cast<double>(pt.y));
|
||||||
|
}
|
||||||
|
if (inner.front() != inner.back())
|
||||||
|
{
|
||||||
|
inner.emplace_back(inner.front().x, inner.front().y);
|
||||||
|
}
|
||||||
|
polygon.add_hole(std::move(inner));
|
||||||
|
}
|
||||||
|
mp.emplace_back(std::move(polygon));
|
||||||
|
for (auto * ring : polynode->Childs)
|
||||||
|
{
|
||||||
|
for (auto * sub_ring : ring->Childs)
|
||||||
|
{
|
||||||
|
process_polynode_branch(sub_ring, mp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class test4 : public benchmark::test_case
|
class test4 : public benchmark::test_case
|
||||||
{
|
{
|
||||||
std::string wkt_in_;
|
std::string wkt_in_;
|
||||||
|
@ -347,6 +384,11 @@ public:
|
||||||
double y = pt.y;
|
double y = pt.y;
|
||||||
path.emplace_back(static_cast<ClipperLib::cInt>(x),static_cast<ClipperLib::cInt>(y));
|
path.emplace_back(static_cast<ClipperLib::cInt>(x),static_cast<ClipperLib::cInt>(y));
|
||||||
}
|
}
|
||||||
|
double area = ClipperLib::Area(path);
|
||||||
|
if (area > 0)
|
||||||
|
{
|
||||||
|
std::reverse(path.begin(), path.end());
|
||||||
|
}
|
||||||
if (!clipper.AddPath(path, ClipperLib::ptSubject, true))
|
if (!clipper.AddPath(path, ClipperLib::ptSubject, true))
|
||||||
{
|
{
|
||||||
std::clog << "ptSubject ext failed!\n";
|
std::clog << "ptSubject ext failed!\n";
|
||||||
|
@ -360,6 +402,11 @@ public:
|
||||||
double y = pt.y;
|
double y = pt.y;
|
||||||
path.emplace_back(static_cast<ClipperLib::cInt>(x),static_cast<ClipperLib::cInt>(y));
|
path.emplace_back(static_cast<ClipperLib::cInt>(x),static_cast<ClipperLib::cInt>(y));
|
||||||
}
|
}
|
||||||
|
area = ClipperLib::Area(path);
|
||||||
|
if (area < 0)
|
||||||
|
{
|
||||||
|
std::reverse(path.begin(), path.end());
|
||||||
|
}
|
||||||
if (!clipper.AddPath(path, ClipperLib::ptSubject, true))
|
if (!clipper.AddPath(path, ClipperLib::ptSubject, true))
|
||||||
{
|
{
|
||||||
std::clog << "ptSubject ext failed!\n";
|
std::clog << "ptSubject ext failed!\n";
|
||||||
|
@ -379,39 +426,17 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
ClipperLib::PolyTree polygons;
|
ClipperLib::PolyTree polygons;
|
||||||
clipper.Execute(ClipperLib::ctIntersection, polygons, ClipperLib::pftNonZero, ClipperLib::pftNonZero);
|
clipper.Execute(ClipperLib::ctIntersection, polygons);// ClipperLib::pftNonZero);
|
||||||
clipper.Clear();
|
clipper.Clear();
|
||||||
ClipperLib::PolyNode* polynode = polygons.GetFirst();
|
|
||||||
mapnik::geometry::multi_polygon<double> mp;
|
mapnik::geometry::multi_polygon<double> mp;
|
||||||
mp.emplace_back();
|
for (auto * polynode : polygons.Childs)
|
||||||
bool first = true;
|
|
||||||
while (polynode)
|
|
||||||
{
|
{
|
||||||
if (!polynode->IsHole())
|
process_polynode_branch(polynode, mp);
|
||||||
{
|
|
||||||
if (first) first = false;
|
|
||||||
else mp.emplace_back(); // start new polygon
|
|
||||||
for (auto const& pt : polynode->Contour)
|
|
||||||
{
|
|
||||||
mp.back().exterior_ring.add_coord(pt.x, pt.y);
|
|
||||||
}
|
|
||||||
// childrens are interior rings
|
|
||||||
for (auto const* ring : polynode->Childs)
|
|
||||||
{
|
|
||||||
mapnik::geometry::linear_ring<double> hole;
|
|
||||||
for (auto const& pt : ring->Contour)
|
|
||||||
{
|
|
||||||
hole.add_coord(pt.x, pt.y);
|
|
||||||
}
|
|
||||||
mp.back().add_hole(std::move(hole));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
polynode = polynode->GetNext();
|
|
||||||
}
|
}
|
||||||
std::string expect = expected_+".png";
|
std::string expect = expected_+".png";
|
||||||
std::string actual = expected_+"_actual.png";
|
std::string actual = expected_+"_actual.png";
|
||||||
mapnik::geometry::geometry<double> geom2(mp);
|
//mapnik::geometry::geometry<double> geom2(mp);
|
||||||
auto env = mapnik::geometry::envelope(geom2);
|
auto env = mapnik::geometry::envelope(mp);
|
||||||
if (!mapnik::util::exists(expect) || (std::getenv("UPDATE") != nullptr))
|
if (!mapnik::util::exists(expect) || (std::getenv("UPDATE") != nullptr))
|
||||||
{
|
{
|
||||||
std::clog << "generating expected image: " << expect << "\n";
|
std::clog << "generating expected image: " << expect << "\n";
|
||||||
|
|
Loading…
Add table
Reference in a new issue