00001 #include <math.h>
00002
00003 #include "xalloc.h"
00004 #include "uti.h"
00005 #include "vecint.hpp"
00006
00007
00008
00009 VecInt::VecInt( INT n, BOOL linint, DOUBLE te )
00010 {
00011 len=n;
00012 lin=linint;
00013 tend=te?te:1;
00014
00015 v1=v2=vwrk=NULL;
00016
00017 v1 = (DOUBLE*)xmalloc(sizeof(DOUBLE)*len);
00018 v2 = (DOUBLE*)xmalloc(sizeof(DOUBLE)*len);
00019 if (lin) vwrk = (DOUBLE*)xmalloc(sizeof(DOUBLE)*len);
00020 }
00021
00022
00023
00024 VecInt::~VecInt()
00025 {
00026 #define FREE(v) if (v) xfree(v)
00027 FREE(v1);
00028 FREE(v2);
00029 FREE(vwrk);
00030 #undef FREE
00031 }
00032
00033
00034
00035 VOID VecInt::set( DOUBLE *v, DOUBLE te )
00036 {
00037 if (te==0) memcpy(v1,v,sizeof(DOUBLE)*len);
00038 else memcpy(v1,v2,sizeof(DOUBLE)*len);
00039 memcpy(v2,v,sizeof(DOUBLE)*len);
00040 if (te>0) tend=te;
00041 }
00042
00043
00044
00045 PRIVATE void interp( DOUBLE *v1, DOUBLE *v2, DOUBLE *out, INT len, DOUBLE pos )
00046 {
00047 for (INT i=0; i<len; i++) out[i]=v1[i]*(1-pos)+v2[i]*pos;
00048 }
00049
00050
00051
00052 DOUBLE *VecInt::get( DOUBLE pos )
00053 {
00054 pos /= tend;
00055
00056 if (pos<=0) return v1;
00057 if (pos>=1) return v2;
00058
00059 if (lin) {
00060 interp(v1,v2,vwrk,len,pos);
00061 return vwrk;
00062 }
00063
00064 if (pos<0.5) return v1;
00065 return v2;
00066 }
00067
00068
00069