[Refactored Reused Code]: Code responsible for dynamically computing 'xctx->manhattan_lines' are now bundled up in a separate function -- reducing complexity, increasing readability and future maintainablity, and the need to look out for unintentional C89-standard violations.
This commit is contained in:
parent
e2b3a58540
commit
02f0a4ea3a
|
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -107,7 +107,6 @@ void redraw_w_a_l_r_p_z_rubbers(int force)
|
||||||
{
|
{
|
||||||
double mx = xctx->mousex_snap;
|
double mx = xctx->mousex_snap;
|
||||||
double my = xctx->mousey_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;
|
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(xctx->constr_mv == 2) mx = xctx->mx_double_save;
|
||||||
if(tclgetboolvar("orthogonal_wiring")) {
|
if(tclgetboolvar("orthogonal_wiring")) {
|
||||||
new_wire(RUBBER|CLEAR, xctx->mousex_snap, xctx->mousey_snap);
|
new_wire(RUBBER|CLEAR, xctx->mousex_snap, xctx->mousey_snap);
|
||||||
/* Origin shift the cartesian coordinate p2(x2,y2) w.r.t. p1(x1,y1) */
|
recompute_orthogonal_manhattanline(xctx->nl_x1, xctx->nl_y1, xctx->nl_x2, xctx->nl_y2);
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
new_wire(RUBBER, mx, my);
|
new_wire(RUBBER, mx, my);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
10
src/draw.c
10
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)
|
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 nl_xx1, nl_yy1, nl_xx2, nl_yy2;
|
||||||
double origin_shifted_x2, origin_shifted_y2;
|
|
||||||
if(tclgetboolvar("orthogonal_wiring") && force_manhattan) {
|
if(tclgetboolvar("orthogonal_wiring") && force_manhattan) {
|
||||||
/* Origin shift the cartesian coordinate p2(x2,y2) w.r.t. p1(x1,y1) */
|
recompute_orthogonal_manhattanline(x1, y1, x2, y2);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
if(xctx->manhattan_lines & 1) {
|
if(xctx->manhattan_lines & 1) {
|
||||||
nl_xx1 = x1; nl_yy1 = y1;
|
nl_xx1 = x1; nl_yy1 = y1;
|
||||||
|
|
|
||||||
10
src/move.c
10
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
|
/* 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*/
|
* `manhattan_lines` value gets forced on all wires connected to a moved object*/
|
||||||
if(orthogonal_wiring) {
|
if(orthogonal_wiring) {
|
||||||
double origin_shifted_x2, origin_shifted_y2;
|
recompute_orthogonal_manhattanline(xctx->rx1, xctx->ry1, xctx->rx2, xctx->ry2);
|
||||||
/* 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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* wire x1,y1 point was moved
|
/* wire x1,y1 point was moved
|
||||||
|
|
|
||||||
|
|
@ -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 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);
|
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
|
/* instead of doing a drawtemprect(xctx->gctiled, NOW, ....) do 4
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue