LinearInterpolant.js 842 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import { Interpolant } from '../Interpolant';
  2. /**
  3. * @author tschw
  4. */
  5. function LinearInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  6. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  7. }
  8. LinearInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  9. constructor: LinearInterpolant,
  10. interpolate_: function( i1, t0, t, t1 ) {
  11. var result = this.resultBuffer,
  12. values = this.sampleValues,
  13. stride = this.valueSize,
  14. offset1 = i1 * stride,
  15. offset0 = offset1 - stride,
  16. weight1 = ( t - t0 ) / ( t1 - t0 ),
  17. weight0 = 1 - weight1;
  18. for ( var i = 0; i !== stride; ++ i ) {
  19. result[ i ] =
  20. values[ offset0 + i ] * weight0 +
  21. values[ offset1 + i ] * weight1;
  22. }
  23. return result;
  24. }
  25. } );
  26. export { LinearInterpolant };