Debian Codegraph @

tests/scene/test_height_map_shape_3d.h

raw symbols SCIP
1 /**************************************************************************/
2 /* test_height_map_shape_3d.h */
3 /**************************************************************************/
4 /* This file is part of: */
5 /* GODOT ENGINE */
6 /* https://godotengine.org */
7 /**************************************************************************/
8 /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9 /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10 /* */
11 /* Permission is hereby granted, free of charge, to any person obtaining */
12 /* a copy of this software and associated documentation files (the */
13 /* "Software"), to deal in the Software without restriction, including */
14 /* without limitation the rights to use, copy, modify, merge, publish, */
15 /* distribute, sublicense, and/or sell copies of the Software, and to */
16 /* permit persons to whom the Software is furnished to do so, subject to */
17 /* the following conditions: */
18 /* */
19 /* The above copyright notice and this permission notice shall be */
20 /* included in all copies or substantial portions of the Software. */
21 /* */
22 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25 /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26 /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27 /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28 /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29 /**************************************************************************/
30
31 #pragma once
32
33 #include "scene/resources/3d/height_map_shape_3d.h"
34 #include "scene/resources/image_texture.h"
35
36 #include "tests/test_macros.h"
37 #include "tests/test_utils.h"
38
39 namespace TestHeightMapShape3D {
40
41 TEST_CASE("[SceneTree][HeightMapShape3D] Constructor") {
42 Ref<HeightMapShape3D> height_map_shape = memnew(HeightMapShape3D);
43 CHECK(height_map_shape->get_map_width() == 2);
44 CHECK(height_map_shape->get_map_depth() == 2);
45 CHECK(height_map_shape->get_map_data().size() == 4);
46 CHECK(height_map_shape->get_min_height() == 0.0);
47 CHECK(height_map_shape->get_max_height() == 0.0);
48 }
49
50 TEST_CASE("[SceneTree][HeightMapShape3D] set_map_width and get_map_width") {
51 Ref<HeightMapShape3D> height_map_shape = memnew(HeightMapShape3D);
52 height_map_shape->set_map_width(10);
53 CHECK(height_map_shape->get_map_width() == 10);
54 }
55
56 TEST_CASE("[SceneTree][HeightMapShape3D] set_map_depth and get_map_depth") {
57 Ref<HeightMapShape3D> height_map_shape = memnew(HeightMapShape3D);
58 height_map_shape->set_map_depth(15);
59 CHECK(height_map_shape->get_map_depth() == 15);
60 }
61
62 TEST_CASE("[SceneTree][HeightMapShape3D] set_map_data and get_map_data") {
63 Ref<HeightMapShape3D> height_map_shape = memnew(HeightMapShape3D);
64 Vector<real_t> map_data;
65 map_data.push_back(1.0);
66 map_data.push_back(2.0);
67 height_map_shape->set_map_data(map_data);
68 CHECK(height_map_shape->get_map_data().size() == 4.0);
69 CHECK(height_map_shape->get_map_data()[0] == 0.0);
70 CHECK(height_map_shape->get_map_data()[1] == 0.0);
71 }
72
73 TEST_CASE("[SceneTree][HeightMapShape3D] get_min_height") {
74 Ref<HeightMapShape3D> height_map_shape = memnew(HeightMapShape3D);
75 height_map_shape->set_map_width(3);
76 height_map_shape->set_map_depth(1);
77 height_map_shape->set_map_data(Vector<real_t>{ 1.0, 2.0, 0.5 });
78 CHECK(height_map_shape->get_min_height() == 0.5);
79 }
80
81 TEST_CASE("[SceneTree][HeightMapShape3D] get_max_height") {
82 Ref<HeightMapShape3D> height_map_shape = memnew(HeightMapShape3D);
83 height_map_shape->set_map_width(3);
84 height_map_shape->set_map_depth(1);
85 height_map_shape->set_map_data(Vector<real_t>{ 1.0, 2.0, 0.5 });
86 CHECK(height_map_shape->get_max_height() == 2.0);
87 }
88
89 TEST_CASE("[SceneTree][HeightMapShape3D] update_map_data_from_image") {
90 // Create a HeightMapShape3D instance.
91 Ref<HeightMapShape3D> height_map_shape = memnew(HeightMapShape3D);
92
93 // Create a mock image with FORMAT_R8 and set its data.
94 Vector<uint8_t> image_data;
95 image_data.push_back(0);
96 image_data.push_back(128);
97 image_data.push_back(255);
98 image_data.push_back(64);
99
100 Ref<Image> image = memnew(Image);
101 image->set_data(2, 2, false, Image::FORMAT_R8, image_data);
102
103 height_map_shape->update_map_data_from_image(image, 0.0, 10.0);
104
105 // Check the map data.
106 Vector<real_t> expected_map_data = { 0.0, 5.0, 10.0, 2.5 };
107 Vector<real_t> actual_map_data = height_map_shape->get_map_data();
108 real_t tolerance = 0.1;
109
110 for (int i = 0; i < expected_map_data.size(); ++i) {
111 CHECK(Math::abs(actual_map_data[i] - expected_map_data[i]) < tolerance);
112 }
113
114 // Check the min and max heights.
115 CHECK(height_map_shape->get_min_height() == 0.0);
116 CHECK(height_map_shape->get_max_height() == 10.0);
117 }
118
119 } // namespace TestHeightMapShape3D