#include "sprite.h"

sprite *make_sprite(void)
{
  sprite *sprite = calloc(sizeof(*sprite),1);
  sprite->image = JS_NULL;
  return sprite;
}

void sprite_free(JSRuntime *rt, sprite *sprite)
{
  JS_FreeValueRT(rt,sprite->image);
  free(sprite);
}

void sprite_apply(sprite *sp)
{
  /* -------- rotation + skew → 2×2 affine matrix -------- */
  float  rot = sp->rotation;
  HMM_Vec2 k = sp->skew;

  float c = cosf(rot), s = sinf(rot);

  sp->affine.Columns[0] = (HMM_Vec2){ .x =  c + k.x * s,
                                      .y =  k.y * c + s };
  sp->affine.Columns[1] = (HMM_Vec2){ .x = -s + k.x * c,
                                      .y = -k.y * s + c };
}

