testcase for remove_collinear_points in Polygon

This commit is contained in:
Florens Wasserfall 2019-02-06 17:51:48 +01:00 committed by Joseph Lenox
parent 72b0d2b763
commit db426758ca
2 changed files with 49 additions and 0 deletions

View File

@ -306,6 +306,7 @@ set(SLIC3R_TEST_SOURCES
${TESTDIR}/libslic3r/test_geometry.cpp
${TESTDIR}/libslic3r/test_log.cpp
${TESTDIR}/libslic3r/test_model.cpp
${TESTDIR}/libslic3r/test_polygon.cpp
${TESTDIR}/libslic3r/test_print.cpp
${TESTDIR}/libslic3r/test_printgcode.cpp
${TESTDIR}/libslic3r/test_skirt_brim.cpp

View File

@ -0,0 +1,48 @@
#include <catch.hpp>
#include "Point.hpp"
#include "Polygon.hpp"
using namespace Slic3r;
// This test currently only covers remove_collinear_points.
// All remaining tests are to be ported from xs/t/06_polygon.t
Points collinear_circle({
Point::new_scale(0, 0), // 3 collinear points at beginning
Point::new_scale(10, 0),
Point::new_scale(20, 0),
Point::new_scale(30, 10),
Point::new_scale(40, 20), // 2 collinear points
Point::new_scale(40, 30),
Point::new_scale(30, 40), // 3 collinear points
Point::new_scale(20, 40),
Point::new_scale(10, 40),
Point::new_scale(-10, 20),
Point::new_scale(-20, 10),
Point::new_scale(-20, 0), // 3 collinear points at end
Point::new_scale(-10, 0),
Point::new_scale(-5, 0)
});
SCENARIO("Remove collinear points from Polygon") {
GIVEN("Polygon with collinear points"){
Polygon p(collinear_circle);
WHEN("collinear points are removed") {
p.remove_collinear_points();
THEN("Leading collinear points are removed") {
REQUIRE(p.points.front() == Point::new_scale(20, 0));
}
THEN("Trailing collinear points are removed") {
REQUIRE(p.points.back() == Point::new_scale(-20, 0));
}
THEN("Number of remaining points is correct") {
REQUIRE(p.points.size() == 7);
}
}
}
}