package app.brest.utils;

import java.util.ArrayList;

import app.brest.utils.geometry.Point;

/*
public class SlideBuffer {
    private float mData;
    private int mSize;
    private int mHead;

    public SlideBuffer(int size)
    {
        mData = 0;
        mSize = 0;
        mHead =0;
    }

    public void enqueue(float val)
    {
        mData= mData + 0.5f*(val-mData);
    }

    public float average()
    {
        return mData;
    }

}*/

public class SlideBuffer {
    private float mDataSin;
    private float mDataCos;
    private float mCoef = 0.1f;
    private final static float[] SENSORS_COEFS = {0.4f, 0.2f, 0.1f, 0.05f, 0.025f};
    private int mSize;
    private int mHead;

    public SlideBuffer(int latency_level)
    {
        mCoef=SENSORS_COEFS[latency_level];
        mDataSin = 0;
        mDataCos = 0;
        mSize = 0;
        mHead =0;
    }

    public void setLatencyLevel(int x)
    {
        mCoef=SENSORS_COEFS[x];
    }

    public void enqueue(float _val)
    {
        float val = -_val-90;
        mDataSin= mDataSin + mCoef*((float)Math.sin(val*Math.PI/180)-mDataSin);
        mDataCos= mDataCos + mCoef*((float)Math.cos(val*Math.PI/180)-mDataCos);
    }

    public float average()
    {
        return (float)( (((Math.atan2(mDataCos, mDataSin))*180/Math.PI)+180f) % 360);
    }

}

/*
public class SlideBuffer {
    private float mDataCos[] ;
    private float mDataSin[];
    private int mSize;
    private int mI=0;
    private int mHead;

    public SlideBuffer(int size)
    {
        mSize = size;
        mHead =0;
        mDataCos = new float[size];
        mDataSin = new float[size];
    }

    public void enqueue(float val)
    {
        //mData= mData + 0.5f*(val-mData);
        mDataCos[mI]=(float)Math.cos(val);
        mDataSin[mI]=(float)Math.sin(val);
        mI=(mI+1)%mSize;

    }

    public float average()
    {
        float avSin=0, avCos=0;
        for(int i=0; i<mSize; i++)
        {
            avSin+=mDataSin[i];
            avCos+=mDataCos[i];
        }
        avSin/=mSize;
        avCos/=mSize;
        return (float)((Math.PI+Math.atan2(avCos, avSin))*180/Math.PI);
    }

}
*/


/*
package app.brest.utils;

import java.util.ArrayList;

public class SlideBuffer {
    private float[] mData;
    private float[] mTmp;
    private int mSize;
    private int mHead;

    public SlideBuffer(int size)
    {
        mData = new float[size];
        mTmp = new float[size];
        mSize = 0;
        mHead =0;
    }

    public void enqueue(float val)
    {

        mData[mHead] = val;
        mHead=(mHead+1)%mData.length;
        if(mSize<mData.length) mSize++;
    }

    private float[] exponentialSmoothing( float[] input, float[] output_mkv, float alpha ) {
        if ( output_mkv == null )
            return input;
        for ( int i=0; i<input.length; i++ ) {
            output_mkv[i] = output_mkv[i] + alpha * (input[i] - output_mkv[i]);
        }
        return output_mkv;
    }

    public float average()
    {

            float acc=0;
            for(int i=0; i<mSize; i++)
                acc+=mData[i];
            return acc/mSize;
    }



}
*/
