//    Copyright 2025 Bill Rossi
//    
//    This file is part of Hanafuda Hachi-Hachi.
//
//    Hanafuda Hachi-Hachi is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
//
//    Hanafuda Hachi-Hachi is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License along with Hanafuda Hachi-Hachi. If not, see <https://www.gnu.org/licenses/>. 
#include <math.h>
#include "move.h"

void move_position(Move *m, float delta) {
  m->current_time += delta;
  float percentage = m->current_time / m->end_time;
  if (percentage < 0.0) percentage = 0.0;
  else if (percentage > 1.0) percentage = 1.0;

  Vector2 v;
  switch (m->curve) {
  case CURVE_LINEAR:
    v = (Vector2) {
      ((m->destination.x - m->origin.x) * percentage) + m->origin.x,
      ((m->destination.y - m->origin.y) * percentage) + m->origin.y
    };
    break;
  case CURVE_EASE_IN_OUT:
    percentage = -(cos(PI * percentage) - 1) / 2;
    v = (Vector2) {
      ((m->destination.x - m->origin.x) * percentage) + m->origin.x,
      ((m->destination.y - m->origin.y) * percentage) + m->origin.y
    };
    break;
  default:
    v = m->destination;
    break;
  }

  m->position->x = v.x;
  m->position->y = v.y;
}