Blender V5.3
mesh_brush_common_tests.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2025 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
5
6#include "BKE_gtest_base.hh"
7#include "BKE_lib_id.hh"
8
9#include "BLI_array_utils.hh"
10#include "BLI_map.hh"
11
12#include "DNA_mesh_types.h"
13
16
17#include "sculpt_boundary.hh"
18
19#include "testing/testing.h"
20
22
24 public:
26
27 void TearDown() override
28 {
29 if (mesh) {
30 BKE_id_free(nullptr, mesh);
31 }
32 }
33};
34
35TEST_F(MeshBrushCommonTests, calc_vert_neighbors_interior__cube)
36{
37 mesh = geometry::create_cuboid_mesh(float3(1.0, 1.0, 1.0), 2, 2, 2);
38
39 const OffsetIndices faces = mesh->faces();
40 const Span<int> corner_verts = mesh->corner_verts();
41 const GroupedSpan<int> vert_to_face_map = mesh->vert_to_face_map();
42 const Vector<bool> hide_poly(mesh->faces_num, false);
43
44 Array<int> verts(8);
46
48
49 Vector<int> offset_data;
52 corner_verts,
53 vert_to_face_map,
54 boundary_info_cache.verts,
55 boundary_info_cache.edges,
56 hide_poly,
57 verts,
58 offset_data,
59 data);
60
61 /* Each of the cube's 8 vertices should have 3 neighbor elements */
62 Map<int, int> expected_counts = {{3, 8}};
63
64 ASSERT_EQ(result.size(), 8);
65 Map<int, int> calculated_counts;
66 for (const int i : result.index_range()) {
67 calculated_counts.add_or_modify(
68 result[i].size(), [](int *value) { *value = 1; }, [](int *value) { (*value)++; });
69 }
70 for (const int key : expected_counts.keys()) {
71 ASSERT_EQ(calculated_counts.lookup_default(key, -1), expected_counts.lookup_default(key, -2));
72 }
73}
74
75TEST_F(MeshBrushCommonTests, calc_vert_neighbors_interior__1D_strip)
76{
77 mesh = geometry::create_grid_mesh(3, 2, 1.0, 1.0, {});
78
79 const OffsetIndices faces = mesh->faces();
80 const Span<int> corner_verts = mesh->corner_verts();
81 const GroupedSpan<int> vert_to_face_map = mesh->vert_to_face_map();
82 const Vector<bool> hide_poly(mesh->faces_num, false);
83
84 Array<int> verts(6);
86
88
89 Vector<int> offset_data;
92 corner_verts,
93 vert_to_face_map,
94 boundary_info_cache.verts,
95 boundary_info_cache.edges,
96 hide_poly,
97 verts,
98 offset_data,
99 data);
100 /* The 4 corner elements should each have no neighbor. The remaining 2 elements should have 2
101 * neighbors */
102 Map<int, int> expected_counts = {{0, 4}, {2, 2}};
103
104 ASSERT_EQ(result.size(), 6);
105 Map<int, int> calculated_counts;
106 for (const int i : result.index_range()) {
107 calculated_counts.add_or_modify(
108 result[i].size(), [](int *value) { *value = 1; }, [](int *value) { (*value)++; });
109 }
110 for (const int key : expected_counts.keys()) {
111 ASSERT_EQ(calculated_counts.lookup_default(key, -1), expected_counts.lookup_default(key, -2));
112 }
113}
114} // namespace blender::ed::sculpt_paint::tests
MutableSpan< T > as_mutable_span()
Definition BLI_array.hh:259
Value lookup_default(const Key &key, const Value &default_value) const
Definition BLI_map.hh:570
KeyIterator keys() const &
Definition BLI_map.hh:875
auto add_or_modify(const Key &key, const CreateValueF &create_value, const ModifyValueF &modify_value) -> decltype(create_value(nullptr))
Definition BLI_map.hh:481
void fill_index_range(MutableSpan< T > span, const T start=0)
SculptBoundaryInfoCache create_boundary_info(const Mesh &mesh)
Definition sculpt.cc:599
TEST_F(MeshBrushCommonTests, calc_vert_neighbors_interior__cube)
GroupedSpan< int > calc_vert_neighbors_interior(OffsetIndices< int > faces, Span< int > corner_verts, GroupedSpan< int > vert_to_face, BitSpan boundary_verts, const Set< OrderedEdge > &boundary_edges, Span< bool > hide_poly, Span< int > verts, Vector< int > &r_offset_data, Vector< int > &r_data)
Definition sculpt.cc:8099
Mesh * create_cuboid_mesh(const float3 &size, int verts_x, int verts_y, int verts_z, std::optional< StringRef > uv_id)
Mesh * create_grid_mesh(int verts_x, int verts_y, float size_x, float size_y, std::optional< StringRef > uv_map_id)
BMesh const char void * data
void BKE_id_free(Main *bmain, void *idv)
VecBase< float, 3 > float3