Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "ext/Potential.h"
Toshihiro Shimizu 890ddd
#include <algorithm></algorithm>
Toshihiro Shimizu 890ddd
e280ae
#if defined(_MSC_VER) && (_MSC_VER <= 1200)
Toshihiro Shimizu 890ddd
#pragma warning(push)
Toshihiro Shimizu 890ddd
#pragma warning(disable : 4290)
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
ToonzExt::Potential::Potential() { isValid_ = false; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void ToonzExt::Potential::setParameters(const TStroke *ref, double w,
Shinya Kitaoka 120a6e
                                        double actionLength) {
Shinya Kitaoka 120a6e
  isValid_ = true;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  assert(ref);
Shinya Kitaoka 120a6e
  if (!ref) throw std::invalid_argument("Not valid stroke!!!");
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  assert(actionLength != 0.0);
Shinya Kitaoka 120a6e
  if (actionLength == 0.0) actionLength = TConsts::epsilon;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  assert(0.0 <= w && w <= 1.0);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (0.0 > w || w > 1.0) {
Shinya Kitaoka 120a6e
    throw std::invalid_argument("Not valid parameter!!!");
Shinya Kitaoka 120a6e
    //  w = std::min(std::max(0.0,w),1.0);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  this->setParameters_(ref, w, actionLength);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
double ToonzExt::Potential::value(double at) const {
Shinya Kitaoka 120a6e
  if (!isValid_) throw std::range_error("Not yet initialized potential!");
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  assert(0.0 <= at && at <= 1.0);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (0 > at || at > 1.0) at = std::min(std::max(at, 0.0), 1.0);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  return this->value_(at);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
//  End Of File
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
e280ae
#if defined(_MSC_VER) && (_MSC_VER <= 1200)
Toshihiro Shimizu 890ddd
#pragma warning(pop)
Toshihiro Shimizu 890ddd
#endif