/*
** EPITECH PROJECT, 2018
** task01
** File description:
** I do task
*/
#include "../../include/lib/s_sfml.h"
#include "../../include/lib/my_graphics.h"

static void my_line_dx(sfml_t *sfml, int var[7], uint32_t color)
{
    int cumul;
    int i;

    i = 0;
    cumul = var[2] / 2;
    while (++i < var[2]){
        var[0] += var[4];
        cumul += var[3];
        if (cumul > var[2]){
            cumul -= var[2];
            var[1] += var[5];
        }
        my_pixel(sfml, var[0], var[1], color);
    }
}

static void my_line_dy(sfml_t *sfml, int var[7], uint32_t color)
{
    int cumul;
    int i;

    i = 0;
    cumul = var[3] / 2;
    while (++i < var[3]){
        var[1] += var[5];
        cumul += var[2];
        if (cumul > var[3]){
            cumul -= var[3];
            var[0] += var[4];
        }
        my_pixel(sfml, var[0], var[1], color);
    }
}

void my_line(sfml_t *sfml, int line[4], uint32_t color)
{
    int var[6];

    var[0] = line[0];
    var[1] = line[1];
    var[2] = line[2] - line[0];
    var[3] = line[3] - line[1];
    var[4] = (var[2] > 0) ? 1 : -1;
    var[5] = (var[3] > 0) ? 1 : -1;
    var[2] = (var[2] > 0) ? var[2] : -var[2];
    var[3] = (var[3] > 0) ? var[3] : -var[3];
    my_pixel(sfml, var[0], var[1], color);
    if (var[2] > var[3])
        my_line_dx(sfml, var, color);
    else
        my_line_dy(sfml, var, color);
}
