code cleanup: rename transform Slide operations to EdgeSlide.
[blender.git] / source / blender / editors / transform / transform.c
index 68cc1c8e9b653f3ee64308712ec1d7ce94ff166a..7cc6006970c8302e2a5ce5a6d3abd90fb72703e2 100644 (file)
 #include "DNA_movieclip_types.h"
 #include "DNA_scene_types.h"  /* PET modes */
 
-#include "RNA_access.h"
-
-#include "BIF_gl.h"
-#include "BIF_glutil.h"
+#include "BLI_utildefines.h"
+#include "BLI_math.h"
+#include "BLI_rect.h"
+#include "BLI_listbase.h"
+#include "BLI_string.h"
+#include "BLI_ghash.h"
+#include "BLI_linklist.h"
+#include "BLI_smallhash.h"
 
 #include "BKE_nla.h"
 #include "BKE_bmesh.h"
 #include "BKE_particle.h"
 #include "BKE_pointcache.h"
 #include "BKE_unit.h"
+#include "BKE_mask.h"
+
+#include "BIF_gl.h"
+#include "BIF_glutil.h"
 
 #include "ED_image.h"
 #include "ED_keyframing.h"
 #include "ED_clip.h"
 #include "ED_mask.h"
 
-#include "UI_view2d.h"
 #include "WM_types.h"
 #include "WM_api.h"
 
-#include "BLI_math.h"
-#include "BLI_blenlib.h"
-#include "BLI_utildefines.h"
-#include "BLI_ghash.h"
-#include "BLI_linklist.h"
-#include "BLI_smallhash.h"
-#include "BLI_array.h"
-
+#include "UI_view2d.h"
+#include "UI_interface_icons.h"
 #include "UI_resources.h"
 
-#include "transform.h"
+#include "RNA_access.h"
 
-#include <stdio.h>
+#include "BLF_api.h"
+
+#include "transform.h"
 
 static void drawTransformApply(const struct bContext *C, ARegion *ar, void *arg);
 static int doEdgeSlide(TransInfo *t, float perc);
@@ -125,11 +128,11 @@ static void convertViewVec2D(View2D *v2d, float r_vec[3], int dx, int dy)
 {
        float divx, divy;
        
-       divx = BLI_RCT_SIZE_X(&v2d->mask);
-       divy = BLI_RCT_SIZE_Y(&v2d->mask);
+       divx = BLI_rcti_size_x(&v2d->mask);
+       divy = BLI_rcti_size_y(&v2d->mask);
 
-       r_vec[0] = BLI_RCT_SIZE_X(&v2d->cur) * dx / divx;
-       r_vec[1] = BLI_RCT_SIZE_Y(&v2d->cur) * dy / divy;
+       r_vec[0] = BLI_rctf_size_x(&v2d->cur) * dx / divx;
+       r_vec[1] = BLI_rctf_size_y(&v2d->cur) * dy / divy;
        r_vec[2] = 0.0f;
 }
 
@@ -138,11 +141,11 @@ static void convertViewVec2D_mask(View2D *v2d, float r_vec[3], int dx, int dy)
        float divx, divy;
        float mulx, muly;
 
-       divx = BLI_RCT_SIZE_X(&v2d->mask);
-       divy = BLI_RCT_SIZE_Y(&v2d->mask);
+       divx = BLI_rcti_size_x(&v2d->mask);
+       divy = BLI_rcti_size_y(&v2d->mask);
 
-       mulx = BLI_RCT_SIZE_X(&v2d->cur);
-       muly = BLI_RCT_SIZE_Y(&v2d->cur);
+       mulx = BLI_rctf_size_x(&v2d->cur);
+       muly = BLI_rctf_size_y(&v2d->cur);
 
        /* difference with convertViewVec2D */
        /* clamp w/h, mask only */
@@ -224,13 +227,35 @@ void convertViewVec(TransInfo *t, float r_vec[3], int dx, int dy)
 void projectIntView(TransInfo *t, const float vec[3], int adr[2])
 {
        if (t->spacetype == SPACE_VIEW3D) {
-               if (t->ar->regiontype == RGN_TYPE_WINDOW)
-                       project_int_noclip(t->ar, vec, adr);
+               if (t->ar->regiontype == RGN_TYPE_WINDOW) {
+                       if (ED_view3d_project_int_global(t->ar, vec, adr, V3D_PROJ_TEST_NOP) != V3D_PROJ_RET_OK) {
+                               adr[0] = (int)2140000000.0f;  /* this is what was done in 2.64, perhaps we can be smarter? */
+                               adr[1] = (int)2140000000.0f;
+                       }
+               }
        }
        else if (t->spacetype == SPACE_IMAGE) {
+               SpaceImage *sima = t->sa->spacedata.first;
+
                if (t->options & CTX_MASK) {
+                       /* not working quite right, TODO (see below too) */
+                       float aspx, aspy;
                        float v[2];
-                       ED_mask_point_pos__reverse(t->sa, t->ar, vec[0], vec[1], &v[0], &v[1]);
+
+                       ED_space_image_get_aspect(sima, &aspx, &aspy);
+
+                       copy_v2_v2(v, vec);
+
+                       v[0] = v[0] / aspx;
+                       v[1] = v[1] / aspy;
+
+                       BKE_mask_coord_to_image(sima->image, &sima->iuser, v, v);
+
+                       v[0] = v[0] / aspx;
+                       v[1] = v[1] / aspy;
+
+                       ED_image_point_pos__reverse(sima, t->ar, v, v);
+
                        adr[0] = v[0];
                        adr[1] = v[1];
                }
@@ -253,7 +278,7 @@ void projectIntView(TransInfo *t, const float vec[3], int adr[2])
                        //vec[0] = vec[0]/((t->scene->r.frs_sec / t->scene->r.frs_sec_base));
                        /* same as below */
                        UI_view2d_to_region_no_clip((View2D *)t->view, vec[0], vec[1], out, out + 1);
-               } 
+               }
                else
 #endif
                {
@@ -278,23 +303,44 @@ void projectIntView(TransInfo *t, const float vec[3], int adr[2])
                adr[1] = out[1];
        }
        else if (t->spacetype == SPACE_CLIP) {
-               float v[2];
-               float aspx = 1.0f, aspy = 1.0f;
+               SpaceClip *sc = t->sa->spacedata.first;
+
+               if (t->options & CTX_MASK) {
+                       /* not working quite right, TODO (see above too) */
+                       float aspx, aspy;
+                       float v[2];
 
-               copy_v2_v2(v, vec);
+                       ED_space_clip_get_aspect(sc, &aspx, &aspy);
 
-               if (t->options & CTX_MOVIECLIP) {
-                       ED_space_clip_get_aspect_dimension_aware(t->sa->spacedata.first, &aspx, &aspy);
-               }
-               else if (t->options & CTX_MASK) {
-                       /* MASKTODO - not working as expected */
-                       ED_space_clip_get_aspect(t->sa->spacedata.first, &aspx, &aspy);
+                       copy_v2_v2(v, vec);
+
+                       v[0] = v[0] / aspx;
+                       v[1] = v[1] / aspy;
+
+                       BKE_mask_coord_to_movieclip(sc->clip, &sc->user, v, v);
+
+                       v[0] = v[0] / aspx;
+                       v[1] = v[1] / aspy;
+
+                       ED_clip_point_stable_pos__reverse(sc, t->ar, v, v);
+
+                       adr[0] = v[0];
+                       adr[1] = v[1];
                }
+               else if (t->options & CTX_MOVIECLIP) {
+                       float v[2], aspx, aspy;
+
+                       copy_v2_v2(v, vec);
+                       ED_space_clip_get_aspect_dimension_aware(t->sa->spacedata.first, &aspx, &aspy);
 
-               v[0] /= aspx;
-               v[1] /= aspy;
+                       v[0] /= aspx;
+                       v[1] /= aspy;
 
-               UI_view2d_to_region_no_clip(t->view, v[0], v[1], adr, adr + 1);
+                       UI_view2d_to_region_no_clip(t->view, v[0], v[1], adr, adr + 1);
+               }
+               else {
+                       BLI_assert(0);
+               }
        }
        else if (t->spacetype == SPACE_NODE) {
                UI_view2d_to_region_no_clip((View2D *)t->view, vec[0], vec[1], adr, adr + 1);
@@ -307,7 +353,12 @@ void projectFloatView(TransInfo *t, const float vec[3], float adr[2])
                case SPACE_VIEW3D:
                {
                        if (t->ar->regiontype == RGN_TYPE_WINDOW) {
-                               project_float_noclip(t->ar, vec, adr);
+                               /* allow points behind the view [#33643] */
+                               if (ED_view3d_project_float_global(t->ar, vec, adr, V3D_PROJ_TEST_NOP) != V3D_PROJ_RET_OK) {
+                                       /* XXX, 2.64 and prior did this, weak! */
+                                       adr[0] = t->ar->winx / 2.0f;
+                                       adr[1] = t->ar->winy / 2.0f;
+                               }
                                return;
                        }
                        break;
@@ -412,7 +463,10 @@ static void viewRedrawForce(const bContext *C, TransInfo *t)
                        WM_event_add_notifier(C, NC_OBJECT | ND_POSE, NULL);
                else
                        WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL);
-               
+
+               if (t->mode == TFM_EDGE_SLIDE && (t->settings->uvcalc_flag & UVCALC_TRANSFORM_CORRECT))
+                       WM_event_add_notifier(C, NC_GEOM | ND_DATA, NULL);
+
                /* for realtime animation record - send notifiers recognised by animation editors */
                // XXX: is this notifier a lame duck?
                if ((t->animtimer) && IS_AUTOKEY_ON(t->scene))
@@ -420,11 +474,11 @@ static void viewRedrawForce(const bContext *C, TransInfo *t)
                
        }
        else if (t->spacetype == SPACE_ACTION) {
-               //SpaceAction *saction= (SpaceAction *)t->sa->spacedata.first;
+               //SpaceAction *saction = (SpaceAction *)t->sa->spacedata.first;
                WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL);
        }
        else if (t->spacetype == SPACE_IPO) {
-               //SpaceIpo *sipo= (SpaceIpo *)t->sa->spacedata.first;
+               //SpaceIpo *sipo = (SpaceIpo *)t->sa->spacedata.first;
                WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL);
        }
        else if (t->spacetype == SPACE_NLA) {
@@ -477,6 +531,10 @@ static void viewRedrawPost(bContext *C, TransInfo *t)
                /* if autokeying is enabled, send notifiers that keyframes were added */
                if (IS_AUTOKEY_ON(t->scene))
                        WM_main_add_notifier(NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL);
+
+               /* redraw UV editor */
+               if (t->mode == TFM_EDGE_SLIDE && (t->settings->uvcalc_flag & UVCALC_TRANSFORM_CORRECT))
+                       WM_event_add_notifier(C, NC_GEOM | ND_DATA, NULL);
                
                /* XXX temp, first hack to get auto-render in compositor work (ton) */
                WM_event_add_notifier(C, NC_SCENE | ND_TRANSFORM_DONE, CTX_data_scene(C));
@@ -632,6 +690,9 @@ static void view_editmove(unsigned short UNUSED(event))
 #define TFM_MODAL_EDGESLIDE_UP 24
 #define TFM_MODAL_EDGESLIDE_DOWN 25
 
+/* for analog input, like trackpad */
+#define TFM_MODAL_PROPSIZE             26
+
 /* called in transform_ops.c, on each regeneration of keymaps */
 wmKeyMap *transform_modal_keymap(wmKeyConfig *keyconf)
 {
@@ -661,6 +722,7 @@ wmKeyMap *transform_modal_keymap(wmKeyConfig *keyconf)
                {TFM_MODAL_AUTOIK_LEN_DEC, "AUTOIK_CHAIN_LEN_DOWN", 0, "Decrease Max AutoIK Chain Length", ""},
                {TFM_MODAL_EDGESLIDE_UP, "EDGESLIDE_EDGE_NEXT", 0, "Select next Edge Slide Edge", ""},
                {TFM_MODAL_EDGESLIDE_DOWN, "EDGESLIDE_PREV_NEXT", 0, "Select previous Edge Slide Edge", ""},
+               {TFM_MODAL_PROPSIZE, "PROPORTIONAL_SIZE", 0, "Adjust Proportional Influence", ""},
                {0, NULL, 0, NULL, NULL}
        };
        
@@ -696,6 +758,7 @@ wmKeyMap *transform_modal_keymap(wmKeyConfig *keyconf)
        WM_modalkeymap_add_item(keymap, PAGEDOWNKEY, KM_PRESS, 0, 0, TFM_MODAL_PROPSIZE_DOWN);
        WM_modalkeymap_add_item(keymap, WHEELDOWNMOUSE, KM_PRESS, 0, 0, TFM_MODAL_PROPSIZE_UP);
        WM_modalkeymap_add_item(keymap, WHEELUPMOUSE, KM_PRESS, 0, 0, TFM_MODAL_PROPSIZE_DOWN);
+       WM_modalkeymap_add_item(keymap, MOUSEPAN, 0, 0, 0, TFM_MODAL_PROPSIZE);
 
        WM_modalkeymap_add_item(keymap, WHEELDOWNMOUSE, KM_PRESS, KM_ALT, 0, TFM_MODAL_EDGESLIDE_UP);
        WM_modalkeymap_add_item(keymap, WHEELUPMOUSE, KM_PRESS, KM_ALT, 0, TFM_MODAL_EDGESLIDE_DOWN);
@@ -779,7 +842,7 @@ int transformEvent(TransInfo *t, wmEvent *event)
        float mati[3][3] = MAT3_UNITY;
        char cmode = constraintModeToChar(t);
        int handled = 1;
-
+       
        t->redraw |= handleMouseInput(t, &t->mouse, event);
 
        if (event->type == MOUSEMOVE) {
@@ -970,11 +1033,24 @@ int transformEvent(TransInfo *t, wmEvent *event)
                                removeSnapPoint(t);
                                t->redraw |= TREDRAW_HARD;
                                break;
+                               
+                       case TFM_MODAL_PROPSIZE:
+                               /* MOUSEPAN usage... */
+                               if (t->flag & T_PROP_EDIT) {
+                                       float fac = 1.0f + 0.005f *(event->y - event->prevy);
+                                       t->prop_size *= fac;
+                                       if (t->spacetype == SPACE_VIEW3D && t->persp != RV3D_ORTHO)
+                                               t->prop_size = min_ff(t->prop_size, ((View3D *)t->view)->far);
+                                       calculatePropRatio(t);
+                               }
+                               t->redraw |= TREDRAW_HARD;
+                               break;
+                               
                        case TFM_MODAL_PROPSIZE_UP:
                                if (t->flag & T_PROP_EDIT) {
                                        t->prop_size *= 1.1f;
                                        if (t->spacetype == SPACE_VIEW3D && t->persp != RV3D_ORTHO)
-                                               t->prop_size = minf(t->prop_size, ((View3D *)t->view)->far);
+                                               t->prop_size = min_ff(t->prop_size, ((View3D *)t->view)->far);
                                        calculatePropRatio(t);
                                }
                                t->redraw |= TREDRAW_HARD;
@@ -1144,7 +1220,7 @@ int transformEvent(TransInfo *t, wmEvent *event)
                                if (event->alt && t->flag & T_PROP_EDIT) {
                                        t->prop_size *= 1.1f;
                                        if (t->spacetype == SPACE_VIEW3D && t->persp != RV3D_ORTHO)
-                                               t->prop_size = minf(t->prop_size, ((View3D *)t->view)->far);
+                                               t->prop_size = min_ff(t->prop_size, ((View3D *)t->view)->far);
                                        calculatePropRatio(t);
                                }
                                t->redraw = 1;
@@ -1171,6 +1247,14 @@ int transformEvent(TransInfo *t, wmEvent *event)
                                }
                                else view_editmove(event->type);
                                t->redraw = 1;
+                               break;
+                       case LEFTALTKEY:
+                       case RIGHTALTKEY:
+                               if (ELEM(t->spacetype, SPACE_SEQ, SPACE_VIEW3D)) {
+                                       t->flag |= T_ALT_TRANSFORM;
+                                       t->redraw |= TREDRAW_HARD;
+                               }
+
                                break;
                        default:
                                handled = 0;
@@ -1205,6 +1289,14 @@ int transformEvent(TransInfo *t, wmEvent *event)
 ////                   if (t->options & CTX_TWEAK)
 //                             t->state = TRANS_CONFIRM;
 //                     break;
+                       case LEFTALTKEY:
+                       case RIGHTALTKEY:
+                               if (ELEM(t->spacetype, SPACE_SEQ, SPACE_VIEW3D)) {
+                                       t->flag &= ~T_ALT_TRANSFORM;
+                                       t->redraw |= TREDRAW_HARD;
+                               }
+
+                               break;
                        default:
                                handled = 0;
                                break;
@@ -1218,15 +1310,19 @@ int transformEvent(TransInfo *t, wmEvent *event)
                        }
                }
        }
+       else
+               handled = 0;
 
        // Per transform event, if present
        if (t->handleEvent)
                t->redraw |= t->handleEvent(t, event);
 
-       if (handled || t->redraw)
+       if (handled || t->redraw) {
                return 0;
-       else
+       }
+       else {
                return OPERATOR_PASS_THROUGH;
+       }
 }
 
 int calculateTransformCenter(bContext *C, int centerMode, float cent3d[3], int cent2d[2])
@@ -1426,7 +1522,6 @@ static void drawHelpline(bContext *UNUSED(C), int x, int y, void *customdata)
                                glTranslatef(mval[0], mval[1], 0);
 
                                glLineWidth(3.0);
-                               glBegin(GL_LINES);
                                drawArrow(UP, 5, 10, 5);
                                drawArrow(DOWN, 5, 10, 5);
                                glLineWidth(1.0);
@@ -1436,8 +1531,8 @@ static void drawHelpline(bContext *UNUSED(C), int x, int y, void *customdata)
                                float dx = t->mval[0] - cent[0], dy = t->mval[1] - cent[1];
                                float angle = atan2f(dy, dx);
                                float dist = sqrtf(dx * dx + dy * dy);
-                               float delta_angle = minf(15.0f / dist, (float)M_PI / 4.0f);
-                               float spacing_angle = minf(5.0f / dist, (float)M_PI / 12.0f);
+                               float delta_angle = min_ff(15.0f / dist, (float)M_PI / 4.0f);
+                               float spacing_angle = min_ff(5.0f / dist, (float)M_PI / 12.0f);
                                UI_ThemeColor(TH_WIRE);
 
                                setlinestyle(3);
@@ -1509,14 +1604,58 @@ static void drawTransformView(const struct bContext *C, ARegion *UNUSED(ar), voi
        drawNonPropEdge(C, t);
 }
 
-#if 0
-static void drawTransformPixel(const struct bContext *UNUSED(C), ARegion *UNUSED(ar), void *UNUSED(arg))
+/* just draw a little warning message in the top-right corner of the viewport to warn that autokeying is enabled */
+static void drawAutoKeyWarning(TransInfo *UNUSED(t), ARegion *ar)
 {
-//     TransInfo *t = arg;
-//
-//     drawHelpline(C, t->mval[0], t->mval[1], t);
+       rcti rect;
+       const char printable[] = "Auto Keying On";
+       float      printable_size[2];
+       int xco, yco;
+
+       ED_region_visible_rect(ar, &rect);
+       
+       BLF_width_and_height_default(printable, &printable_size[0], &printable_size[1]);
+       
+       xco = rect.xmax - (int)printable_size[0] - 10;
+       yco = rect.ymax - (int)printable_size[1] - 10;
+       
+       /* warning text (to clarify meaning of overlays)
+        * - original color was red to match the icon, but that clashes badly with a less nasty border
+        */
+       UI_ThemeColorShade(TH_TEXT_HI, -50);
+       BLF_draw_default_ascii(xco, ar->winy - 17, 0.0f, printable, sizeof(printable));
+       
+       /* autokey recording icon... */
+       glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+       glEnable(GL_BLEND);
+       
+       xco -= (ICON_DEFAULT_WIDTH + 2);
+       UI_icon_draw(xco, yco, ICON_REC);
+       
+       glDisable(GL_BLEND);
+}
+
+static void drawTransformPixel(const struct bContext *UNUSED(C), ARegion *ar, void *arg)
+{      
+       TransInfo *t = arg;
+       Scene *scene = t->scene;
+       Object *ob = OBACT;
+       
+       /* draw autokeyframing hint in the corner 
+        * - only draw if enabled (advanced users may be distracted/annoyed), 
+        *   for objects that will be autokeyframed (no point ohterwise),
+        *   AND only for the active region (as showing all is too overwhelming)
+        */
+       if ((U.autokey_flag & AUTOKEY_FLAG_NOWARNING) == 0) {
+               if (ar == t->ar) {
+                       if (t->flag & (T_OBJECT | T_POSE)) {
+                               if (ob && autokeyframe_cfra_can_key(scene, &ob->id)) {
+                                       drawAutoKeyWarning(t, ar);
+                               }
+                       }
+               }
+       }
 }
-#endif
 
 void saveTransform(bContext *C, TransInfo *t, wmOperator *op)
 {
@@ -1686,7 +1825,7 @@ int initTransform(bContext *C, TransInfo *t, wmOperator *op, wmEvent *event, int
 
                t->draw_handle_apply = ED_region_draw_cb_activate(t->ar->type, drawTransformApply, t, REGION_DRAW_PRE_VIEW);
                t->draw_handle_view = ED_region_draw_cb_activate(t->ar->type, drawTransformView, t, REGION_DRAW_POST_VIEW);
-               //t->draw_handle_pixel = ED_region_draw_cb_activate(t->ar->type, drawTransformPixel, t, REGION_DRAW_POST_PIXEL);
+               t->draw_handle_pixel = ED_region_draw_cb_activate(t->ar->type, drawTransformPixel, t, REGION_DRAW_POST_PIXEL);
                t->draw_handle_cursor = WM_paint_cursor_activate(CTX_wm_manager(C), helpline_poll, drawHelpline, t);
        }
        else if (t->spacetype == SPACE_IMAGE) {
@@ -2140,8 +2279,8 @@ static void protectedQuaternionBits(short protectflag, float *quat, float *oldqu
 static void constraintTransLim(TransInfo *t, TransData *td)
 {
        if (td->con) {
-               bConstraintTypeInfo *ctiLoc = get_constraint_typeinfo(CONSTRAINT_TYPE_LOCLIMIT);
-               bConstraintTypeInfo *ctiDist = get_constraint_typeinfo(CONSTRAINT_TYPE_DISTLIMIT);
+               bConstraintTypeInfo *ctiLoc = BKE_get_constraint_typeinfo(CONSTRAINT_TYPE_LOCLIMIT);
+               bConstraintTypeInfo *ctiDist = BKE_get_constraint_typeinfo(CONSTRAINT_TYPE_DISTLIMIT);
                
                bConstraintOb cob = {NULL};
                bConstraint *con;
@@ -2158,7 +2297,6 @@ static void constraintTransLim(TransInfo *t, TransData *td)
                for (con = td->con; con; con = con->next) {
                        bConstraintTypeInfo *cti = NULL;
                        ListBase targets = {NULL, NULL};
-                       float tmat[4][4];
                        
                        /* only consider constraint if enabled */
                        if (con->flag & CONSTRAINT_DISABLE) continue;
@@ -2184,8 +2322,7 @@ static void constraintTransLim(TransInfo *t, TransData *td)
                                /* do space conversions */
                                if (con->ownspace == CONSTRAINT_SPACE_WORLD) {
                                        /* just multiply by td->mtx (this should be ok) */
-                                       copy_m4_m4(tmat, cob.matrix);
-                                       mul_m4_m3m4(cob.matrix, td->mtx, tmat);
+                                       mul_m4_m3m4(cob.matrix, td->mtx, cob.matrix);
                                }
                                else if (con->ownspace != CONSTRAINT_SPACE_LOCAL) {
                                        /* skip... incompatable spacetype */
@@ -2193,16 +2330,15 @@ static void constraintTransLim(TransInfo *t, TransData *td)
                                }
                                
                                /* get constraint targets if needed */
-                               get_constraint_targets_for_solving(con, &cob, &targets, ctime);
+                               BKE_get_constraint_targets_for_solving(con, &cob, &targets, ctime);
                                
                                /* do constraint */
                                cti->evaluate_constraint(con, &cob, &targets);
                                
                                /* convert spaces again */
                                if (con->ownspace == CONSTRAINT_SPACE_WORLD) {
-                                       /* just multiply by td->mtx (this should be ok) */
-                                       copy_m4_m4(tmat, cob.matrix);
-                                       mul_m4_m3m4(cob.matrix, td->smtx, tmat);
+                                       /* just multiply by td->smtx (this should be ok) */
+                                       mul_m4_m3m4(cob.matrix, td->smtx, cob.matrix);
                                }
                                
                                /* free targets list */
@@ -2246,22 +2382,21 @@ static void constraintob_from_transdata(bConstraintOb *cob, TransData *td)
 static void constraintRotLim(TransInfo *UNUSED(t), TransData *td)
 {
        if (td->con) {
-               bConstraintTypeInfo *cti = get_constraint_typeinfo(CONSTRAINT_TYPE_ROTLIMIT);
+               bConstraintTypeInfo *cti = BKE_get_constraint_typeinfo(CONSTRAINT_TYPE_ROTLIMIT);
                bConstraintOb cob;
                bConstraint *con;
                int do_limit = FALSE;
-               
+
                /* Evaluate valid constraints */
                for (con = td->con; con; con = con->next) {
                        /* only consider constraint if enabled */
                        if (con->flag & CONSTRAINT_DISABLE) continue;
                        if (con->enforce == 0.0f) continue;
-                       
+
                        /* we're only interested in Limit-Rotation constraints */
                        if (con->type == CONSTRAINT_TYPE_ROTLIMIT) {
                                bRotLimitConstraint *data = con->data;
-                               float tmat[4][4];
-                               
+
                                /* only use it if it's tagged for this purpose */
                                if ((data->flag2 & LIMIT_TRANSFORM) == 0)
                                        continue;
@@ -2275,12 +2410,11 @@ static void constraintRotLim(TransInfo *UNUSED(t), TransData *td)
                                        constraintob_from_transdata(&cob, td);
                                        do_limit = TRUE;
                                }
-                               
+
                                /* do space conversions */
                                if (con->ownspace == CONSTRAINT_SPACE_WORLD) {
                                        /* just multiply by td->mtx (this should be ok) */
-                                       copy_m4_m4(tmat, cob.matrix);
-                                       mul_m4_m3m4(cob.matrix, td->mtx, tmat);
+                                       mul_m4_m3m4(cob.matrix, td->mtx, cob.matrix);
                                }
                                
                                /* do constraint */
@@ -2288,9 +2422,8 @@ static void constraintRotLim(TransInfo *UNUSED(t), TransData *td)
                                
                                /* convert spaces again */
                                if (con->ownspace == CONSTRAINT_SPACE_WORLD) {
-                                       /* just multiply by td->mtx (this should be ok) */
-                                       copy_m4_m4(tmat, cob.matrix);
-                                       mul_m4_m3m4(cob.matrix, td->smtx, tmat);
+                                       /* just multiply by td->smtx (this should be ok) */
+                                       mul_m4_m3m4(cob.matrix, td->smtx, cob.matrix);
                                }
                        }
                }
@@ -2316,9 +2449,11 @@ static void constraintRotLim(TransInfo *UNUSED(t), TransData *td)
 static void constraintSizeLim(TransInfo *t, TransData *td)
 {
        if (td->con && td->ext) {
-               bConstraintTypeInfo *cti = get_constraint_typeinfo(CONSTRAINT_TYPE_SIZELIMIT);
+               bConstraintTypeInfo *cti = BKE_get_constraint_typeinfo(CONSTRAINT_TYPE_SIZELIMIT);
                bConstraintOb cob = {NULL};
                bConstraint *con;
+               float size_sign[3], size_abs[3];
+               int i;
                
                /* Make a temporary bConstraintOb for using these limit constraints
                 *  - they only care that cob->matrix is correctly set ;-)
@@ -2332,8 +2467,14 @@ static void constraintSizeLim(TransInfo *t, TransData *td)
                        /* Reset val if SINGLESIZE but using a constraint */
                        if (td->flag & TD_SINGLESIZE)
                                return;
+
+                       /* separate out sign to apply back later */
+                       for (i = 0; i < 3; i++) {
+                               size_sign[i] = signf(td->ext->size[i]);
+                               size_abs[i] = fabsf(td->ext->size[i]);
+                       }
                        
-                       size_to_mat4(cob.matrix, td->ext->size);
+                       size_to_mat4(cob.matrix, size_abs);
                }
                
                /* Evaluate valid constraints */
@@ -2345,7 +2486,6 @@ static void constraintSizeLim(TransInfo *t, TransData *td)
                        /* we're only interested in Limit-Scale constraints */
                        if (con->type == CONSTRAINT_TYPE_SIZELIMIT) {
                                bSizeLimitConstraint *data = con->data;
-                               float tmat[4][4];
                                
                                /* only use it if it's tagged for this purpose */
                                if ((data->flag2 & LIMIT_TRANSFORM) == 0)
@@ -2354,11 +2494,10 @@ static void constraintSizeLim(TransInfo *t, TransData *td)
                                /* do space conversions */
                                if (con->ownspace == CONSTRAINT_SPACE_WORLD) {
                                        /* just multiply by td->mtx (this should be ok) */
-                                       copy_m4_m4(tmat, cob.matrix);
-                                       mul_m4_m3m4(cob.matrix, td->mtx, tmat);
+                                       mul_m4_m3m4(cob.matrix, td->mtx, cob.matrix);
                                }
                                else if (con->ownspace != CONSTRAINT_SPACE_LOCAL) {
-                                       /* skip... incompatable spacetype */
+                                       /* skip... incompatible spacetype */
                                        continue;
                                }
                                
@@ -2367,13 +2506,12 @@ static void constraintSizeLim(TransInfo *t, TransData *td)
                                
                                /* convert spaces again */
                                if (con->ownspace == CONSTRAINT_SPACE_WORLD) {
-                                       /* just multiply by td->mtx (this should be ok) */
-                                       copy_m4_m4(tmat, cob.matrix);
-                                       mul_m4_m3m4(cob.matrix, td->smtx, tmat);
+                                       /* just multiply by td->smtx (this should be ok) */
+                                       mul_m4_m3m4(cob.matrix, td->smtx, cob.matrix);
                                }
                        }
                }
-               
+
                /* copy results from cob->matrix */
                if ((td->flag & TD_SINGLESIZE) && !(t->con.mode & CON_APPLY)) {
                        /* scale val and reset size */
@@ -2383,8 +2521,10 @@ static void constraintSizeLim(TransInfo *t, TransData *td)
                        /* Reset val if SINGLESIZE but using a constraint */
                        if (td->flag & TD_SINGLESIZE)
                                return;
-                       
+
+                       /* extrace scale from matrix and apply back sign */
                        mat4_to_size(td->ext->size, cob.matrix);
+                       mul_v3_v3(td->ext->size, size_sign);
                }
        }
 }
@@ -2464,7 +2604,8 @@ int handleEventWarp(TransInfo *t, wmEvent *event)
 int Warp(TransInfo *t, const int UNUSED(mval[2]))
 {
        TransData *td = t->data;
-       float vec[3], circumfac, dist, phi0, co, si, *curs, cursor[3], gcursor[3];
+       float vec[3], circumfac, dist, phi0, co, si, cursor[3], gcursor[3];
+       const float *curs;
        int i;
        char str[50];
        
@@ -2601,6 +2742,18 @@ int handleEventShear(TransInfo *t, wmEvent *event)
 
                status = 1;
        }
+       else if (event->type == XKEY && event->val == KM_PRESS) {
+               initMouseInputMode(t, &t->mouse, INPUT_HORIZONTAL_ABSOLUTE);
+               t->customData = NULL;
+               
+               status = 1;
+       }
+       else if (event->type == YKEY && event->val == KM_PRESS) {
+               initMouseInputMode(t, &t->mouse, INPUT_VERTICAL_ABSOLUTE);
+               t->customData = (void *)1;
+               
+               status = 1;
+       }
        
        return status;
 }
@@ -2634,7 +2787,7 @@ int Shear(TransInfo *t, const int UNUSED(mval[2]))
        }
        else {
                /* default header print */
-               sprintf(str, "Shear: %.3f %s", value, t->proptext);
+               sprintf(str, "Shear: %.3f %s (Press X or Y to set shear axis)", value, t->proptext);
        }
        
        t->values[0] = value;
@@ -2755,11 +2908,21 @@ static void headerResize(TransInfo *t, float vec[3], char *str)
        (void)spos;
 }
 
-#define SIGN(a)     (a<-FLT_EPSILON ? 1 : a>FLT_EPSILON ? 2 : 3)
-#define VECSIGNFLIP(a, b) ((SIGN(a[0]) & SIGN(b[0])) == 0 || (SIGN(a[1]) & SIGN(b[1])) == 0 || (SIGN(a[2]) & SIGN(b[2])) == 0)
+/* FLT_EPSILON is too small [#29633], 0.0000001f starts to flip */
+#define TX_FLIP_EPS 0.00001f
+BLI_INLINE int tx_sign(const float a)
+{
+       return (a < -TX_FLIP_EPS ? 1 : a > TX_FLIP_EPS ? 2 : 3);
+}
+BLI_INLINE int tx_vec_sign_flip(const float a[3], const float b[3])
+{
+       return ((tx_sign(a[0]) & tx_sign(b[0])) == 0 ||
+               (tx_sign(a[1]) & tx_sign(b[1])) == 0 ||
+               (tx_sign(a[2]) & tx_sign(b[2])) == 0);
+}
 
 /* smat is reference matrix, only scaled */
-static void TransMat3ToSize(float mat[][3], float smat[][3], float *size)
+static void TransMat3ToSize(float mat[3][3], float smat[3][3], float size[3])
 {
        float vec[3];
        
@@ -2771,9 +2934,9 @@ static void TransMat3ToSize(float mat[][3], float smat[][3], float *size)
        size[2] = normalize_v3(vec);
        
        /* first tried with dotproduct... but the sign flip is crucial */
-       if (VECSIGNFLIP(mat[0], smat[0]) ) size[0] = -size[0];
-       if (VECSIGNFLIP(mat[1], smat[1]) ) size[1] = -size[1];
-       if (VECSIGNFLIP(mat[2], smat[2]) ) size[2] = -size[2];
+       if (tx_vec_sign_flip(mat[0], smat[0]) ) size[0] = -size[0];
+       if (tx_vec_sign_flip(mat[1], smat[1]) ) size[1] = -size[1];
+       if (tx_vec_sign_flip(mat[2], smat[2]) ) size[2] = -size[2];
 }
 
 
@@ -2815,11 +2978,11 @@ static void ElementResize(TransInfo *t, TransData *td, float mat[3][3])
                
                if (t->flag & (T_OBJECT | T_TEXTURE | T_POSE)) {
                        float obsizemat[3][3];
-                       // Reorient the size mat to fit the oriented object.
+                       /* Reorient the size mat to fit the oriented object. */
                        mul_m3_m3m3(obsizemat, tmat, td->axismtx);
-                       //print_m3("obsizemat", obsizemat);
+                       /* print_m3("obsizemat", obsizemat); */
                        TransMat3ToSize(obsizemat, td->axismtx, fsize);
-                       //print_v3("fsize", fsize);
+                       /* print_v3("fsize", fsize); */
                }
                else {
                        mat3_to_size(fsize, tmat);
@@ -2827,7 +2990,7 @@ static void ElementResize(TransInfo *t, TransData *td, float mat[3][3])
                
                protectedSizeBits(td->protectflag, fsize);
                
-               if ((t->flag & T_V3D_ALIGN) == 0) {   // align mode doesn't resize objects itself
+               if ((t->flag & T_V3D_ALIGN) == 0) {   /* align mode doesn't resize objects itself */
                        if ((td->flag & TD_SINGLESIZE) && !(t->con.mode & CON_APPLY)) {
                                /* scale val and reset size */
                                *td->val = td->ival * (1 + (fsize[0] - 1) * td->factor);
@@ -3302,7 +3465,7 @@ static void ElementRotation(TransInfo *t, TransData *td, float mat[3][3], short
                                /* this function works on end result */
                                protectedAxisAngleBits(td->protectflag, td->ext->rotAxis, td->ext->rotAngle, td->ext->irotAxis, td->ext->irotAngle);
                        }
-                       else { 
+                       else {
                                float eulmat[3][3];
                                
                                mul_m3_m3m3(totmat, mat, td->ext->r_mtx);
@@ -3850,10 +4013,8 @@ void initShrinkFatten(TransInfo *t)
 }
 
 
-
 int ShrinkFatten(TransInfo *t, const int UNUSED(mval[2]))
 {
-       float vec[3];
        float distance;
        int i;
        char str[64];
@@ -3878,20 +4039,23 @@ int ShrinkFatten(TransInfo *t, const int UNUSED(mval[2]))
                sprintf(str, "Shrink/Fatten: %.4f %s", distance, t->proptext);
        }
 
-       t->values[0] = distance;
+       t->values[0] = -distance;
 
        for (i = 0; i < t->total; i++, td++) {
+               float tdistance;  /* temp dist */
                if (td->flag & TD_NOACTION)
                        break;
 
                if (td->flag & TD_SKIP)
                        continue;
 
-               copy_v3_v3(vec, td->axismtx[2]);
-               mul_v3_fl(vec, distance);
-               mul_v3_fl(vec, td->factor);
+               /* get the final offset */
+               tdistance = distance * td->factor;
+               if (td->ext && (t->flag & T_ALT_TRANSFORM)) {
+                       tdistance *= td->ext->isize[0];  /* shell factor */
+               }
 
-               add_v3_v3v3(td->loc, td->iloc, vec);
+               madd_v3_v3v3fl(td->loc, td->iloc, td->axismtx[2], tdistance);
        }
 
        recalcData(t);
@@ -3942,12 +4106,15 @@ int Tilt(TransInfo *t, const int UNUSED(mval[2]))
 
                outputNumInput(&(t->num), c);
 
-               sprintf(str, "Tilt: %s %s", &c[0], t->proptext);
+               sprintf(str, "Tilt: %s° %s", &c[0], t->proptext);
 
                final = DEG2RADF(final);
+
+               /* XXX For some reason, this seems needed for this op, else RNA prop is not updated... :/ */
+               t->values[0] = final;
        }
        else {
-               sprintf(str, "Tilt: %.2f %s", RAD2DEGF(final), t->proptext);
+               sprintf(str, "Tilt: %.2f° %s", RAD2DEGF(final), t->proptext);
        }
 
        for (i = 0; i < t->total; i++, td++) {
@@ -4063,9 +4230,9 @@ void initMaskShrinkFatten(TransInfo *t)
 
 int MaskShrinkFatten(TransInfo *t, const int UNUSED(mval[2]))
 {
-       TransData *td = t->data;
+       TransData *td;
        float ratio;
-       int i;
+       int i, initial_feather = FALSE;
        char str[50];
 
        ratio = t->values[0];
@@ -4079,13 +4246,30 @@ int MaskShrinkFatten(TransInfo *t, const int UNUSED(mval[2]))
                char c[NUM_STR_REP_LEN];
 
                outputNumInput(&(t->num), c);
-               sprintf(str, "Shrink/Fatten: %s", c);
+               sprintf(str, "Feather Shrink/Fatten: %s", c);
        }
        else {
-               sprintf(str, "Shrink/Fatten: %3f", ratio);
+               sprintf(str, "Feather Shrink/Fatten: %3f", ratio);
        }
 
-       for (i = 0; i < t->total; i++, td++) {
+       /* detect if no points have feather yet */
+       if (ratio > 1.0f) {
+               initial_feather = TRUE;
+
+               for (td = t->data, i = 0; i < t->total; i++, td++) {
+                       if (td->flag & TD_NOACTION)
+                               break;
+
+                       if (td->flag & TD_SKIP)
+                               continue;
+
+                       if (td->ival >= 0.001f)
+                               initial_feather = FALSE;
+               }
+       }
+
+       /* apply shrink/fatten */
+       for (td = t->data, i = 0; i < t->total; i++, td++) {
                if (td->flag & TD_NOACTION)
                        break;
 
@@ -4093,7 +4277,11 @@ int MaskShrinkFatten(TransInfo *t, const int UNUSED(mval[2]))
                        continue;
 
                if (td->val) {
-                       *td->val = td->ival * ratio;
+                       if (initial_feather)
+                               *td->val = td->ival + (ratio - 1.0f) * 0.01f;
+                       else
+                               *td->val = td->ival * ratio;
+
                        /* apply PET */
                        *td->val = (*td->val * td->factor) + ((1.0f - td->factor) * td->ival);
                        if (*td->val <= 0.0f) *td->val = 0.001f;
@@ -4684,8 +4872,7 @@ static BMLoop *get_next_loop(BMVert *v, BMLoop *l,
                                cross_v3_v3v3(a, f2, l->f->no);
                                mul_v3_fl(a, -1.0f);
 
-                               add_v3_v3(a, f3);
-                               mul_v3_fl(a, 0.5f);
+                               mid_v3_v3v3(a, a, f3);
                        }
                        
                        copy_v3_v3(vec, a);
@@ -4706,7 +4893,7 @@ static BMLoop *get_next_loop(BMVert *v, BMLoop *l,
                }
                
                l = l->radial_next;
-       } while (l != firstl); 
+       } while (l != firstl);
 
        if (i)
                mul_v3_fl(a, 1.0f / (float)i);
@@ -4716,9 +4903,9 @@ static BMLoop *get_next_loop(BMVert *v, BMLoop *l,
        return NULL;
 }
 
-static void calcNonProportionalEdgeSlide(TransInfo *t, SlideData *sld, const float mval[2])
+static void calcNonProportionalEdgeSlide(TransInfo *t, EdgeSlideData *sld, const float mval[2])
 {
-       TransDataSlideVert *sv = sld->sv;
+       TransDataEdgeSlideVert *sv = sld->sv;
 
        if (sld->totsv > 0) {
                int i = 0;
@@ -4727,22 +4914,18 @@ static void calcNonProportionalEdgeSlide(TransInfo *t, SlideData *sld, const flo
                float dist = 0;
                float min_dist = FLT_MAX;
 
-               float up_p[3];
-               float dw_p[3];
-
                for (i = 0; i < sld->totsv; i++, sv++) {
                        /* Set length */
-                       add_v3_v3v3(up_p, sv->origvert.co, sv->upvec);
-                       add_v3_v3v3(dw_p, sv->origvert.co, sv->downvec);
-                       sv->edge_len = len_v3v3(dw_p, up_p);
+                       sv->edge_len = len_v3v3(sv->upvec, sv->downvec);
 
                        mul_v3_m4v3(v_proj, t->obedit->obmat, sv->v->co);
-                       project_float_noclip(t->ar, v_proj, v_proj);
-
-                       dist = len_squared_v2v2(mval, v_proj);
-                       if (dist < min_dist) {
-                               min_dist = dist;
-                               sld->curr_sv_index = i;
+                       /* allow points behind the view [#33643] */
+                       if (ED_view3d_project_float_global(t->ar, v_proj, v_proj, V3D_PROJ_TEST_NOP) == V3D_PROJ_RET_OK) {
+                               dist = len_squared_v2v2(mval, v_proj);
+                               if (dist < min_dist) {
+                                       min_dist = dist;
+                                       sld->curr_sv_index = i;
+                               }
                        }
                }
        }
@@ -4751,19 +4934,17 @@ static void calcNonProportionalEdgeSlide(TransInfo *t, SlideData *sld, const flo
        }
 }
 
-static int createSlideVerts(TransInfo *t)
+static int createEdgeSlideVerts(TransInfo *t)
 {
-       Mesh *me = t->obedit->data;
-       BMEditMesh *em = me->edit_btmesh;
+       BMEditMesh *em = BMEdit_FromObject(t->obedit);
        BMesh *bm = em->bm;
-       BMIter iter, iter2;
+       BMIter iter;
        BMEdge *e, *e1;
        BMVert *v, *v2, *first;
-       BMLoop *l, *l1, *l2;
-       TransDataSlideVert *sv_array;
-       BMBVHTree *btree = BMBVH_NewBVH(em, BMBVH_RESPECT_HIDDEN, NULL, NULL);
+       TransDataEdgeSlideVert *sv_array;
+       BMBVHTree *btree;
        SmallHash table;
-       SlideData *sld = MEM_callocN(sizeof(*sld), "sld");
+       EdgeSlideData *sld = MEM_callocN(sizeof(*sld), "sld");
        View3D *v3d = NULL;
        RegionView3D *rv3d = NULL;
        ARegion *ar = t->ar;
@@ -4773,6 +4954,7 @@ static int createSlideVerts(TransInfo *t)
        float vec[3], vec2[3] /*, lastvec[3], size, dis=0.0, z */ /* UNUSED */;
        float dir[3], maxdist, (*loop_dir)[3], *loop_maxdist;
        int numsel, i, j, loop_nr, l_nr;
+       int use_btree_disp;
 
        if (t->spacetype == SPACE_VIEW3D) {
                /* background mode support */
@@ -4780,6 +4962,15 @@ static int createSlideVerts(TransInfo *t)
                rv3d = t->ar ? t->ar->regiondata : NULL;
        }
 
+       use_btree_disp = (v3d && t->obedit->dt > OB_WIRE && v3d->drawtype > OB_WIRE);
+
+       if (use_btree_disp) {
+               btree = BMBVH_NewBVH(em, BMBVH_RESPECT_HIDDEN, NULL, NULL);
+       }
+       else {
+               btree = NULL;
+       }
+
        sld->is_proportional = TRUE;
        sld->curr_sv_index = 0;
        sld->flipped_vtx = FALSE;
@@ -4799,6 +4990,7 @@ static int createSlideVerts(TransInfo *t)
        /*ensure valid selection*/
        BM_ITER_MESH (v, &iter, bm, BM_VERTS_OF_MESH) {
                if (BM_elem_flag_test(v, BM_ELEM_SELECT)) {
+                       BMIter iter2;
                        numsel = 0;
                        BM_ITER_ELEM (e, &iter2, v, BM_EDGES_OF_VERT) {
                                if (BM_elem_flag_test(e, BM_ELEM_SELECT)) {
@@ -4812,7 +5004,8 @@ static int createSlideVerts(TransInfo *t)
 
                        if (numsel == 0 || numsel > 2) {
                                MEM_freeN(sld);
-                               BMBVH_FreeBVH(btree);
+                               if (btree)
+                                       BMBVH_FreeBVH(btree);
                                return 0; /* invalid edge selection */
                        }
                }
@@ -4822,7 +5015,8 @@ static int createSlideVerts(TransInfo *t)
                if (BM_elem_flag_test(e, BM_ELEM_SELECT)) {
                        if (!BM_edge_is_manifold(e)) {
                                MEM_freeN(sld);
-                               BMBVH_FreeBVH(btree);
+                               if (btree)
+                                       BMBVH_FreeBVH(btree);
                                return 0; /* can only handle exactly 2 faces around each edge */
                        }
                }
@@ -4842,15 +5036,18 @@ static int createSlideVerts(TransInfo *t)
 
        if (!j) {
                MEM_freeN(sld);
-               BMBVH_FreeBVH(btree);
+               if (btree)
+                       BMBVH_FreeBVH(btree);
                return 0;
        }
 
-       sv_array = MEM_callocN(sizeof(TransDataSlideVert) * j, "sv_array");
+       sv_array = MEM_callocN(sizeof(TransDataEdgeSlideVert) * j, "sv_array");
        loop_nr = 0;
 
        j = 0;
        while (1) {
+               BMLoop *l, *l1, *l2;
+
                v = NULL;
                BM_ITER_MESH (v, &iter, bm, BM_VERTS_OF_MESH) {
                        if (BM_elem_flag_test(v, BM_ELEM_TAG))
@@ -4906,7 +5103,7 @@ static int createSlideVerts(TransInfo *t)
                /*iterate over the loop*/
                first = v;
                do {
-                       TransDataSlideVert *sv = sv_array + j;
+                       TransDataEdgeSlideVert *sv = sv_array + j;
 
                        sv->v = v;
                        sv->origvert = *v;
@@ -4984,7 +5181,7 @@ static int createSlideVerts(TransInfo *t)
                if (BM_elem_flag_test(e, BM_ELEM_SELECT)) {
                        BMIter iter2;
                        BMEdge *e2;
-                       float vec1[3], mval[2] = {t->mval[0], t->mval[1]}, d;
+                       float vec1[3], d;
 
                        /* search cross edges for visible edge to the mouse cursor,
                         * then use the shared vertex to calculate screen vector*/
@@ -4995,28 +5192,26 @@ static int createSlideVerts(TransInfo *t)
                                                continue;
 
                                        /* This test is only relevant if object is not wire-drawn! See [#32068]. */
-                                       if (v3d && t->obedit->dt > OB_WIRE && v3d->drawtype > OB_WIRE &&
-                                           !BMBVH_EdgeVisible(btree, e2, ar, v3d, t->obedit))
-                                       {
+                                       if (use_btree_disp && !BMBVH_EdgeVisible(btree, e2, ar, v3d, t->obedit)) {
                                                continue;
                                        }
 
                                        j = GET_INT_FROM_POINTER(BLI_smallhash_lookup(&table, (uintptr_t)v));
 
                                        if (sv_array[j].down) {
-                                               ED_view3d_project_float_v3(ar, sv_array[j].down->co, vec1, projectMat);
+                                               ED_view3d_project_float_v3_m4(ar, sv_array[j].down->co, vec1, projectMat);
                                        }
                                        else {
                                                add_v3_v3v3(vec1, v->co, sv_array[j].downvec);
-                                               ED_view3d_project_float_v3(ar, vec1, vec1, projectMat);
+                                               ED_view3d_project_float_v3_m4(ar, vec1, vec1, projectMat);
                                        }
                                        
                                        if (sv_array[j].up) {
-                                               ED_view3d_project_float_v3(ar, sv_array[j].up->co, vec2, projectMat);
+                                               ED_view3d_project_float_v3_m4(ar, sv_array[j].up->co, vec2, projectMat);
                                        }
                                        else {
                                                add_v3_v3v3(vec2, v->co, sv_array[j].upvec);
-                                               ED_view3d_project_float_v3(ar, vec2, vec2, projectMat);
+                                               ED_view3d_project_float_v3_m4(ar, vec2, vec2, projectMat);
                                        }
                                        
                                        /* global direction */
@@ -5071,7 +5266,7 @@ static int createSlideVerts(TransInfo *t)
                if (dot_v3v3(loop_dir[l_nr], dir) < 0.0f) {
                        swap_v3_v3(sv_array->upvec, sv_array->downvec);
                        SWAP(BMVert, sv_array->vup, sv_array->vdown);
-                       SWAP(BMVert*, sv_array->up, sv_array->down);
+                       SWAP(BMVert *, sv_array->up, sv_array->down);
                }
        }
 
@@ -5099,17 +5294,22 @@ static int createSlideVerts(TransInfo *t)
        t->customData = sld;
        
        BLI_smallhash_release(&table);
-       BMBVH_FreeBVH(btree);
+       if (btree) {
+               BMBVH_FreeBVH(btree);
+       }
        MEM_freeN(loop_dir);
        MEM_freeN(loop_maxdist);
-       
+
+       /* arrays are dirty from copying faces: EDBM_index_arrays_free */
+       EDBM_update_generic(em, FALSE, TRUE);
+
        return 1;
 }
 
-void projectSVData(TransInfo *t, int final)
+void projectEdgeSlideData(TransInfo *t, bool is_final)
 {
-       SlideData *sld = t->customData;
-       TransDataSlideVert *sv;
+       EdgeSlideData *sld = t->customData;
+       TransDataEdgeSlideVert *sv;
        BMEditMesh *em = sld->em;
        SmallHash visit;
        int i;
@@ -5228,7 +5428,7 @@ void projectSVData(TransInfo *t, int final)
                                        }
 
                                }
-                               
+
                                if (!affected)
                                        continue;
 
@@ -5236,7 +5436,7 @@ void projectSVData(TransInfo *t, int final)
                                 * and we do not want to mess up other shape keys */
                                BM_loop_interp_from_face(em->bm, l, f_copy_flip, FALSE, FALSE);
 
-                               if (final) {
+                               if (is_final) {
                                        BM_loop_interp_multires(em->bm, l, f_copy_flip);
                                        if (f_copy != f_copy_flip) {
                                                BM_loop_interp_multires(em->bm, l, f_copy);
@@ -5260,7 +5460,7 @@ void projectSVData(TransInfo *t, int final)
        BLI_smallhash_release(&visit);
 }
 
-void freeSlideTempFaces(SlideData *sld)
+void freeEdgeSlideTempFaces(EdgeSlideData *sld)
 {
        if (sld->origfaces_init) {
                SmallHashIter hiter;
@@ -5274,17 +5474,20 @@ void freeSlideTempFaces(SlideData *sld)
                BLI_smallhash_release(&sld->origfaces);
 
                sld->origfaces_init = FALSE;
+
+               /* arrays are dirty from removing faces: EDBM_index_arrays_free */
+               EDBM_update_generic(sld->em, FALSE, TRUE);
        }
 }
 
 
-void freeSlideVerts(TransInfo *t)
+void freeEdgeSlideVerts(TransInfo *t)
 {
-       SlideData *sld = t->customData;
+       EdgeSlideData *sld = t->customData;
        
 #if 0 /*BMESH_TODO*/
        if (me->drawflag & ME_DRAWEXTRA_EDGELEN) {
-               TransDataSlideVert *sv;
+               TransDataEdgeSlideVert *sv;
                LinkNode *look = sld->vertlist;
                GHash *vertgh = sld->vhash;
                while (look) {
@@ -5301,7 +5504,7 @@ void freeSlideVerts(TransInfo *t)
        if (!sld)
                return;
        
-       freeSlideTempFaces(sld);
+       freeEdgeSlideTempFaces(sld);
 
        bmesh_edit_end(sld->em->bm, BMO_OP_FLAG_UNTAN_MULTIRES);
 
@@ -5317,13 +5520,13 @@ void freeSlideVerts(TransInfo *t)
 
 void initEdgeSlide(TransInfo *t)
 {
-       SlideData *sld;
+       EdgeSlideData *sld;
 
        t->mode = TFM_EDGE_SLIDE;
        t->transform = EdgeSlide;
        t->handleEvent = handleEventEdgeSlide;
 
-       if (!createSlideVerts(t)) {
+       if (!createEdgeSlideVerts(t)) {
                t->state = TRANS_CANCEL;
                return;
        }
@@ -5333,7 +5536,7 @@ void initEdgeSlide(TransInfo *t)
        if (!sld)
                return;
 
-       t->customFree = freeSlideVerts;
+       t->customFree = freeEdgeSlideVerts;
 
        /* set custom point first if you want value to be initialized by init */
        setCustomPoints(t, &t->mouse, sld->end, sld->start);
@@ -5353,7 +5556,7 @@ void initEdgeSlide(TransInfo *t)
 int handleEventEdgeSlide(struct TransInfo *t, struct wmEvent *event)
 {
        if (t->mode == TFM_EDGE_SLIDE) {
-               SlideData *sld = t->customData;
+               EdgeSlideData *sld = t->customData;
 
                if (sld) {
                        switch (event->type) {
@@ -5363,7 +5566,8 @@ int handleEventEdgeSlide(struct TransInfo *t, struct wmEvent *event)
                                                return 1;
                                        }
                                        break;
-                               case FKEY: {
+                               case FKEY:
+                               {
                                        if (event->val == KM_PRESS) {
                                                if (sld->is_proportional == FALSE) {
                                                        sld->flipped_vtx = !sld->flipped_vtx;
@@ -5372,13 +5576,16 @@ int handleEventEdgeSlide(struct TransInfo *t, struct wmEvent *event)
                                        }
                                        break;
                                }
-                               case EVT_MODAL_MAP: {
+                               case EVT_MODAL_MAP:
+                               {
                                        switch (event->val) {
-                                               case TFM_MODAL_EDGESLIDE_DOWN: {
+                                               case TFM_MODAL_EDGESLIDE_DOWN:
+                                               {
                                                        sld->curr_sv_index = ((sld->curr_sv_index - 1) + sld->totsv) % sld->totsv;
                                                        break;
                                                }
-                                               case TFM_MODAL_EDGESLIDE_UP: {
+                                               case TFM_MODAL_EDGESLIDE_UP:
+                                               {
                                                        sld->curr_sv_index = (sld->curr_sv_index + 1) % sld->totsv;
                                                        break;
                                                }
@@ -5395,15 +5602,15 @@ int handleEventEdgeSlide(struct TransInfo *t, struct wmEvent *event)
 void drawNonPropEdge(const struct bContext *C, TransInfo *t)
 {
        if (t->mode == TFM_EDGE_SLIDE) {
-               SlideData *sld = (SlideData *)t->customData;
+               EdgeSlideData *sld = (EdgeSlideData *)t->customData;
                /* Non-Prop mode */
                if (sld && sld->is_proportional == FALSE) {
                        View3D *v3d = CTX_wm_view3d(C);
                        float marker[3];
                        float v1[3], v2[3];
                        float interp_v;
-                       TransDataSlideVert *curr_sv = &sld->sv[sld->curr_sv_index];
-                       const float ctrl_size = UI_GetThemeValuef(TH_FACEDOT_SIZE) + 1.5;
+                       TransDataEdgeSlideVert *curr_sv = &sld->sv[sld->curr_sv_index];
+                       const float ctrl_size = UI_GetThemeValuef(TH_FACEDOT_SIZE) + 1.5f;
                        const float guide_size = ctrl_size - 0.5f;
                        const float line_size = UI_GetThemeValuef(TH_OUTLINE_WIDTH) + 0.5f;
                        const int alpha_shade = -30;
@@ -5468,52 +5675,61 @@ void drawNonPropEdge(const struct bContext *C, TransInfo *t)
 
 static int doEdgeSlide(TransInfo *t, float perc)
 {
-       SlideData *sld = t->customData;
-       TransDataSlideVert *svlist = sld->sv, *sv;
-       float vec[3];
+       EdgeSlideData *sld = t->customData;
+       TransDataEdgeSlideVert *svlist = sld->sv, *sv;
        int i;
 
        sld->perc = perc;
-
        sv = svlist;
-       for (i = 0; i < sld->totsv; i++, sv++) {
-               if (sld->is_proportional == FALSE) {
-                       TransDataSlideVert *curr_sv = &sld->sv[sld->curr_sv_index];
-                       float cur_sel = curr_sv->edge_len;
-                       float cur_sv = sv->edge_len;
-                       float extd = 0.0f;
-                       float recip_cur_sv = 0.0f;
-
-                       if (cur_sel == 0.0f) cur_sel = 1.0f;
-                       if (cur_sv == 0.0f) cur_sv = 1.0f;
-
-                       recip_cur_sv = 1.0f / cur_sv;
 
-                       if (!sld->flipped_vtx) {
-                               extd = (cur_sv - cur_sel) * recip_cur_sv;
+       if (sld->is_proportional == TRUE) {
+               for (i = 0; i < sld->totsv; i++, sv++) {
+                       float vec[3];
+                       if (perc > 0.0f) {
+                               copy_v3_v3(vec, sv->upvec);
+                               mul_v3_fl(vec, perc);
+                               add_v3_v3v3(sv->v->co, sv->origvert.co, vec);
                        }
                        else {
-                               extd = (cur_sel - cur_sv) * recip_cur_sv;
+                               copy_v3_v3(vec, sv->downvec);
+                               mul_v3_fl(vec, -perc);
+                               add_v3_v3v3(sv->v->co, sv->origvert.co, vec);
                        }
-
-                       extd += (sld->perc * cur_sel) * recip_cur_sv;
-                       CLAMP(extd, -1.0f, 1.0f);
-                       perc = extd;
                }
+       }
+       else {
+               /**
+                * Implementation note, non proportional mode ignores the starting positions and uses only the
+                * up/down verts, this could be changed/improved so the distance is still met but the verts are moved along
+                * their original path (which may not be straight), however how it works now is OK and matches 2.4x - Campbell
+                *
+                * \note len_v3v3(curr_sv->upvec, curr_sv->downvec)
+                * is the same as the distance between the original vert locations, same goes for the lines below.
+                */
+               TransDataEdgeSlideVert *curr_sv = &sld->sv[sld->curr_sv_index];
+               const float curr_length_perc = curr_sv->edge_len * (((sld->flipped_vtx ? perc : -perc) + 1.0f) / 2.0f);
 
-               if (perc > 0.0f) {
-                       copy_v3_v3(vec, sv->upvec);
-                       mul_v3_fl(vec, perc);
-                       add_v3_v3v3(sv->v->co, sv->origvert.co, vec);
-               }
-               else {
-                       copy_v3_v3(vec, sv->downvec);
-                       mul_v3_fl(vec, -perc);
-                       add_v3_v3v3(sv->v->co, sv->origvert.co, vec);
+               float down_co[3];
+               float up_co[3];
+
+               for (i = 0; i < sld->totsv; i++, sv++) {
+                       if (sv->edge_len > FLT_EPSILON) {
+                               const float fac = min_ff(sv->edge_len, curr_length_perc) / sv->edge_len;
+
+                               add_v3_v3v3(up_co, sv->origvert.co, sv->upvec);
+                               add_v3_v3v3(down_co, sv->origvert.co, sv->downvec);
+
+                               if (sld->flipped_vtx) {
+                                       interp_v3_v3v3(sv->v->co, down_co, up_co, fac);
+                               }
+                               else {
+                                       interp_v3_v3v3(sv->v->co, up_co, down_co, fac);
+                               }
+                       }
                }
        }
        
-       projectSVData(t, 0);
+       projectEdgeSlideData(t, 0);
        
        return 1;
 }
@@ -5522,7 +5738,7 @@ int EdgeSlide(TransInfo *t, const int UNUSED(mval[2]))
 {
        char str[128];
        float final;
-       SlideData *sld =  t->customData;
+       EdgeSlideData *sld =  t->customData;
        int flipped = sld->flipped_vtx;
        int is_proportional = sld->is_proportional;
 
@@ -5998,7 +6214,7 @@ static short getAnimEdit_DrawTime(TransInfo *t)
                SpaceIpo *sipo = (SpaceIpo *)t->sa->spacedata.first;
                
                drawtime = (sipo->flag & SIPO_DRAWTIME) ? 1 : 0;
-       }       
+       }
        else {
                drawtime = 0;
        }
@@ -6479,5 +6695,5 @@ int TimeScale(TransInfo *t, const int UNUSED(mval[2]))
 void BIF_TransformSetUndo(const char *UNUSED(str))
 {
        // TRANSFORM_FIX_ME
-       //Trans.undostr= str;
+       //Trans.undostr = str;
 }