diff options
author | Campbell Barton <campbell@blender.org> | 2022-07-22 06:05:26 +0300 |
---|---|---|
committer | Campbell Barton <campbell@blender.org> | 2022-07-22 06:07:24 +0300 |
commit | 08c5d99e88ee3e9f807dfe69c188660eae347f31 (patch) | |
tree | 7e4298800487b17a43c289462420507c35e4bb2b /source/blender/editors | |
parent | 72e249974aa7f6a3bd6d5c35c5d5e59cd1c3bded (diff) |
Cleanup: add BKE_image_find_nearest_tile_with_offset
Every caller BKE_image_find_nearest_tile was calculating the tile offset
so add a version of this function that returns the offset too.
Diffstat (limited to 'source/blender/editors')
-rw-r--r-- | source/blender/editors/transform/transform_mode_resize.c | 8 | ||||
-rw-r--r-- | source/blender/editors/transform/transform_mode_translate.c | 8 | ||||
-rw-r--r-- | source/blender/editors/uvedit/uvedit_islands.c | 10 |
3 files changed, 5 insertions, 21 deletions
diff --git a/source/blender/editors/transform/transform_mode_resize.c b/source/blender/editors/transform/transform_mode_resize.c index bbe1cfdf521..1ccda96fecb 100644 --- a/source/blender/editors/transform/transform_mode_resize.c +++ b/source/blender/editors/transform/transform_mode_resize.c @@ -137,13 +137,7 @@ static bool clip_uv_transform_resize(TransInfo *t, float vec[2]) /* If tiled image then constrain to correct/closest UDIM tile, else 0-1 UV space. */ if (is_tiled_image) { - int nearest_tile_index = BKE_image_find_nearest_tile(image, t->center_global); - if (nearest_tile_index != -1) { - nearest_tile_index -= 1001; - /* Getting coordinates of nearest tile from the tile index. */ - base_offset[0] = nearest_tile_index % 10; - base_offset[1] = nearest_tile_index / 10; - } + BKE_image_find_nearest_tile_with_offset(image, t->center_global, base_offset); } /* Assume no change is required. */ diff --git a/source/blender/editors/transform/transform_mode_translate.c b/source/blender/editors/transform/transform_mode_translate.c index 67bdeb3fed0..04a41814b53 100644 --- a/source/blender/editors/transform/transform_mode_translate.c +++ b/source/blender/editors/transform/transform_mode_translate.c @@ -448,13 +448,7 @@ static bool clip_uv_transform_translation(TransInfo *t, float vec[2]) /* If tiled image then constrain to correct/closest UDIM tile, else 0-1 UV space. */ if (is_tiled_image) { - int nearest_tile_index = BKE_image_find_nearest_tile(image, t->center_global); - if (nearest_tile_index != -1) { - nearest_tile_index -= 1001; - /* Getting coordinates of nearest tile from the tile index. */ - base_offset[0] = nearest_tile_index % 10; - base_offset[1] = nearest_tile_index / 10; - } + BKE_image_find_nearest_tile_with_offset(image, t->center_global, base_offset); } float min[2], max[2]; diff --git a/source/blender/editors/uvedit/uvedit_islands.c b/source/blender/editors/uvedit/uvedit_islands.c index e1752ae5a29..9a31fd6469d 100644 --- a/source/blender/editors/uvedit/uvedit_islands.c +++ b/source/blender/editors/uvedit/uvedit_islands.c @@ -256,16 +256,12 @@ bool uv_coords_isect_udim(const Image *image, const int udim_grid[2], const floa * Calculates distance to nearest UDIM image tile in UV space and its UDIM tile number. */ static float uv_nearest_image_tile_distance(const Image *image, - float coords[2], + const float coords[2], float nearest_tile_co[2]) { - int nearest_image_tile_index = BKE_image_find_nearest_tile(image, coords); - if (nearest_image_tile_index == -1) { - nearest_image_tile_index = 1001; + if (BKE_image_find_nearest_tile_with_offset(image, coords, nearest_tile_co) == -1) { + zero_v2(nearest_tile_co); } - - nearest_tile_co[0] = (nearest_image_tile_index - 1001) % 10; - nearest_tile_co[1] = (nearest_image_tile_index - 1001) / 10; /* Add 0.5 to get tile center coordinates. */ float nearest_tile_center_co[2] = {nearest_tile_co[0], nearest_tile_co[1]}; add_v2_fl(nearest_tile_center_co, 0.5f); |