#include "AnimationMove.h"
#include <math.h>

ARGB
AM_Linear(const Animation* anim, u32 frameIndex, ARGB pixel, i32 r, i32 c, void* priv) {
	struct AM_Linear ml = *(struct AM_Linear*)priv;

	r = (r - ml.startRow - (i32)(frameIndex * ml.dRow));
	c = (c - ml.startCol - (i32)(frameIndex * ml.dCol));

	if (ml.wrapCoordinates == true) {
		r %= anim->width;
		c %= anim->height;
	}

	return ml.callback(anim, frameIndex, pixel, r, c, ml.priv);
}

ARGB
AM_Spin(const Animation* anim, u32 frameIndex, ARGB pixel, i32 r, i32 c, void* priv) {
	struct AM_Spin ms = *(struct AM_Spin*)priv;

	double radius = sqrt(r * r + c * c);
	double phi = atan2(c, r);

	phi += ms.theta + ms.dTheta * frameIndex;

	r = (ms.centerRow + (i32)(radius * cos(phi)));
	c = (ms.centerCol + (i32)(radius * sin(phi)));

	return ms.callback(anim, frameIndex, pixel, r, c, ms.priv);
}
