SubdivCCG: Add to_index helper method
This commit adds a method to compute the position of a given SubdivCCGCoord in an appropriately sized array. Pull Request: https://projects.blender.org/blender/blender/pulls/125462
This commit is contained in:
@@ -68,6 +68,14 @@ struct SubdivCCGCoord {
|
||||
|
||||
/* Coordinate within the grid. */
|
||||
short x, y;
|
||||
|
||||
/* Returns the index for the coordinate in an array sized to contain all grid vertices (including
|
||||
* duplicates) */
|
||||
int to_index(const CCGKey &key) const
|
||||
{
|
||||
return key.grid_area * this->grid_index +
|
||||
CCG_grid_xy_to_index(key.grid_size, this->x, this->y);
|
||||
}
|
||||
};
|
||||
|
||||
/* Definition of an edge which is adjacent to at least one of the faces. */
|
||||
|
||||
@@ -849,6 +849,7 @@ if(WITH_GTESTS)
|
||||
intern/lib_remap_test.cc
|
||||
intern/main_test.cc
|
||||
intern/nla_test.cc
|
||||
intern/subdiv_ccg_test.cc
|
||||
intern/tracking_test.cc
|
||||
intern/volume_test.cc
|
||||
)
|
||||
|
||||
36
source/blender/blenkernel/intern/subdiv_ccg_test.cc
Normal file
36
source/blender/blenkernel/intern/subdiv_ccg_test.cc
Normal file
@@ -0,0 +1,36 @@
|
||||
/* SPDX-FileCopyrightText: 2024 Blender Authors
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
|
||||
#include "testing/testing.h"
|
||||
|
||||
#include "BKE_subdiv_ccg.hh"
|
||||
#include "BKE_subsurf.hh"
|
||||
|
||||
namespace blender::bke::tests {
|
||||
TEST(subdiv_ccg_coord, to_index)
|
||||
{
|
||||
CCGKey key;
|
||||
key.level = 2;
|
||||
key.elem_size = sizeof(float);
|
||||
|
||||
key.has_normals = false;
|
||||
key.has_mask = false;
|
||||
|
||||
key.normal_offset = -1;
|
||||
key.mask_offset = -1;
|
||||
|
||||
key.grid_size = BKE_ccg_gridsize(key.level); /* 3 */
|
||||
key.grid_area = key.grid_size * key.grid_size; /* 9 */
|
||||
key.grid_bytes = key.grid_area * key.elem_size;
|
||||
|
||||
SubdivCCGCoord coord;
|
||||
coord.grid_index = 2;
|
||||
coord.x = 1;
|
||||
coord.y = 1;
|
||||
|
||||
/* (grid_index * grid_area) + y * grid_size + x */
|
||||
/* (2 * 9) + (1 * 3) + 1 */
|
||||
EXPECT_EQ(coord.to_index(key), 22);
|
||||
}
|
||||
} // namespace blender::bke::tests
|
||||
Reference in New Issue
Block a user