Heal shape with points close to line
(after conversion to floating point it is on the other side of line) ExPolygons indexing (fixed)
This commit is contained in:
parent
bdf8c5ce88
commit
8511b280bf
10 changed files with 571 additions and 99 deletions
3
tests/data/points_close_to_line.svg
Normal file
3
tests/data/points_close_to_line.svg
Normal file
|
@ -0,0 +1,3 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 50 100" width="50px" height="100px">
|
||||
<path fill="#808080" d="M 10,10 11,90 20,80 11,70 25,50 V 22 L 10,20 40,15 Z"/>
|
||||
</svg>
|
After Width: | Height: | Size: 177 B |
|
@ -197,7 +197,7 @@ TEST_CASE("Visualize glyph from font", "[Emboss]")
|
|||
#include "test_utils.hpp"
|
||||
#include "nanosvg/nanosvg.h" // load SVG file
|
||||
#include "libslic3r/NSVGUtils.hpp"
|
||||
void heal_and_check(const Polygons &polygons)
|
||||
ExPolygons heal_and_check(const Polygons &polygons)
|
||||
{
|
||||
Pointfs intersections_prev = intersection_points(polygons);
|
||||
Points polygons_points = to_points(polygons);
|
||||
|
@ -233,6 +233,7 @@ void heal_and_check(const Polygons &polygons)
|
|||
|
||||
CHECK(intersections.empty());
|
||||
CHECK(duplicits.empty());
|
||||
return shape;
|
||||
}
|
||||
|
||||
void scale(Polygons &polygons, double multiplicator) {
|
||||
|
@ -270,6 +271,23 @@ TEST_CASE("Heal of damaged polygons", "[Emboss]")
|
|||
#endif // VISUALIZE
|
||||
}
|
||||
|
||||
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);
|
||||
Polygons polygons = NSVGUtils::to_polygons(image);
|
||||
nsvgDelete(image);
|
||||
REQUIRE(polygons.size() == 1);
|
||||
Polygon polygon = polygons.front();
|
||||
polygon.points.pop_back();// NSVG put first point as last one when polygon is closed
|
||||
ExPolygons expoly({ExPolygon(polygon)});
|
||||
Emboss::heal_shape(expoly);
|
||||
//{ SVG svg("C:/data/temp/healed.svg"); svg.draw(expoly);}
|
||||
CHECK(expoly.size() == 3);
|
||||
}
|
||||
|
||||
TEST_CASE("Convert text with glyph cache to model", "[Emboss]")
|
||||
{
|
||||
std::string font_path = get_font_filepath();
|
||||
|
|
|
@ -210,3 +210,34 @@ SCENARIO("Simplify polygon", "[Polygon]")
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
#include "libslic3r/ExPolygon.hpp"
|
||||
#include "libslic3r/ExPolygonsIndex.hpp"
|
||||
TEST_CASE("Indexing expolygons", "[ExPolygon]")
|
||||
{
|
||||
ExPolygons expolys{
|
||||
ExPolygon{Polygon{{0, 0}, {10, 0}, {0, 5}}, Polygon{{4, 3}, {6, 3}, {5, 2}}},
|
||||
ExPolygon{Polygon{{100, 0}, {110, 0}, {100, 5}}, Polygon{{104, 3}, {106, 3}, {105, 2}}}
|
||||
};
|
||||
Points points = to_points(expolys);
|
||||
Lines lines = to_lines(expolys);
|
||||
Linesf linesf = to_linesf(expolys);
|
||||
ExPolygonsIndices ids(expolys);
|
||||
REQUIRE(points.size() == lines.size());
|
||||
REQUIRE(points.size() == linesf.size());
|
||||
REQUIRE(points.size() == ids.get_count());
|
||||
for (size_t i = 0; i < ids.get_count(); i++) {
|
||||
ExPolygonsIndex id = ids.cvt(i);
|
||||
const ExPolygon &expoly = expolys[id.expolygons_index];
|
||||
const Polygon &poly = id.is_contour() ? expoly.contour : expoly.holes[id.hole_index()];
|
||||
const Points &pts = poly.points;
|
||||
const Point &p = pts[id.point_index];
|
||||
CHECK(points[i] == p);
|
||||
CHECK(lines[i].a == p);
|
||||
CHECK(linesf[i].a.cast<int>() == p);
|
||||
CHECK(ids.cvt(id) == i);
|
||||
const Point &p_b = ids.is_last_point(id) ? pts.front() : pts[id.point_index + 1];
|
||||
CHECK(lines[i].b == p_b);
|
||||
CHECK(linesf[i].b.cast<int>() == p_b);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue