#ifndef MISC_H
#define MISC_H

// Miscellaneous functions that don't belong anywhere else

#include "Point.h"
#include "ICPPoint.h"
#include <vector>
#include <iostream>
#include <cstdlib>

using namespace std;

int MyRandRange(int x); // Range from [0, x-1], used with random_shuffle()

template <class T>
void reverseable_shuffle_forward(vector <T> &p, vector <unsigned int> &table)
{
    if(p.size() != table.size())
    {
        cerr << "reverseable_shuffle: size mismatch" << endl;
        exit(1);
    }

    vector <T> tmp;

    for(unsigned int i=0; i < table.size(); i++)
    {
        unsigned int pos = table[i];

        swap(p[i], p[pos]);
    }
}

template <class T>
void reverseable_shuffle_backward(vector <T> &p, vector <unsigned int> &table)
{
    if(p.size() != table.size())
    {
        cerr << "reverseable_shuffle: size mismatch" << endl;
        exit(1);
    }

    vector <T> tmp;

    for(unsigned int i=0; i < table.size(); i++)
    {
        unsigned int pos = table[table.size() - i -1];

        swap(p[table.size()-1-i], p[pos]);
    }
}

#endif
