#include <math.h>
#include <iostream>


float* makeGridPoints(unsigned int X=2, unsigned int Y=2) {
    int numPoints = 5*X*Y;
    float xStep = 1/ ((float)(X-1));
    float yStep = 1/ ((float)(Y-1));
    float* ret = new float[numPoints];
    for (int i = 0; i < Y; i++) {
        for (int j = 0; j < X; j++) {
            ret[5*(i*X+j)] = xStep*j-0.5;
            ret[5*(i*X+j)+1] = yStep*i-0.5;
            ret[5*(i*X+j)+2] = 0.0;
            ret[5*(i*X+j)+3] = yStep*i;
            ret[5*(i*X+j)+4] = xStep*j;
        }
    }
    
    return ret;
}

unsigned int* makeGridIndex(unsigned int X=2, unsigned int Y=2) {
    unsigned int tiles = (X-1)*(Y-1);
    unsigned int* ret = new unsigned int[tiles*6];
    unsigned int tileInd;
    for (int i = 0; i < Y-1; i++) {
        for (int j = 0; j < X-1; j++) {
            tileInd = i*(X-1)+j;
            ret[6*tileInd] = i*X+j;
            ret[6*tileInd+1] = (i+1)*X+j;
            ret[6*tileInd+2] = (i+1)*X+(j+1);
            
            ret[6*tileInd+3] = i*X+j;
            ret[6*tileInd+4] = i*X+j+1;
            ret[6*tileInd+5] = (i+1)*X+(j+1);
        }
    }

    return ret;
}