[BACK]Return to compact.c CVS log [TXT][DIR] Up to [local] / OpenXM_contrib / gnuplot / term

Annotation of OpenXM_contrib/gnuplot/term/compact.c, Revision 1.1.1.2

1.1       maekawa     1: /*
1.1.1.2 ! maekawa     2:  * $Id: compact.c,v 1.2 1998/11/25 21:05:04 lhecking Exp $
1.1       maekawa     3:  *
                      4:  */
                      5:
                      6: /* GNUPLOT - compact.c */
                      7:
                      8: /* contains routines to compress a vector stream without modifying it */
                      9:
                     10: /*[
                     11:  * Copyright 1986 - 1993, 1998   Thomas Williams, Colin Kelley
                     12:  *
                     13:  * Permission to use, copy, and distribute this software and its
                     14:  * documentation for any purpose with or without fee is hereby granted,
                     15:  * provided that the above copyright notice appear in all copies and
                     16:  * that both that copyright notice and this permission notice appear
                     17:  * in supporting documentation.
                     18:  *
                     19:  * Permission to modify the software is granted, but not the right to
                     20:  * distribute the complete modified source code.  Modifications are to
                     21:  * be distributed as patches to the released version.  Permission to
                     22:  * distribute binaries produced by compiling modified sources is granted,
                     23:  * provided you
                     24:  *   1. distribute the corresponding source modifications from the
                     25:  *    released version in the form of a patch file along with the binaries,
                     26:  *   2. add special version identification to distinguish your version
                     27:  *    in addition to the base release version number,
                     28:  *   3. provide your name and address as the primary contact for the
                     29:  *    support of your modified version, and
                     30:  *   4. retain our contact information in regard to use of the base
                     31:  *    software.
                     32:  * Permission to distribute the released version of the source code along
                     33:  * with corresponding source modifications in the form of a patch file is
                     34:  * granted with same provisions 2 through 4 for binary distributions.
                     35:  *
                     36:  * This software is provided "as is" without express or implied warranty
                     37:  * to the extent permitted by applicable law.
                     38: ]*/
                     39:
                     40: #ifndef COMPACT
                     41:
                     42: /* replaces runs of constant slope in the buffer with single vectors
                     43:    returns the number of points eliminated */
                     44: int compact_slope(xp, yp, isa_move, sz, delta)
                     45: int xp[], yp[], isa_move[];
                     46: int *sz;
                     47: double delta;
                     48: {
                     49:     int dx, dy, old_size, new_index, i, start;
                     50:     float slope, old_slope;
                     51:
                     52:     old_size = *sz;
                     53:     new_index = 0;
                     54:     start = 0;
                     55:     if (xp[1] != xp[0])
                     56:        old_slope = (float) (yp[1] - yp[0]) / (float) (xp[1] - xp[0]);
                     57:     else
                     58:        old_slope = (float) (yp[1] - yp[0]) / (float) (0.00001 + xp[1] - xp[0]);
                     59:     for (i = 2; i < old_size; i++) {
                     60:        dx = xp[i] - xp[i - 1];
                     61:        dy = yp[i] - yp[i - 1];
                     62:        if (dx != 0)
                     63:            slope = (float) dy / (float) dx;
                     64:        else
                     65:            slope = (float) dy / ((float) dx + 0.00001);
                     66:        if ((ABS(slope - old_slope) > delta) || (isa_move[i])) {
                     67:            xp[new_index] = xp[start];
                     68:            yp[new_index] = yp[start];
                     69:            isa_move[new_index] = isa_move[start];
                     70:            new_index++;
                     71:            if (start != i - 1) {
                     72:                xp[new_index] = xp[i - 1];
                     73:                yp[new_index] = yp[i - 1];
                     74:                isa_move[new_index] = isa_move[i - 1];
                     75:                new_index++;
                     76:            }
                     77:            start = i;
                     78:            /* this is the slope for the new run */
                     79:            old_slope = slope;
                     80:        }
                     81:     }
                     82:     /* copy the last point into the new array */
                     83:     xp[new_index] = xp[old_size - 1];
                     84:     yp[new_index] = yp[old_size - 1];
                     85:     isa_move[new_index] = isa_move[old_size - 1];
                     86:     new_index++;
                     87:     *sz = new_index;
                     88:     return (old_size - *sz);
                     89: }
                     90:
                     91: /* compacts the vector list by compressing runs of constant
                     92:    dx&dy into one vector
                     93:    use this if floating point is too expensive!
                     94:    more naive than compact_slope; doesn't compact as much as possible
                     95:    returns the number of points eliminated */
                     96: int compact_int(xp, yp, isa_move, size)
                     97: int xp[], yp[], isa_move[], *size;
                     98: {
                     99:     int dx, dy, old_dx, old_dy, start, index, i, old_size;
                    100:
                    101:     start = index = 0;
                    102:     old_dx = xp[1] - xp[0];
                    103:     old_dy = yp[1] - yp[0];
                    104:     for (i = 2; i < *size; i++) {
                    105:        dx = xp[i] - xp[i - 1];
                    106:        dy = yp[i] - yp[i - 1];
                    107:        if ((ABS(dx - old_dx) + ABS(dy - old_dy) != 0) || (isa_move[i])) {
                    108:            /*  we've reached the end of a run */
                    109:            xp[index] = xp[start];
                    110:            yp[index] = yp[start];
                    111:            isa_move[index] = isa_move[start];
                    112:            index++;
                    113:            if (start != i - 1) {
                    114:                xp[index] = xp[i - 1];
                    115:                yp[index] = yp[i - 1];
                    116:                isa_move[index] = isa_move[i - 1];
                    117:                index++;
                    118:            }
                    119:            start = i;
                    120:            old_dx = dx;
                    121:            old_dy = dy;
                    122:        }
                    123:     }                          /* end for */
                    124:     /* include the last point */
                    125:     xp[index] = xp[*size - 1];
                    126:     yp[index] = yp[*size - 1];
                    127:     isa_move[index] = isa_move[*size - 1];
                    128:     index++;
                    129:     old_size = *size;
                    130:     *size = index;
                    131:     return (old_size - *size);
                    132: }
                    133: #endif
                    134:
                    135: #define COMPACT

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>