#include "fastmath.hpp"
#include "polygon.hpp"
#include <QApplication>
#include <QImage>
#include <QLabel>
#include <QPixmap>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
// testing fastmath.h
/*
void test(vec<2> *in) {
    vec<2> v = {{decimal(1.0), decimal(0.5)}};
    in = &v;
}*/

int main(int argc, char *argv[]) {
    vec3 v1 = vec3(5.0f, 40.0f, 2.0f);
    vec3 v2 = vec3(5.0, 10.0, 2.2);
    vec3 v3 = v1;
    std::cout << v1 << v2 << decimal(0.5) * v2 << (v1 + v2) << v1 * v2 << "\n"
              << v1.cross(v2) << v1.len() << "\n"
              << v1.normalize() << std::endl;

    decimal d = decimal(2.0f);
    d += decimal(0.5);
    std::cout << "\n"
              << decimal(2.0) / decimal(-0.5) << "\n"
              << decimal(2.0).sqrt() << "\n"
              << d << std::endl;

    polygon p = {vec3(0.0, 0.0, 0.0), vec3(0.0, 1.0, 0.0), vec3(1.0, 0.0, 0.0)};
    std::cout << p.contains(vec3(0.1, 0.1, 0.1)) << std::endl;

    mat4 m = mat4::translation({2.0f, 3.0f, 5.0f});

    std::cout << matN<3>::identity() * v1 << std::endl;
    std::cout << m << std::endl;
    std::cout << mat4::identity().cutTo<mat3>() << std::endl;
    std::cout << m * vec4(v1, decimal(1.0f)) << std::endl;
    std::cout << mat4::rotateOnX(1.5707f) * vec4(1.f, 0.f, 0.f, 0.f)
              << std::endl;

    // QApplication a(argc, argv);
    //
    // uint8_t *pixel = new uint8_t[64 * 64 * 3];
    //
    // for (int i = 1; i < 64 * 64 * 3; i += 3) {
    //     pixel[i] = 255;
    // }
    //
    // QWidget widget;
    // widget.setAutoFillBackground(true);
    // widget.setGeometry(0, 0, 500, 500);
    // QLabel display(&widget);
    // QImage img((unsigned char *)pixel, 64, 64, QImage::Format_RGB888);
    // display.setPixmap(QPixmap::fromImage(img).scaled(widget.size()));
    // widget.show();
    // return a.exec();
}
