From 1f52d630f53ba3cd0d2329f810da4847f775dc07 Mon Sep 17 00:00:00 2001 From: stefan schippers Date: Mon, 15 Sep 2025 09:18:25 +0200 Subject: [PATCH] better distance threshold tuning for object selection --- src/callback.c | 1 + src/findnet.c | 20 +++++++++----------- src/xschem.h | 2 +- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/callback.c b/src/callback.c index 0266d7a3..3e455ce7 100644 --- a/src/callback.c +++ b/src/callback.c @@ -1843,6 +1843,7 @@ static int add_wire_from_wire(Selected *sel, double mx, double my) double y1 = xctx->wire[n].y1; double x2 = xctx->wire[n].x2; double y2 = xctx->wire[n].y2; + dbg(1, "add_wire_from_wire\n"); if( (mx == x1 && my == y1) || (mx == x2 && my == y2) ) { unselect_all(1); start_wire(xctx->mousex_snap, xctx->mousey_snap); diff --git a/src/findnet.c b/src/findnet.c index 3a19ef2a..4621588f 100644 --- a/src/findnet.c +++ b/src/findnet.c @@ -33,8 +33,9 @@ static void find_closest_wire(double mx, double my, int override_lock) int i, w=-1; double threshold; double d = distance; - threshold = CADWIREMINDIST * CADWIREMINDIST * xctx->zoom * xctx->zoom * tk_scaling; + threshold = CADWIREMINDIST * CADWIREMINDIST * xctx->zoom * xctx->zoom * tk_scaling * tk_scaling; + dbg(1, "threshold=%g\n", threshold); for(i=0;iwires; ++i) { if( (tmp = dist(xctx->wire[i].x1, xctx->wire[i].y1, xctx->wire[i].x2, xctx->wire[i].y2, mx, my)) < d ) @@ -117,7 +118,7 @@ static void find_closest_polygon(double mx, double my, int override_lock) double x1, y1, x2, y2; double threshold; double d = distance; - threshold = CADWIREMINDIST * CADWIREMINDIST * xctx->zoom * xctx->zoom * tk_scaling; + threshold = CADWIREMINDIST * CADWIREMINDIST * xctx->zoom * xctx->zoom * tk_scaling * tk_scaling; for(c=0;cenable_layer[c]) continue; @@ -162,7 +163,7 @@ static void find_closest_line(double mx, double my, int override_lock) int i, c, l = -1, col = 0; double threshold; double d = distance; - threshold = CADWIREMINDIST * CADWIREMINDIST * xctx->zoom * xctx->zoom * tk_scaling; + threshold = CADWIREMINDIST * CADWIREMINDIST * xctx->zoom * xctx->zoom * tk_scaling * tk_scaling; for(c=0;cenable_layer[c]) continue; @@ -329,7 +330,7 @@ static void find_closest_arc(double mx, double my, int override_lock) int match; double threshold; double d = distance; - threshold = CADWIREMINDIST * CADWIREMINDIST * xctx->zoom * xctx->zoom * tk_scaling; + threshold = CADWIREMINDIST * CADWIREMINDIST * xctx->zoom * xctx->zoom * tk_scaling * tk_scaling; for(c=0;ccadhalfdotsize; + double threshold = CADWIREMINDIST * xctx->zoom * tk_scaling; int i, c, r=-1, col = 0; double d = distance; @@ -389,11 +390,8 @@ static void find_closest_box(double mx ,double my, int override_lock) if(!xctx->enable_layer[c]) continue; for(i=0;irects[c]; ++i) { - double min = MINOR(xctx->rect[c][i].x2 - xctx->rect[c][i].x1, - xctx->rect[c][i].y2 - xctx->rect[c][i].y1); - ds = (xctx->cadhalfdotsize * 8 <= min ) ? xctx->cadhalfdotsize : min / 8; - if( POINTINSIDE(mx, my, xctx->rect[c][i].x1 - ds, xctx->rect[c][i].y1 - ds, - xctx->rect[c][i].x2 + ds, xctx->rect[c][i].y2 + ds) ) + if( POINTINSIDE(mx, my, xctx->rect[c][i].x1 - threshold, xctx->rect[c][i].y1 - threshold, + xctx->rect[c][i].x2 + threshold, xctx->rect[c][i].y2 + threshold) ) { tmp=dist_from_rect(mx, my, xctx->rect[c][i].x1, xctx->rect[c][i].y1, xctx->rect[c][i].x2, xctx->rect[c][i].y2); @@ -447,7 +445,7 @@ static void find_closest_text(double mx, double my, int override_lock) #endif char *estr = NULL; double d = distance; - threshold = CADWIREMINDIST * CADWIREMINDIST * xctx->zoom * xctx->zoom * tk_scaling; + threshold = CADWIREMINDIST * CADWIREMINDIST * xctx->zoom * xctx->zoom * tk_scaling * tk_scaling; for(i=0;itexts; ++i) { rot = xctx->text[i].rot; diff --git a/src/xschem.h b/src/xschem.h index e0ed0d41..200074ff 100644 --- a/src/xschem.h +++ b/src/xschem.h @@ -169,7 +169,7 @@ extern char win_temp_dir[PATH_MAX]; #define CADMINZOOM 0.005 #define CADHALFDOTSIZE 3.7 #define CADNULLNODE -1 /* no valid node number */ -#define CADWIREMINDIST 8.0 +#define CADWIREMINDIST 12.0 #define CADMAXWIRES 200 #define CADMAXTEXT 100 #define CADMAXOBJECTS 100 /* (initial) max # of lines, rects (for each layer!!) */