better distance threshold tuning for object selection

This commit is contained in:
stefan schippers 2025-09-15 09:18:25 +02:00
parent 987faa1a41
commit 1f52d630f5
3 changed files with 11 additions and 12 deletions

View File

@ -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);

View File

@ -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;i<xctx->wires; ++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;c<cadlayers; ++c)
{
if(!xctx->enable_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;c<cadlayers; ++c)
{
if(!xctx->enable_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;c<cadlayers; ++c)
{
@ -379,7 +380,7 @@ static void find_closest_arc(double mx, double my, int override_lock)
static void find_closest_box(double mx ,double my, int override_lock)
{
double tmp;
double ds = xctx->cadhalfdotsize;
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;i<xctx->rects[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;i<xctx->texts; ++i)
{
rot = xctx->text[i].rot;

View File

@ -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!!) */