#include "RotateTransition.hpp"

RotateTransition::RotateTransition(PieSlice* pDataElement, float fDeltaValue, int iTotalSteps) {
  iType = ROTATE_TRANSITION;
  bStarted = false;
  this->pDataElement = pDataElement;
  this->fDeltaValue = fDeltaValue;
  this->iTotalSteps = iTotalSteps;

  iStepsDone = 0;
}

RotateTransition::~RotateTransition() {
  while (vChildren.size() > 0) {
    std::vector<Transition*>::iterator it = vChildren.begin();

    if (it != vChildren.end()) {
      delete *it;
      vChildren.erase(it);
    }
  }

  while (vToBeDeleted.size() > 0) {
    std::vector<AlterableObject*>::iterator it = vToBeDeleted.begin();

    if (it != vToBeDeleted.end()) {
      delete *it;
      vToBeDeleted.erase(it);
    }
  }
}

void RotateTransition::Update() {
  if (!bStarted) {
    Start();
  }

  float fValueStep = fDeltaValue / iTotalSteps;

  pDataElement->Rotate(fValueStep);
  iStepsDone++;
}

bool RotateTransition::Complete() {
  if ((bStarted) && (iStepsDone >= iTotalSteps)) {
    return true;
  }
  else {
    return false;
  }
}