Switch from GPLv2 to GPLv2+
[fw/altos] / ao-tools / lib / cc-integrate.c
index f9793dcdb3a3c3a5377a939659039a19d833d8b6..8009f0c3cda816dd20896dfe4a2c947b93088859 100644 (file)
@@ -3,7 +3,8 @@
  *
  * 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
- * the Free Software Foundation; version 2 of the License.
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful, but
  * WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -37,24 +38,27 @@ cc_timedata_convert(struct cc_timedata *d, double (*f)(double v, double a), doub
 }
 
 struct cc_timedata *
-cc_timedata_integrate(struct cc_timedata *d)
+cc_timedata_integrate(struct cc_timedata *d, double min_time, double max_time)
 {
        struct cc_timedata      *i;
-       int                     n;
+       int                     n, m;
+       int                     start, stop;
 
+       cc_timedata_limits(d, min_time, max_time, &start, &stop);
        i = calloc (1, sizeof (struct cc_timedata));
-       i->num = d->num;
-       i->size = d->num;
+       i->num = stop - start + 1;
+       i->size = i->num;
        i->data = calloc (i->size, sizeof (struct cc_timedataelt));
-       i->time_offset = d->time_offset;
-       for (n = 0; n < d->num; n++) {
-               i->data[n].time = d->data[n].time;
+       i->time_offset = d->data[start].time;
+       for (n = 0; n < i->num; n++) {
+               m = n + start;
+               i->data[n].time = d->data[m].time;
                if (n == 0) {
                        i->data[n].value = 0;
                } else {
                        i->data[n].value = i->data[n-1].value +
-                               (d->data[n].value + d->data[n-1].value) / 2 *
-                               ((d->data[n].time - d->data[n-1].time) / 100.0);
+                               (d->data[m].value + d->data[m-1].value) / 2 *
+                               ((d->data[m].time - d->data[m-1].time) / 100.0);
                }
        }
        return i;