diff --git a/src/actions.c b/src/actions.c index 9d5b67d9..ef30355b 100644 --- a/src/actions.c +++ b/src/actions.c @@ -3867,3 +3867,18 @@ void select_rect(int stretch, int what, int select) } } +/* needed to dynamically reassign the `manhattan_lines` value for wire-drawing */ +void recompute_orthogonal_manhattanline(double linex1, double liney1, double linex2, double liney2) { + double origin_shifted_x2, origin_shifted_y2; + /* Origin shift the cartesian coordinate p2(x2,y2) w.r.t. p1(x1,y1) */ + origin_shifted_x2 = linex2 - linex1; + origin_shifted_y2 = liney2 - liney1; + /* Draw whichever component of the resulting orthogonal-wire is bigger (either horizontal or vertical), first */ + if(origin_shifted_x2*origin_shifted_x2 > origin_shifted_y2*origin_shifted_y2) + xctx->manhattan_lines = 1; + else + xctx->manhattan_lines = 2; + + return; +} + diff --git a/src/callback.c b/src/callback.c index 3f5a4142..0b057c3a 100644 --- a/src/callback.c +++ b/src/callback.c @@ -107,7 +107,6 @@ void redraw_w_a_l_r_p_z_rubbers(int force) { double mx = xctx->mousex_snap; double my = xctx->mousey_snap; - double origin_shifted_x2, origin_shifted_y2; if(!force && xctx->mousex_snap == xctx->prev_rubberx && xctx->mousey_snap == xctx->prev_rubbery) return; @@ -117,15 +116,7 @@ void redraw_w_a_l_r_p_z_rubbers(int force) if(xctx->constr_mv == 2) mx = xctx->mx_double_save; if(tclgetboolvar("orthogonal_wiring")) { new_wire(RUBBER|CLEAR, xctx->mousex_snap, xctx->mousey_snap); - /* Origin shift the cartesian coordinate p2(x2,y2) w.r.t. p1(x1,y1) */ - origin_shifted_x2 = xctx->nl_x2 - xctx->nl_x1; - origin_shifted_y2 = xctx->nl_y2 - xctx->nl_y1; - /* Draw whichever component of the resulting orthogonal-wire is bigger (either horizontal or vertical), first */ - if(origin_shifted_x2*origin_shifted_x2 > origin_shifted_y2*origin_shifted_y2){ - xctx->manhattan_lines = 1; - } else { - xctx->manhattan_lines = 2; - } + recompute_orthogonal_manhattanline(xctx->nl_x1, xctx->nl_y1, xctx->nl_x2, xctx->nl_y2); } new_wire(RUBBER, mx, my); } diff --git a/src/draw.c b/src/draw.c index 39a6cd09..cddcb681 100644 --- a/src/draw.c +++ b/src/draw.c @@ -1378,16 +1378,8 @@ void drawtempline(GC gc, int what, double linex1,double liney1,double linex2,dou void drawtemp_manhattanline(GC gc, int what, double x1, double y1, double x2, double y2, int force_manhattan) { double nl_xx1, nl_yy1, nl_xx2, nl_yy2; - double origin_shifted_x2, origin_shifted_y2; if(tclgetboolvar("orthogonal_wiring") && force_manhattan) { - /* Origin shift the cartesian coordinate p2(x2,y2) w.r.t. p1(x1,y1) */ - origin_shifted_x2 = x2 - x1; - origin_shifted_y2 = y2 - y1; - /* Draw whichever component of the resulting orthogonal-wire is bigger (either horizontal or vertical), first */ - if(origin_shifted_x2*origin_shifted_x2 > origin_shifted_y2*origin_shifted_y2) - xctx->manhattan_lines = 1; - else - xctx->manhattan_lines = 2; + recompute_orthogonal_manhattanline(x1, y1, x2, y2); } if(xctx->manhattan_lines & 1) { nl_xx1 = x1; nl_yy1 = y1; diff --git a/src/move.c b/src/move.c index afbe9288..d7b97e54 100644 --- a/src/move.c +++ b/src/move.c @@ -1034,15 +1034,7 @@ static void place_moved_wire(int n, int orthogonal_wiring) /* Need to dynamically assign `manhattan_lines` to each wire. Otherwise, a single * `manhattan_lines` value gets forced on all wires connected to a moved object*/ if(orthogonal_wiring) { - double origin_shifted_x2, origin_shifted_y2; - /* Origin shift the cartesian coordinate p2(x2,y2) w.r.t. p1(x1,y1) */ - origin_shifted_x2 = xctx->rx2 - xctx->rx1; - origin_shifted_y2 = xctx->ry2 - xctx->ry1; - /* Draw whichever component of the resulting orthogonal-wire is bigger (either horizontal or vertical), first */ - if(origin_shifted_x2*origin_shifted_x2 > origin_shifted_y2*origin_shifted_y2) - xctx->manhattan_lines = 1; - else - xctx->manhattan_lines = 2; + recompute_orthogonal_manhattanline(xctx->rx1, xctx->ry1, xctx->rx2, xctx->ry2); } /* wire x1,y1 point was moved diff --git a/src/xschem.h b/src/xschem.h index 8a881df9..4177b28a 100644 --- a/src/xschem.h +++ b/src/xschem.h @@ -1428,6 +1428,7 @@ extern void filledrect(int c, int what, double rectx1,double recty1, extern void drawtempline(GC gc, int what, double x1,double y1,double x2,double y2); +extern void recompute_orthogonal_manhattanline(double linex1, double liney1, double linex2, double liney2); extern void drawtemp_manhattanline(GC gc, int what, double x1,double y1,double x2,double y2, int force_manhattan); /* instead of doing a drawtemprect(xctx->gctiled, NOW, ....) do 4