Changeset 58ce967 in git


Ignore:
Timestamp:
20/09/11 12:57:15 (8 years ago)
Author:
Olly Betts <olly@…>
Branches:
svn/1.0, svn/tags/1.0.40
Children:
9d044ac
Parents:
bfc4c77
Message:

Backport changes from 1.2.0:
src/diffpos.c: Handle files with duplicate labels in better - extend
generates duplicate labels when it breaks a loop.
tests/extend.tst: Enable eswap-break testcase now that diffpos is
fixed.

git-svn-id: file:///home/survex-svn/survex/branches/1.0@3705 4b37db11-9a0c-4f06-9ece-9ab7cdaee568

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • ChangeLog

    rbfc4c77 r58ce967  
     1Tue Sep 20 11:56:04 GMT 2011  Olly Betts <olly@survex.com>
     2
     3        * Backport changes from 1.2.0:
     4        * src/diffpos.c: Handle files with duplicate labels in better - extend
     5          generates duplicate labels when it breaks a loop.
     6        * tests/extend.tst: Enable eswap-break testcase now that diffpos is
     7          fixed.
     8
    19Tue Sep 20 11:36:30 GMT 2011  Olly Betts <olly@survex.com>
    210
  • src/diffpos.c

    rbfc4c77 r58ce967  
    11/* diffpos.c */
    22/* Utility to compare two SURVEX .pos or .3d files */
    3 /* Copyright (C) 1994,1996,1998-2003 Olly Betts
     3/* Copyright (C) 1994,1996,1998-2003,2010 Olly Betts
    44 *
    55 * This program is free software; you can redistribute it and/or modify
     
    100100{
    101101   int v = hash_string(name) & (TREE_SIZE - 1);
    102    station *stn;
    103 
    104    /* Catch duplicate labels - .3d files shouldn't have them, but some do
    105     * due to a couple of bugs in some versions of Survex
    106     */
    107    for (stn = htab[v]; stn; stn = stn->next) {
    108       if (strcmp(stn->name, name) == 0) return; /* found dup */
    109    }
    110 
    111    stn = osnew(station);
     102   station * stn = osnew(station);
    112103   stn->name = osstrdup(name);
    113104   stn->pt = *pt;
     
    116107}
    117108
     109static int
     110close_enough(const img_point * p1, const img_point * p2)
     111{
     112    return fabs(p1->x - p2->x) - threshold <= TOLERANCE &&
     113           fabs(p1->y - p2->y) - threshold <= TOLERANCE &&
     114           fabs(p1->z - p2->z) - threshold <= TOLERANCE;
     115}
     116
    118117static void
    119118tree_remove(const char *name, const img_point *pt)
    120119{
     120   /* We need to handle duplicate labels - normal .3d files shouldn't have them
     121    * (though some older ones do due to a couple of bugs in earlier versions of
     122    * Survex) but extended .3d files repeat the label where a loop is broken,
     123    * and data read from foreign formats might repeat labels.
     124    */
    121125   int v = hash_string(name) & (TREE_SIZE - 1);
    122126   station **prev;
    123127   station *p;
     128   station **found = NULL;
     129   bool was_close_enough = fFalse;
    124130
    125131   for (prev = &htab[v]; *prev; prev = &((*prev)->next)) {
    126       if (strcmp((*prev)->name, name) == 0) break;
    127    }
    128 
    129    if (!*prev) {
     132      if (strcmp((*prev)->name, name) == 0) {
     133         /* Handle stations with the same name.  Stations are inserted at the
     134          * start of the linked list, so pick the *last* matching station in
     135          * the list as then we match the first stations with the same name in
     136          * each file.
     137          */
     138         if (close_enough(pt, &((*prev)->pt))) {
     139            found = prev;
     140            was_close_enough = fTrue;
     141         } else if (!was_close_enough) {
     142            found = prev;
     143         }
     144      }
     145   }
     146
     147   if (!found) {
    130148      added *add = osnew(added);
    131149      add->name = osstrdup(name);
     
    137155   }
    138156
    139    if (fabs(pt->x - (*prev)->pt.x) - threshold > TOLERANCE ||
    140        fabs(pt->y - (*prev)->pt.y) - threshold > TOLERANCE ||
    141        fabs(pt->z - (*prev)->pt.z) - threshold > TOLERANCE) {
     157   if (!was_close_enough) {
    142158      printf(msg(/*Moved by (%3.2f,%3.2f,%3.2f): %s*/500),
    143              pt->x - (*prev)->pt.x,
    144              pt->y - (*prev)->pt.y,
    145              pt->z - (*prev)->pt.z,
     159             pt->x - (*found)->pt.x,
     160             pt->y - (*found)->pt.y,
     161             pt->z - (*found)->pt.z,
    146162             name);
    147163      putnl();
     
    149165   }
    150166
    151    osfree((*prev)->name);
    152    p = *prev;
    153    *prev = p->next;
     167   osfree((*found)->name);
     168   p = *found;
     169   *found = p->next;
    154170   osfree(p);
    155171}
  • tests/extend.tst

    rbfc4c77 r58ce967  
    3232: ${DIFFPOS="$testdir"/../src/diffpos}
    3333
    34 : ${TESTS=${*:-"extend extend2names eswap"}} # also eswap-break
    35 # JPNP: eswap-break currently fails due to bug in diffpos
     34: ${TESTS=${*:-"extend extend2names eswap eswap-break"}}
    3635
    3736for file in $TESTS ; do
Note: See TracChangeset for help on using the changeset viewer.