Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/transform/transform_convert.c
| Show All 31 Lines | |||||
| #include "BLI_listbase.h" | #include "BLI_listbase.h" | ||||
| #include "BLI_math.h" | #include "BLI_math.h" | ||||
| #include "BKE_action.h" | #include "BKE_action.h" | ||||
| #include "BKE_anim_data.h" | #include "BKE_anim_data.h" | ||||
| #include "BKE_context.h" | #include "BKE_context.h" | ||||
| #include "BKE_fcurve.h" | #include "BKE_fcurve.h" | ||||
| #include "BKE_global.h" | #include "BKE_global.h" | ||||
| #include "BKE_image.h" | |||||
| #include "BKE_layer.h" | #include "BKE_layer.h" | ||||
| #include "BKE_lib_id.h" | #include "BKE_lib_id.h" | ||||
| #include "BKE_main.h" | #include "BKE_main.h" | ||||
| #include "BKE_modifier.h" | #include "BKE_modifier.h" | ||||
| #include "BKE_nla.h" | #include "BKE_nla.h" | ||||
| #include "BKE_scene.h" | #include "BKE_scene.h" | ||||
| #include "ED_keyframes_edit.h" | #include "ED_keyframes_edit.h" | ||||
| ▲ Show 20 Lines • Show All 452 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); | |||||
| /* Stores the coordinates of the closest UDIM tile. Also acts as an offset to the tile from the | |||||
campbellbarton: Even though these are rounded, they can be floats as they're for the most part being used with… | |||||
| * origin of UV space */ | |||||
| float base_offset[2]; | |||||
| /* If tiled image then constrain to correct/closest UDIM tile, else 0-1 UV space */ | |||||
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… | |||||
| if (is_tiled_image) { | |||||
| float temp[2] = {t->center_global[0], t->center_global[1]}; | |||||
| int nearest_tile_index = BKE_image_find_nearest_tile(image, temp) - 1001; | |||||
Not Done Inline ActionsThe scope can be moved inside the loop. campbellbarton: The scope can be moved inside the loop. | |||||
campbellbartonUnsubmitted Not Done Inline Actionst->center_global can be passed in directly. campbellbarton: `t->center_global` can be passed in directly. | |||||
| /* Getting coordinates of nearest tile from the tile index */ | |||||
| base_offset[0] = nearest_tile_index % 10; | |||||
| base_offset[1] = nearest_tile_index / 10; | |||||
| } | |||||
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… | |||||
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… | |||||
| else { | |||||
| base_offset[0] = 0; | |||||
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.
| |||||
Not Done Inline ActionsAssigned the variable inside BKE_image_find_nearest_tile() sidd017: Assigned the variable inside `BKE_image_find_nearest_tile()` | |||||
| base_offset[1] = 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] < base_offset[0] && t->center_global[0] > base_offset[0] && | ||||
| vec[0] *= t->center_global[0] / (t->center_global[0] - min[0]); | t->center_global[0] < base_offset[0] + (t->aspect[0] * 0.5f)) { | ||||
| } | vec[0] *= (t->center_global[0] - base_offset[0]) / (t->center_global[0] - min[0]); | ||||
| else if (max[0] > t->aspect[0] && t->center_global[0] < t->aspect[0]) { | } | ||||
| vec[0] *= (t->center_global[0] - t->aspect[0]) / (t->center_global[0] - max[0]); | else if (max[0] > (base_offset[0] + t->aspect[0]) && | ||||
| t->center_global[0] < (base_offset[0] + t->aspect[0])) { | |||||
| vec[0] *= (t->center_global[0] - (base_offset[0] + 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] < base_offset[1] && t->center_global[1] > base_offset[1] && | ||||
| vec[1] *= t->center_global[1] / (t->center_global[1] - min[1]); | t->center_global[1] < base_offset[1] + (t->aspect[1] * 0.5f)) { | ||||
| } | vec[1] *= (t->center_global[1] - base_offset[1]) / (t->center_global[1] - min[1]); | ||||
| else if (max[1] > t->aspect[1] && t->center_global[1] < t->aspect[1]) { | } | ||||
| vec[1] *= (t->center_global[1] - t->aspect[1]) / (t->center_global[1] - max[1]); | else if (max[1] > (base_offset[1] + t->aspect[1]) && | ||||
| t->center_global[1] < (base_offset[1] + t->aspect[1])) { | |||||
| vec[1] *= (t->center_global[1] - (base_offset[1] + 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] < base_offset[0]) { | ||||
| vec[0] -= min[0]; | vec[0] += base_offset[0] - min[0]; | ||||
| } | } | ||||
| else if (max[0] > t->aspect[0]) { | else if (max[0] > base_offset[0] + t->aspect[0]) { | ||||
| vec[0] -= max[0] - t->aspect[0]; | vec[0] -= max[0] - base_offset[0] - t->aspect[0]; | ||||
| } | } | ||||
| else { | else { | ||||
| clipx = 0; | clipx = 0; | ||||
| } | } | ||||
| if (min[1] < 0.0f) { | if (min[1] < base_offset[1]) { | ||||
| vec[1] -= min[1]; | vec[1] += base_offset[1] - min[1]; | ||||
| } | } | ||||
| else if (max[1] > t->aspect[1]) { | else if (max[1] > base_offset[1] + t->aspect[1]) { | ||||
| vec[1] -= max[1] - t->aspect[1]; | vec[1] -= max[1] - base_offset[1] - 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.