Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/transform/transform_convert.c
| Show First 20 Lines • Show All 499 Lines • ▼ Show 20 Lines | |||||
| /** \name UV Coordinates | /** \name UV Coordinates | ||||
| * \{ */ | * \{ */ | ||||
| bool clipUVTransform(TransInfo *t, float vec[2], const bool resize) | bool clipUVTransform(TransInfo *t, float vec[2], const bool resize) | ||||
| { | { | ||||
| bool clipx = true, clipy = true; | bool clipx = true, clipy = true; | ||||
| float min[2], max[2]; | float min[2], max[2]; | ||||
| min[0] = min[1] = 0.0f; | /* Check if the current image in UV editor is a tiled image or not */ | ||||
| max[0] = t->aspect[0]; | SpaceImage *sima = t->area->spacedata.first; | ||||
| max[1] = t->aspect[1]; | Image *image = sima->image; | ||||
| bool is_tiled_image = image && (image->source == IMA_SRC_TILED); | |||||
| uint basex, basey; | |||||
campbellbarton: Even though these are rounded, they can be floats as they're for the most part being used with… | |||||
| /* If tiled image then constrain to correct/closest UDIM tile, else 0-1 UV space */ | |||||
| if (is_tiled_image) { | |||||
| /* Distance to the closest UDIM tile */ | |||||
campbellbartonUnsubmitted Not Done Inline ActionsThis can be moved into an image utility function that looks up the closest tile, so any other code that needs to do this can re-use it. e.g. /** Return the tile index. */
int BKE_image_find_nearest_tile(Image *image, co[2])
{
..
}campbellbarton: This can be moved into an image utility function that looks up the closest tile, so any other… | |||||
| float closest_distance = FLT_MAX; | |||||
| float distance = 0; | |||||
| int tile_index; | |||||
campbellbartonUnsubmitted Not Done Inline ActionsThe scope can be moved inside the loop. campbellbarton: The scope can be moved inside the loop. | |||||
Not Done Inline Actionst->center_global can be passed in directly. campbellbarton: `t->center_global` can be passed in directly. | |||||
| LISTBASE_FOREACH (ImageTile *, tile, &image->tiles) { | |||||
| tile_index = tile->tile_number - 1001; | |||||
| /* Distance between UV and UDIM tile */ | |||||
| distance = sqrtf(square_f((tile_index % 10) - t->center_global[0]) + | |||||
campbellbartonUnsubmitted Not Done Inline ActionsFor comparing distances there is no need for sqrt, this can be dist_sq (common convention for naming distance squared). campbellbarton: For comparing distances there is no need for `sqrt`, this can be `dist_sq` (common convention… | |||||
sidd017AuthorUnsubmitted Not Done Inline ActionsWasn't sure about the convention so I did a quick search on the code-base and used a few instances where dist_sq is declared as reference. sidd017: Wasn't sure about the convention so I did a quick search on the code-base and used a few… | |||||
| square_f((tile_index / 10) - t->center_global[1])); | |||||
campbellbartonUnsubmitted Not Done Inline Actionstile_index % 10, tile_index / 10 can be assigned to variables a they're accessed twice. campbellbarton: `tile_index % 10`, `tile_index / 10` can be assigned to variables a they're accessed twice.
| |||||
sidd017AuthorUnsubmitted Not Done Inline ActionsAssigned the variable inside BKE_image_find_nearest_tile() sidd017: Assigned the variable inside `BKE_image_find_nearest_tile()` | |||||
| if (floor(t->center_global[0]) == tile_index % 10 && | |||||
| floor(t->center_global[1]) == tile_index / 10) { | |||||
| basex = floor(t->center_global[0]); | |||||
| basey = floor(t->center_global[1]); | |||||
| break; | |||||
| } | |||||
| else if (distance < closest_distance) { | |||||
| closest_distance = distance; | |||||
| basex = tile_index % 10; | |||||
| basey = tile_index / 10; | |||||
| } | |||||
| } | |||||
| } | |||||
| else { | |||||
| basex = 0; | |||||
| basey = 0; | |||||
| } | |||||
| min[0] = min[1] = FLT_MAX; | |||||
| max[0] = max[1] = FLT_MIN; | |||||
| FOREACH_TRANS_DATA_CONTAINER (t, tc) { | FOREACH_TRANS_DATA_CONTAINER (t, tc) { | ||||
| TransData *td; | TransData *td; | ||||
| int a; | int a; | ||||
| for (a = 0, td = tc->data; a < tc->data_len; a++, td++) { | for (a = 0, td = tc->data; a < tc->data_len; a++, td++) { | ||||
| minmax_v2v2_v2(min, max, td->loc); | minmax_v2v2_v2(min, max, td->loc); | ||||
| } | } | ||||
| } | } | ||||
| if (resize) { | if (resize) { | ||||
| if (min[0] < 0.0f && t->center_global[0] > 0.0f && t->center_global[0] < t->aspect[0] * 0.5f) { | if (min[0] < basex && t->center_global[0] > basex && | ||||
| vec[0] *= t->center_global[0] / (t->center_global[0] - min[0]); | t->center_global[0] < basex + (t->aspect[0] * 0.5f)) { | ||||
| vec[0] *= (t->center_global[0] - basex) / (t->center_global[0] - min[0]); | |||||
| } | } | ||||
| else if (max[0] > t->aspect[0] && t->center_global[0] < t->aspect[0]) { | else if (max[0] > (basex + t->aspect[0]) && t->center_global[0] < (basex + t->aspect[0])) { | ||||
| vec[0] *= (t->center_global[0] - t->aspect[0]) / (t->center_global[0] - max[0]); | vec[0] *= (t->center_global[0] - (basex + t->aspect[0])) / (t->center_global[0] - max[0]); | ||||
| } | } | ||||
| else { | else { | ||||
| clipx = 0; | clipx = 0; | ||||
| } | } | ||||
| if (min[1] < 0.0f && t->center_global[1] > 0.0f && t->center_global[1] < t->aspect[1] * 0.5f) { | if (min[1] < basey && t->center_global[1] > basey && | ||||
| vec[1] *= t->center_global[1] / (t->center_global[1] - min[1]); | t->center_global[1] < basey + (t->aspect[1] * 0.5f)) { | ||||
| vec[1] *= (t->center_global[1] - basey) / (t->center_global[1] - min[1]); | |||||
| } | } | ||||
| else if (max[1] > t->aspect[1] && t->center_global[1] < t->aspect[1]) { | else if (max[1] > (basey + t->aspect[1]) && t->center_global[1] < (basey + t->aspect[1])) { | ||||
| vec[1] *= (t->center_global[1] - t->aspect[1]) / (t->center_global[1] - max[1]); | vec[1] *= (t->center_global[1] - (basey + t->aspect[1])) / (t->center_global[1] - max[1]); | ||||
| } | } | ||||
| else { | else { | ||||
| clipy = 0; | clipy = 0; | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| if (min[0] < 0.0f) { | if (min[0] < basex) { | ||||
| vec[0] -= min[0]; | vec[0] += basex - min[0]; | ||||
| } | } | ||||
| else if (max[0] > t->aspect[0]) { | else if (max[0] > basex + t->aspect[0]) { | ||||
| vec[0] -= max[0] - t->aspect[0]; | vec[0] -= max[0] - basex - t->aspect[0]; | ||||
| } | } | ||||
| else { | else { | ||||
| clipx = 0; | clipx = 0; | ||||
| } | } | ||||
| if (min[1] < 0.0f) { | if (min[1] < basey) { | ||||
| vec[1] -= min[1]; | vec[1] += basey - min[1]; | ||||
| } | } | ||||
| else if (max[1] > t->aspect[1]) { | else if (max[1] > basey + t->aspect[1]) { | ||||
| vec[1] -= max[1] - t->aspect[1]; | vec[1] -= max[1] - basey - t->aspect[1]; | ||||
| } | } | ||||
| else { | else { | ||||
| clipy = 0; | clipy = 0; | ||||
| } | } | ||||
| } | } | ||||
| return (clipx || clipy); | return (clipx || clipy); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 992 Lines • Show Last 20 Lines | |||||
Even though these are rounded, they can be floats as they're for the most part being used with other floats.
I'd also prefer float base_offset[2], with a comment explaining what this does exactly.