Find closest point from points

This commit is contained in:
Filip Sykala - NTB T15p 2022-07-18 13:26:06 +02:00
parent 4889a1a1b1
commit 8f66ba4bd5
5 changed files with 194 additions and 1 deletions

View file

@ -7,10 +7,11 @@ add_executable(${_TEST_NAME}_tests
test_kdtreeindirect.cpp
test_clipper_offset.cpp
test_clipper_utils.cpp
test_closest_point.cpp
test_color.cpp
test_config.cpp
test_curve_fitting.cpp
test_cut_surface.cpp
test_cut_surface.cpp
test_elephant_foot_compensation.cpp
test_geometry.cpp
test_placeholder_parser.cpp

View file

@ -0,0 +1,42 @@
#include <catch2/catch.hpp>
#include <libslic3r/ClosestPoint.hpp>
using namespace Slic3r;
TEST_CASE("Find the closest point from 2", "[ClosestPoint]")
{
Points pts = {{0, 1}, {0, 2}};
CHECK(std::is_sorted(pts.begin(), pts.end(), closestPoint::sort_fnc));
CHECK(0 == find_closest_in_sorted(Point{0, 0}, pts));
CHECK(0 == find_closest_in_sorted(Point{1, 1}, pts));
CHECK(1 == find_closest_in_sorted(Point{1, 2}, pts));
}
TEST_CASE("Find the closest point from 9", "[ClosestPoint]")
{
// 0 - 3 - 6
// | | |
// 1 - 4 - 7
// | | |
// 2 - 5 - 8
Points pts = {{-3, 3}, {-3, 0}, {-3, -3}, {0, 3}, {0, 0},
{0, -3}, {3, 3}, {3, 0}, {3, -3}};
CHECK(std::is_sorted(pts.begin(), pts.end(), closestPoint::sort_fnc));
CHECK(0 == find_closest_in_sorted(Point{-4, 4}, pts));
CHECK(0 == find_closest_in_sorted(Point{-2, 2}, pts));
// check center
CHECK(4 == find_closest_in_sorted(Point{-1, 1}, pts));
CHECK(4 == find_closest_in_sorted(Point{ 0, 1}, pts));
CHECK(4 == find_closest_in_sorted(Point{ 1, 1}, pts));
CHECK(4 == find_closest_in_sorted(Point{-1, 0}, pts));
CHECK(4 == find_closest_in_sorted(Point{ 0, 0}, pts));
CHECK(4 == find_closest_in_sorted(Point{ 1, 0}, pts));
CHECK(4 == find_closest_in_sorted(Point{-1,-1}, pts));
CHECK(4 == find_closest_in_sorted(Point{ 0,-1}, pts));
CHECK(4 == find_closest_in_sorted(Point{ 1,-1}, pts));
CHECK(4 == find_closest_in_sorted(Point{ 0, 0}, pts));
CHECK(7 == find_closest_in_sorted(Point{2, 1}, pts));
CHECK(8 == find_closest_in_sorted(Point{2,-2}, pts));
}