#include "Slicer.h"

Slicer::Slicer()
    : _idxStart(0)
    , _idxEnd(0)
    , _idxNext(0)
    , _idxPrevious(0)
    , _overlap(0)
    , _N(0)
{}

void Slicer::setOverlap(uint32_t overlap)
{
    _overlap = overlap;
}

void Slicer::setN(uint32_t N)
{
    _N = N > 0 ? N : 1;
}

void Slicer::setStartIndex(int idxStart)
{
    _idxStart = idxStart;
}

uint32_t Slicer::overlap()
{
    return _overlap;
}

uint32_t Slicer::N()
{
    return _N;
}

int Slicer::startIndex()
{
    return _idxStart;
}

void Slicer::_updateIdx(long size)
{
    _overlap = _overlap < _N ? _overlap : _N-1;

    long maxStart  = size-_N;
    _idxStart = _idxStart <= maxStart   ? _idxStart : maxStart;
    _idxStart = _idxStart < 0           ? 0         : _idxStart;

    _idxEnd = _idxStart + _N - 1;
    _idxEnd = _idxEnd < size ? _idxEnd : size-1;

    _idxNext = _idxEnd + 1 - _overlap;
    _idxNext = _idxNext < 0       ? 0        : _idxNext;
    _idxNext = _idxNext < size    ? _idxNext : size-1;

    _idxPrevious = _idxStart + _overlap - _N;
    _idxPrevious = _idxPrevious < 0       ? 0            : _idxPrevious;
    _idxPrevious = _idxPrevious < size    ? _idxPrevious : size-1;

//    qDebug() << "size:         " << size;
//    qDebug() << "_N:           " << _N;
//    qDebug() << "_overlap:     " << _overlap;
//    qDebug() << "_idxStart:    " << _idxStart;
//    qDebug() << "_idxEnd:      " << _idxEnd;
//    qDebug() << "_idxNext:     " << _idxNext;
//    qDebug() << "_idxPrevious: " << _idxPrevious << "\n";
}
