mirror of
https://git.mirrors.martin98.com/https://github.com/slic3r/Slic3r.git
synced 2025-08-03 03:30:44 +08:00
testcase for remove_collinear_points in Polygon
This commit is contained in:
parent
72b0d2b763
commit
db426758ca
@ -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
|
||||
|
48
src/test/libslic3r/test_polygon.cpp
Normal file
48
src/test/libslic3r/test_polygon.cpp
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user