]> git.draconx.ca Git - slotifier.git/commitdiff
Fix radius/diameter confusion in overlap search.
authorNick Bowler <nbowler@draconx.ca>
Wed, 14 Apr 2021 00:32:16 +0000 (20:32 -0400)
committerNick Bowler <nbowler@draconx.ca>
Wed, 14 Apr 2021 00:32:16 +0000 (20:32 -0400)
Drill sizes are specified as hole diameter, but the nearest neighbour
search is performed by distance.

The overlap relation is documented as "when the centre of one hole is
inside the other hole" which implies that we should be searching on
hole radius.  Presently the diameter is used, which is twice as far
as expected.

For holes that are the same size this is a minor technicality: such
holes that are apart by less than the hole diameter do "overlap" in
the drilled portion.  But when a small hole is near a large hole they
can be obviously disjoint yet slotifier can erroneously merge them.

Adjust the search to half the diameter, plus some slop (5 tenths)
so that holes exactly on the boundary are counted as overlapping.

NEWS
src/slotifier.c
tests/simple.at

diff --git a/NEWS b/NEWS
index ef6df4bbc93d1dc4033980e53f8ee420294582d6..c9b7e47a838d98778b63b7705e1ab51645e3a49d 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,4 +1,5 @@
 Release 1.1a:
+       * Fix calculation error in overlap relation.
        * Various bug fixes and improvements.
 
 Release 1.1:
index 01659319cf16d9506a53c730703011c60734bafd..b74a9ecf5112c0daa4b3bd41c1ec1b1296af5ef4 100644 (file)
@@ -221,7 +221,7 @@ static int combine_holes(gerbv_image_t *drill, gerbv_net_t *hole,
        hole->aperture = -hole->aperture;
 
        for (i = 0; i < CVectorSize(group); i++) {
-               double xy[2], dia;
+               double xy[2], dia, r;
 
                CVectorGetElement(group, &hole, i);
                tool = drill->aperture[abs(hole->aperture)];
@@ -230,10 +230,13 @@ static int combine_holes(gerbv_image_t *drill, gerbv_net_t *hole,
                xy[0] = hole->start_x; xy[1] = hole->start_y;
                dia = tool->parameter[0];
 
+               /* Half a mil slop to decisively include points on boundary. */
+               r = dia/2 + 0.0005;
+
                if (drill->aperture[biggest_tool]->parameter[0] < dia)
                        biggest_tool = abs(hole->aperture);
 
-               if (CNearTreeFindInSphere(t, dia, 0, tmp, xy, 1) != 0) {
+               if (CNearTreeFindInSphere(t, r, 0, tmp, xy, 1) != 0) {
                        /* We should always should find at least one hole! */
                        fprintf(stderr, _("%s: fatal error searching holes\n"),
                                        progname);
index 1b6c588241d155911f700dd2c2079e9ef0629e3f..8e28f6b24793de54ba87997f61705c622a7b899f 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright © 2018 Nick Bowler
+# Copyright © 2018, 2021 Nick Bowler
 #
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -53,3 +53,35 @@ M30
 ]])
 
 AT_CLEANUP
+
+AT_SETUP([non-overlapping holes])
+
+AT_DATA([test.cnc],
+[[M48
+INCH
+T25C0.010
+T24C0.091
+%
+T25
+X010433Y001181
+T24
+X010512Y002362
+X010512Y002047
+M30
+]])
+
+AT_CHECK([slotifier test.cnc], [0],
+[[M48
+INCH,TZ
+T10C0.091
+T11C0.010
+%
+T10
+X010512Y002362G85X010512Y002047
+T11
+X010433Y001181
+M30
+
+]])
+
+AT_CLEANUP