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

static void my_circle_line(sfml_t *sfml,
int circle[3], int var[4], uint32_t color)
{
    int h_line[3];

    if (var[1] >= var[0]){
        h_line[0] = circle[1] + var[0];
        h_line[1] = circle[0] - var[1];
        h_line[2] = circle[0] + var[1];
        my_horizontal_line(sfml, h_line, color);
        h_line[0] = circle[1] - var[0];
        my_horizontal_line(sfml, h_line, color);
    }
}

static void my_var_init(int var[], int circle[3])
{
    var[0] = 0;
    var[1] = circle[2];
}

static void draw_line_circle(sfml_t *sfml,
int circle[3], int var[4], uint32_t color)
{
    int h_line[3];

    h_line[0] = circle[1] + var[1] + 1;
    h_line[1] = circle[0] - var[0];
    h_line[2] = circle[0] + var[0];
    my_horizontal_line(sfml, h_line, color);
    h_line[0] = circle[1] - var[1] - 1;
    my_horizontal_line(sfml, h_line, color);
}

void my_filled_circle(sfml_t *sfml, int circle[3], uint32_t color)
{
    int h_line[4] = {circle[1], circle[0] - circle[2],
        circle[0] + circle[2]};
    int tmp = 1 - circle[2];
    int var[4];

    if (circle[2] < 0)
        return;
    my_var_init(var, circle);
    my_horizontal_line(sfml, h_line, color);
    while (var[1] > var[0]){
        if (tmp < 0)
            tmp += (var[0] << 1) + 3;
        else {
            tmp += ((var[0]-var[1]) << 1) + 5;
            var[1]--;
            draw_line_circle(sfml, circle, var, color);
        }
        var[0]++;
        my_circle_line(sfml, circle, var, color);
    }
}
