MCPcopy Create free account
hub / github.com/Geode-solutions/OpenGeode / first_test

Function first_test

tests/geometry/test-nnsearch.cpp:32–97  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

30#include <geode/tests/common.hpp>
31
32void first_test()
33{
34 const geode::NNSearch2D search{ { geode::Point2D{ { 0.1, 4.2 } },
35 geode::Point2D{ { 5.9, 7.3 } }, geode::Point2D{ { 1.8, -5 } },
36 geode::Point2D{ { -7.3, -1.6 } } } };
37
38 geode::OpenGeodeGeometryException::test(
39 search.closest_neighbor( geode::Point2D{ { 0, 0 } } ) == 0,
40 "Error in closest neighbor" );
41 geode::OpenGeodeGeometryException::test(
42 search.closest_neighbor( geode::Point2D{ { 1, -4 } } ) == 2,
43 "Error in closest neighbor" );
44
45 const std::vector< geode::index_t > answer_radius{ 0, 2 };
46 geode::OpenGeodeGeometryException::test(
47 search.radius_neighbors( geode::Point2D{ { 0, 0 } }, 5.4 )
48 == answer_radius,
49 "Error in radius neighbors" );
50
51 const std::vector< geode::index_t > answer_neighbors{ 2, 0 };
52 geode::OpenGeodeGeometryException::test(
53 search.neighbors( geode::Point2D{ { -1, -1 } }, 2 ) == answer_neighbors,
54 "Error in neighbors" );
55
56 const geode::Point3D p0{ { 0.1, 2.9, 5.4 } };
57 const geode::Point3D p1{ { 2.4, 8.1, 7.6 } };
58 const geode::Point3D p2{ { 8.1, 4.2, 3.8 } };
59 const geode::Point3D p3{ { 3.1, 9.4, 9.7 } };
60 std::vector< geode::Point3D > points{ p0, p0, p1, p0, p2, p1, p3 };
61 const geode::NNSearch3D colocator( points );
62
63 const auto colocated_info =
64 colocator.colocated_index_mapping( geode::GLOBAL_EPSILON );
65 geode::OpenGeodeGeometryException::test(
66 colocated_info.nb_colocated_points() == 3,
67 "[Test 1] Should be 3 colocated points" );
68 for( const auto p : geode::Indices{ points } )
69 {
70 geode::OpenGeodeGeometryException::test(
71 colocated_info.colocated_mapping[p]
72 < colocated_info.unique_points.size(),
73 "[Test 1] Wrong value of colocated_mapping (bigger than unique "
74 "points size)" );
75 const auto& colocated_point =
76 colocated_info.unique_points[colocated_info.colocated_mapping[p]];
77 geode::OpenGeodeGeometryException::test(
78 geode::point_point_distance( points[p], colocated_point )
79 <= geode::GLOBAL_EPSILON,
80 "[Test 1] Colocated point is not close enough to original point" );
81 }
82 for( const auto up0 : geode::Indices{ colocated_info.unique_points } )
83 {
84 for( const auto up1 : geode::Indices{ colocated_info.unique_points } )
85 {
86 if( up1 <= up0 )
87 {
88 continue;
89 }

Callers 1

testFunction · 0.85

Calls 8

point_point_distanceFunction · 0.85
closest_neighborMethod · 0.80
nb_colocated_pointsMethod · 0.80
testFunction · 0.70
radius_neighborsMethod · 0.45
neighborsMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected