#include <cmath>
#include <render/render.h>
#include "image.h"
namespace render{
namespace sprite{
image::image():scale(1),color(1),parts(1){}

image::image(const std::string& path, bool smooth):image()
{
    texture::load(path, smooth, 1);
}

image::~image()
{
    free();
}

bool image::load(const std::string&path,bool filter)
{
    return texture::load(path,filter,1);
}

vec4f image::getTexCoord(uint32_t part) const noexcept
{
    std::ldiv_t result = std::ldiv(part, parts.x);
    return vec4f(
        float(result.rem)/parts.x,
        float(result.quot)/parts.y,
        vec2f(1)/parts
    );
}

void image::draw(const vec2f &pos, uint32_t part) const noexcept
{
    std::ldiv_t result = std::ldiv(part, parts.x);
    draw(pos, vec2u32(result.rem, result.quot));
}
}}

