tahoma2d/toonz/sources/tnzext/Potential.cpp

56 lines
1.5 KiB
C++
Raw Normal View History

2016-03-19 06:57:51 +13:00
#include "ext/Potential.h"
#include <algorithm>
#if defined(_MSC_VER) && (_MSC_VER <= 1200)
2016-03-19 06:57:51 +13:00
#pragma warning(push)
#pragma warning(disable : 4290)
#endif
//-----------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
ToonzExt::Potential::Potential() { isValid_ = false; }
2016-03-19 06:57:51 +13:00
//-----------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
void ToonzExt::Potential::setParameters(const TStroke *ref, double w,
double actionLength) {
isValid_ = true;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
assert(ref);
if (!ref) throw std::invalid_argument("Not valid stroke!!!");
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
assert(actionLength != 0.0);
if (actionLength == 0.0) actionLength = TConsts::epsilon;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
assert(0.0 <= w && w <= 1.0);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
if (0.0 > w || w > 1.0) {
throw std::invalid_argument("Not valid parameter!!!");
// w = std::min(std::max(0.0,w),1.0);
}
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
this->setParameters_(ref, w, actionLength);
2016-03-19 06:57:51 +13:00
}
//-----------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
double ToonzExt::Potential::value(double at) const {
if (!isValid_) throw std::range_error("Not yet initialized potential!");
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
assert(0.0 <= at && at <= 1.0);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
if (0 > at || at > 1.0) at = std::min(std::max(at, 0.0), 1.0);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
return this->value_(at);
2016-03-19 06:57:51 +13:00
}
//-----------------------------------------------------------------------------
// End Of File
//-----------------------------------------------------------------------------
#if defined(_MSC_VER) && (_MSC_VER <= 1200)
2016-03-19 06:57:51 +13:00
#pragma warning(pop)
#endif