You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
118 lines
3.6 KiB
C++
118 lines
3.6 KiB
C++
4 months ago
|
//Copyright (c) 2015 Ultimaker B.V.
|
||
|
//CuraEngine is released under the terms of the AGPLv3 or higher.
|
||
|
|
||
|
#include "PolygonTest.h"
|
||
|
|
||
|
namespace cura
|
||
|
{
|
||
|
CPPUNIT_TEST_SUITE_REGISTRATION(PolygonTest);
|
||
|
|
||
|
void PolygonTest::setUp()
|
||
|
{
|
||
|
test_square.emplace_back(0, 0);
|
||
|
test_square.emplace_back(100, 0);
|
||
|
test_square.emplace_back(100, 100);
|
||
|
test_square.emplace_back(0, 100);
|
||
|
|
||
|
|
||
|
pointy_square.emplace_back(0, 0);
|
||
|
pointy_square.emplace_back(47, 0);
|
||
|
pointy_square.emplace_back(50, 80);
|
||
|
pointy_square.emplace_back(53, 0);
|
||
|
pointy_square.emplace_back(100, 0);
|
||
|
pointy_square.emplace_back(100, 100);
|
||
|
pointy_square.emplace_back(55, 100);
|
||
|
pointy_square.emplace_back(50, 180);
|
||
|
pointy_square.emplace_back(45, 100);
|
||
|
pointy_square.emplace_back(0, 100);
|
||
|
|
||
|
triangle.emplace_back(100, 0);
|
||
|
triangle.emplace_back(300, 0);
|
||
|
triangle.emplace_back(200, 100);
|
||
|
|
||
|
clipper_bug.emplace_back(107347, 120836);
|
||
|
clipper_bug.emplace_back(107309, 120910);
|
||
|
clipper_bug.emplace_back(107158, 120960);
|
||
|
clipper_bug.emplace_back(106760, 120839);
|
||
|
clipper_bug.emplace_back(106570, 120831);
|
||
|
}
|
||
|
|
||
|
void PolygonTest::tearDown()
|
||
|
{
|
||
|
//Do nothing.
|
||
|
}
|
||
|
|
||
|
|
||
|
void PolygonTest::polygonOffsetTest()
|
||
|
{
|
||
|
Polygons test_squares;
|
||
|
test_squares.add(test_square);
|
||
|
Polygons expanded = test_squares.offset(25);
|
||
|
int64_t expanded_length = expanded.polygonLength();
|
||
|
|
||
|
Polygons square_hole;
|
||
|
PolygonRef square_inverted = square_hole.newPoly();
|
||
|
for (int i = test_square.size() - 1; i >= 0; i--)
|
||
|
{
|
||
|
square_inverted.add(test_square[i]);
|
||
|
}
|
||
|
Polygons contracted = square_hole.offset(25);
|
||
|
int64_t contracted_length = contracted.polygonLength();
|
||
|
|
||
|
CPPUNIT_ASSERT_MESSAGE("Offset on outside poly is different from offset on inverted poly!", std::abs(expanded_length - contracted_length) < 5);
|
||
|
}
|
||
|
|
||
|
void PolygonTest::polygonOffsetBugTest()
|
||
|
{
|
||
|
Polygons polys;
|
||
|
polys.add(clipper_bug);
|
||
|
Polygons offsetted = polys.offset(-20);
|
||
|
|
||
|
for (PolygonRef poly : offsetted)
|
||
|
{
|
||
|
for (Point& p : poly)
|
||
|
{
|
||
|
CPPUNIT_ASSERT_MESSAGE("Polygon offset moved point the wrong way!", polys.inside(p));
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
void PolygonTest::isOutsideTest()
|
||
|
{
|
||
|
Polygons test_triangle;
|
||
|
test_triangle.add(triangle);
|
||
|
|
||
|
CPPUNIT_ASSERT_MESSAGE("Left point is calculated as inside while it's outside!", !test_triangle.inside(Point(0, 100)));
|
||
|
CPPUNIT_ASSERT_MESSAGE("Middle left point is calculated as inside while it's outside!", !test_triangle.inside(Point(100, 100)));
|
||
|
CPPUNIT_ASSERT_MESSAGE("Middle right point is calculated as inside while it's outside!", !test_triangle.inside(Point(300, 100)));
|
||
|
CPPUNIT_ASSERT_MESSAGE("Right point is calculated as inside while it's outside!", !test_triangle.inside(Point(500, 100)));
|
||
|
CPPUNIT_ASSERT_MESSAGE("Above point is calculated as inside while it's outside!", !test_triangle.inside(Point(100, 200)));
|
||
|
CPPUNIT_ASSERT_MESSAGE("Below point is calculated as inside while it's outside!", !test_triangle.inside(Point(100, -100)));
|
||
|
}
|
||
|
|
||
|
void PolygonTest::isInsideTest()
|
||
|
{
|
||
|
Polygons test_polys;
|
||
|
PolygonRef poly = test_polys.newPoly();
|
||
|
poly.add(Point(82124,98235));
|
||
|
poly.add(Point(83179,98691));
|
||
|
poly.add(Point(83434,98950));
|
||
|
poly.add(Point(82751,99026));
|
||
|
poly.add(Point(82528,99019));
|
||
|
poly.add(Point(81605,98854));
|
||
|
poly.add(Point(80401,98686));
|
||
|
poly.add(Point(79191,98595));
|
||
|
poly.add(Point(78191,98441));
|
||
|
poly.add(Point(78998,98299));
|
||
|
poly.add(Point(79747,98179));
|
||
|
poly.add(Point(80960,98095));
|
||
|
|
||
|
CPPUNIT_ASSERT_MESSAGE("Inside point is calculated as being outside!", test_polys.inside(Point(78315, 98440)));
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
}
|