From e99711f2afc981e045002abfa5fe462a18cb9f4a Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Fri, 22 Mar 2024 12:07:05 +1300 Subject: [PATCH] img: Treat > 900 in Compass PLT LRUD as no reading This matches what Compass does. --- src/img.c | 47 ++++++++++++++++++++++++++++++++++++----------- tests/pre1970.dump | 5 +++++ tests/pre1970.plt | 2 ++ 3 files changed, 43 insertions(+), 11 deletions(-) diff --git a/src/img.c b/src/img.c index 931aaeb1..1e356128 100644 --- a/src/img.c +++ b/src/img.c @@ -2761,10 +2761,11 @@ bad_plt_date: */ while (*q && *q <= ' ') q++; if (*q == 'P') { + double dim[4]; int bytes_used; ++q; if (sscanf(q, "%lf%lf%lf%lf%n", - &pimg->l, &pimg->r, &pimg->u, &pimg->d, + &dim[0], &dim[1], &dim[2], &dim[3], &bytes_used) != 4) { osfree(line); if (ferror(pimg->fh)) { @@ -2774,19 +2775,43 @@ bad_plt_date: } return img_BAD; } - if ((pimg->flags & img_SFLAG_UNDERGROUND) && - (pimg->l >= 0 || pimg->r >= 0 || pimg->u >= 0 || pimg->d >= 0)) { - if (pimg->l >= 0) pimg->l *= METRES_PER_FOOT; else pimg->l = -1; - if (pimg->r >= 0) pimg->r *= METRES_PER_FOOT; else pimg->r = -1; - if (pimg->u >= 0) pimg->u *= METRES_PER_FOOT; else pimg->u = -1; - if (pimg->d >= 0) pimg->d *= METRES_PER_FOOT; else pimg->d = -1; + q += bytes_used; + + // No cross-sections for surface data. + if ((pimg->flags & img_SFLAG_UNDERGROUND)) { + int have_xsect = 0; + int i; + for (i = 0; i < 4; ++i) { + // The PLT format specification says 'Values less + // than zero are considered to be missing or + // “Passage.”' but Compass has an (apparently + // undocumented) extra check here for compatibility + // with data that was originally entered in Karst + // which uses 999 instead. + // + // Larry Fish says the check Compass actually uses + // when processing PLT files is: + // + // if (Left<0) or (Left>900) + if (dim[i] < 0.0 || dim[i] > 900.0) { + dim[i] = -1.0; + } else { + dim[i] *= METRES_PER_FOOT; + have_xsect = 1; + } + } + if (!have_xsect) goto no_xsect; + pimg->l = dim[0]; + pimg->r = dim[1]; + pimg->u = dim[2]; + pimg->d = dim[3]; pimg->pending |= PENDING_XSECT | PENDING_HAD_XSECT; - } else if (pimg->pending == PENDING_HAD_XSECT) { - pimg->pending = PENDING_XSECT_END; + } else { + goto no_xsect; } - q += bytes_used; } else { - pimg->l = pimg->r = pimg->u = pimg->d = -1; +no_xsect: + pimg->l = pimg->r = pimg->u = pimg->d = -1.0; if (pimg->pending == PENDING_HAD_XSECT) { pimg->pending = PENDING_XSECT_END; } diff --git a/tests/pre1970.dump b/tests/pre1970.dump index e533ecbf..8bb19ee2 100644 --- a/tests/pre1970.dump +++ b/tests/pre1970.dump @@ -40,4 +40,9 @@ LEG -24.11 39.56 -31.00 -25.27 40.97 -30.45 [Z+] SPLAY 1969.12.30 XSECT_END NODE -25.27 40.97 -30.14 [Z+ Z16] UNDERGROUND WALL LEG -24.11 39.56 -31.00 -25.27 40.97 -30.14 [Z+] DUPLICATE SPLAY 1969.12.30 +XSECT 0.15 0.15 0.15 0.46 [Z+ Z12] 1969.12.30 +NODE -23.47 38.04 -30.18 [Z+ Z17] UNDERGROUND +XSECT 0.15 0.15 -1.00 -1.00 [Z+ Z17] 1969.12.30 +LEG -24.11 39.56 -31.00 -23.47 38.04 -30.18 [Z+] 1969.12.30 +XSECT_END STOP diff --git a/tests/pre1970.plt b/tests/pre1970.plt index f9bd60a8..bd04e96a 100644 --- a/tests/pre1970.plt +++ b/tests/pre1970.plt @@ -16,6 +16,8 @@ M 129.8 -79.1 -101.7 SZ12 I 105.8 D 134.4 -82.9 -99.9 SZ15 P 0.5 4.0 0.5 1.5 FS M 129.8 -79.1 -101.7 SZ12 D 134.4 -82.9 -98.9 SZ16 FSL +M 129.8 -79.1 -101.7 SZ12 P 0.5 0.5 0.5 1.5 +D 124.8 -77.0 -99.0 SZ17 P 0.5 0.5 -1.0 900.1 X 118.78 138.22 -82.94 -63.34 -101.90 -82.53 FFEATURE1 L 0.0 0.0 0.0 SA1 P -9.0 -9.0 -9.0 -9.0 -- 2.11.4.GIT