Cleanup: Simplify NULL handling for BKE_image_find_nearest_tile

Differential Revision: https://developer.blender.org/D15616
This commit is contained in:
Chris Blackbourn 2022-08-06 09:52:23 +12:00
parent 476de3b463
commit 0d62e963b0
Notes: blender-bot 2023-02-14 08:10:10 +01:00
Referenced by commit 4a11c0aabb, Fix regression: crash with uv constrain to bounds without image
4 changed files with 8 additions and 20 deletions

View File

@ -420,9 +420,9 @@ void BKE_image_get_tile_uv(const struct Image *ima, const int tile_number, float
*/
int BKE_image_find_nearest_tile_with_offset(const struct Image *image,
const float co[2],
float r_uv_offset[2]) ATTR_NONNULL(1, 2, 3);
float r_uv_offset[2]) ATTR_NONNULL(2, 3);
int BKE_image_find_nearest_tile(const struct Image *image, const float co[2])
ATTR_NONNULL(1, 2) ATTR_WARN_UNUSED_RESULT;
ATTR_NONNULL(2) ATTR_WARN_UNUSED_RESULT;
void BKE_image_get_size(struct Image *image, struct ImageUser *iuser, int *r_width, int *r_height);
void BKE_image_get_size_fl(struct Image *image, struct ImageUser *iuser, float r_size[2]);

View File

@ -126,19 +126,14 @@ static void constrain_scale_to_boundary(const float numerator,
static bool clip_uv_transform_resize(TransInfo *t, float vec[2])
{
/* Check if the current image in UV editor is a tiled image or not. */
const SpaceImage *sima = t->area->spacedata.first;
const Image *image = sima->image;
const bool is_tiled_image = image && (image->source == IMA_SRC_TILED);
/* Stores the coordinates of the closest UDIM tile.
* Also acts as an offset to the tile from the origin of UV space. */
float base_offset[2] = {0.0f, 0.0f};
/* If tiled image then constrain to correct/closest UDIM tile, else 0-1 UV space. */
if (is_tiled_image) {
BKE_image_find_nearest_tile_with_offset(image, t->center_global, base_offset);
}
const SpaceImage *sima = t->area->spacedata.first;
BKE_image_find_nearest_tile_with_offset(sima->image, t->center_global, base_offset);
/* Assume no change is required. */
float scale = 1.0f;

View File

@ -437,19 +437,13 @@ static void applyTranslationValue(TransInfo *t, const float vec[3])
static bool clip_uv_transform_translation(TransInfo *t, float vec[2])
{
/* Check if the current image in UV editor is a tiled image or not. */
const SpaceImage *sima = t->area->spacedata.first;
const Image *image = sima->image;
const bool is_tiled_image = image && (image->source == IMA_SRC_TILED);
/* Stores the coordinates of the closest UDIM tile.
* Also acts as an offset to the tile from the origin of UV space. */
float base_offset[2] = {0.0f, 0.0f};
/* If tiled image then constrain to correct/closest UDIM tile, else 0-1 UV space. */
if (is_tiled_image) {
BKE_image_find_nearest_tile_with_offset(image, t->center_global, base_offset);
}
const SpaceImage *sima = t->area->spacedata.first;
BKE_image_find_nearest_tile_with_offset(sima->image, t->center_global, base_offset);
float min[2], max[2];
min[0] = min[1] = FLT_MAX;

View File

@ -259,9 +259,8 @@ static float uv_nearest_image_tile_distance(const Image *image,
const float coords[2],
float nearest_tile_co[2])
{
if (BKE_image_find_nearest_tile_with_offset(image, coords, nearest_tile_co) == -1) {
zero_v2(nearest_tile_co);
}
BKE_image_find_nearest_tile_with_offset(image, coords, nearest_tile_co);
/* 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);