WIP: Create another approach to heal shape BUT it is not working
This commit is contained in:
parent
8c2ac9d83b
commit
8f09c3ac82
6 changed files with 377 additions and 174 deletions
|
@ -216,20 +216,20 @@ ExPolygons heal_and_check(const Polygons &polygons)
|
|||
Pointfs intersections = intersection_points(shape);
|
||||
Points shape_points = to_points(shape);
|
||||
Points duplicits = collect_duplicates(shape_points);
|
||||
//{
|
||||
// BoundingBox bb(polygons_points);
|
||||
// // bb.scale(svg_scale);
|
||||
// SVG svg("C:/data/temp/test_visualization.svg", bb);
|
||||
// svg.draw(polygons, "gray"); // input
|
||||
// svg.draw(shape, "green"); // output
|
||||
{
|
||||
BoundingBox bb(polygons_points);
|
||||
// bb.scale(svg_scale);
|
||||
SVG svg("C:/data/temp/test_visualization.svg", bb);
|
||||
svg.draw(polygons, "gray"); // input
|
||||
svg.draw(shape, "green"); // output
|
||||
|
||||
// Points pts;
|
||||
// pts.reserve(intersections.size());
|
||||
// for (const Vec2d &intersection : intersections)
|
||||
// pts.push_back(intersection.cast<int>());
|
||||
// svg.draw(pts, "red", 10);
|
||||
// svg.draw(duplicits, "orenge", 10);
|
||||
//}
|
||||
Points pts;
|
||||
pts.reserve(intersections.size());
|
||||
for (const Vec2d &intersection : intersections)
|
||||
pts.push_back(intersection.cast<int>());
|
||||
svg.draw(pts, "red", 10);
|
||||
svg.draw(duplicits, "orenge", 10);
|
||||
}
|
||||
|
||||
CHECK(intersections.empty());
|
||||
CHECK(duplicits.empty());
|
||||
|
@ -241,39 +241,49 @@ void scale(Polygons &polygons, double multiplicator) {
|
|||
for (Point &p : polygon) p *= multiplicator;
|
||||
}
|
||||
|
||||
TEST_CASE("Heal of damaged polygons", "[Emboss]")
|
||||
{
|
||||
// Shape loaded from svg is letter 'i' from font 'ALIENATE.TTF'
|
||||
std::string file_name = "contour_ALIENATO.TTF_glyph_i.svg";
|
||||
std::string file_path = TEST_DATA_DIR PATH_SEPARATOR + file_name;
|
||||
Polygons load_polygons(const std::string &svg_file) {
|
||||
std::string file_path = TEST_DATA_DIR PATH_SEPARATOR + svg_file;
|
||||
NSVGimage *image = nsvgParseFromFile(file_path.c_str(), "px", 96.0f);
|
||||
Polygons polygons = NSVGUtils::to_polygons(image);
|
||||
nsvgDelete(image);
|
||||
return polygons;
|
||||
}
|
||||
|
||||
heal_and_check(polygons);
|
||||
TEST_CASE("Heal of 'i' in ALIENATO.TTF", "[Emboss]")
|
||||
{
|
||||
// Shape loaded from svg is letter 'i' from font 'ALIENATE.TTF'
|
||||
std::string file_name = "contour_ALIENATO.TTF_glyph_i.svg";
|
||||
Polygons polygons = load_polygons(file_name);
|
||||
|
||||
auto a = heal_and_check(polygons);
|
||||
|
||||
Polygons scaled_shape = polygons; // copy
|
||||
scale(scaled_shape, 1 / Emboss::SHAPE_SCALE);
|
||||
heal_and_check(scaled_shape);
|
||||
auto b = heal_and_check(scaled_shape);
|
||||
|
||||
// different scale
|
||||
scale(scaled_shape, 10.);
|
||||
heal_and_check(scaled_shape);
|
||||
auto c = heal_and_check(scaled_shape);
|
||||
|
||||
// check reverse order of points
|
||||
Polygons reverse_shape = polygons;
|
||||
for (Polygon &p : reverse_shape)
|
||||
std::reverse(p.points.begin(), p.points.end());
|
||||
heal_and_check(scaled_shape);
|
||||
auto d = heal_and_check(scaled_shape);
|
||||
|
||||
#ifdef VISUALIZE
|
||||
CHECK(false);
|
||||
#endif // VISUALIZE
|
||||
}
|
||||
|
||||
TEST_CASE("Heal of 'm' in Allura_Script.ttf", "[Emboss]")
|
||||
{
|
||||
Polygons polygons = load_polygons("contour_Allura_Script.ttf_glyph_m.svg");
|
||||
auto a = heal_and_check(polygons);
|
||||
}
|
||||
|
||||
TEST_CASE("Heal of points close to line", "[Emboss]")
|
||||
{
|
||||
// Shape loaded from svg is letter 'i' from font 'ALIENATE.TTF'
|
||||
std::string file_name = "points_close_to_line.svg";
|
||||
std::string file_path = TEST_DATA_DIR PATH_SEPARATOR + file_name;
|
||||
NSVGimage *image = nsvgParseFromFile(file_path.c_str(), "px", 96.0f);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue