1+ /*
2+ * Copyright (c) 2019 - 2024 Geode-solutions
3+ *
4+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5+ * of this software and associated documentation files (the "Software"), to deal
6+ * in the Software without restriction, including without limitation the rights
7+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+ * copies of the Software, and to permit persons to whom the Software is
9+ * furnished to do so, subject to the following conditions:
10+ *
11+ * The above copyright notice and this permission notice shall be included in
12+ * all copies or substantial portions of the Software.
13+ *
14+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20+ * SOFTWARE.
21+ *
22+ */
23+ #include < geode/basic/logger.h>
24+
25+ #include < geode/geometry/bounding_box.h>
26+ #include < geode/geometry/point.h>
27+
28+ #include < geode/mesh/helpers/build_grid.h>
29+
30+ #include < geode/tests/common.h>
31+
32+ void test ()
33+ {
34+ geode::OpenGeodeMeshLibrary::initialize ();
35+ const geode::index_t max_nb_cells{ 100 };
36+ geode::BoundingBox2D bbox;
37+ bbox.add_point ( { { 0 , 0 } } );
38+ bbox.add_point ( { { 1 , 1 } } );
39+ const auto grid =
40+ geode::build_grid_from_bbox_target_length_and_maximum_cell_number (
41+ bbox, 0.01 , max_nb_cells );
42+ DEBUG ( grid.nb_cells () );
43+ DEBUG ( grid.nb_cells_in_direction ( 0 ) );
44+ DEBUG ( grid.nb_cells_in_direction ( 1 ) );
45+ DEBUG ( grid.cell_length_in_direction ( 0 ) );
46+ DEBUG ( grid.cell_length_in_direction ( 1 ) );
47+ OPENGEODE_EXCEPTION ( grid.nb_cells () <= max_nb_cells,
48+ " [Test] Too much cells in built grid" );
49+
50+ bbox.add_point ( { { 1 , 10 } } );
51+ const auto grid2 =
52+ geode::build_grid_from_bbox_target_length_and_maximum_cell_number (
53+ bbox, 0.01 , max_nb_cells );
54+ DEBUG ( grid2.nb_cells () );
55+ DEBUG ( grid2.nb_cells_in_direction ( 0 ) );
56+ DEBUG ( grid2.nb_cells_in_direction ( 1 ) );
57+ DEBUG ( grid2.cell_length_in_direction ( 0 ) );
58+ DEBUG ( grid2.cell_length_in_direction ( 1 ) );
59+ OPENGEODE_EXCEPTION ( grid.nb_cells () <= max_nb_cells,
60+ " [Test] Too much cells in built grid2" );
61+
62+ bbox.add_point ( { { 3 , 10 } } );
63+ const auto grid3 =
64+ geode::build_grid_from_bbox_target_length_and_maximum_cell_number (
65+ bbox, 0.01 , max_nb_cells );
66+ DEBUG ( grid3.nb_cells () );
67+ DEBUG ( grid3.nb_cells_in_direction ( 0 ) );
68+ DEBUG ( grid3.nb_cells_in_direction ( 1 ) );
69+ DEBUG ( grid3.cell_length_in_direction ( 0 ) );
70+ DEBUG ( grid3.cell_length_in_direction ( 1 ) );
71+ OPENGEODE_EXCEPTION ( grid.nb_cells () <= max_nb_cells,
72+ " [Test] Too much cells in built grid3" );
73+ }
74+
75+ OPENGEODE_TEST ( " graph" )
0 commit comments