Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifdef _DEBUG
Toshihiro Shimizu 890ddd
#define _STLP_DEBUG 1
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
#include "ext/StraightCornerDeformation.h"
Toshihiro Shimizu 890ddd
#include "ext/StrokeDeformation.h"
Toshihiro Shimizu 890ddd
#include "ext/LinearPotential.h"
Toshihiro Shimizu 890ddd
//#include "ext/StrokeParametricDeformer.h"
MCCCS a0ce32
//#include "ext/NotSymmetricBezierPotential.h"
Toshihiro Shimizu 890ddd
#include "ext/ContextStatus.h"
Toshihiro Shimizu 890ddd
#include "ext/Designer.h"
Toshihiro Shimizu 890ddd
//#include "ext/TriParam.h"
Toshihiro Shimizu 890ddd
#include "ext/ExtUtil.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "DeformationSelector.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//#include <tcurves.h></tcurves.h>
Toshihiro Shimizu 890ddd
//#include <tstrokeutil.h></tstrokeutil.h>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include <algorithm></algorithm>
Toshihiro Shimizu 890ddd
#include <iterator></iterator>
Toshihiro Shimizu 890ddd
#include <vector></vector>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include <tstroke.h></tstroke.h>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
using namespace ToonzExt;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
REGISTER(StraightCornerDeformation, 3);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
StraightCornerDeformation::StraightCornerDeformation() {
Shinya Kitaoka 120a6e
  setPotential(new LinearPotential);
Shinya Kitaoka 120a6e
  shortcutKey_ = ContextStatus::CTRL;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
StraightCornerDeformation::~StraightCornerDeformation() {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
bool StraightCornerDeformation::findExtremes_(const ContextStatus *status,
Shinya Kitaoka 120a6e
                                              Interval &ret) {
Shinya Kitaoka 120a6e
  bool found = ToonzExt::findNearestStraightCorners(
Shinya Kitaoka 120a6e
      status->stroke2change_, status->w_, ret, &this->getStraightsList());
Shinya Kitaoka 120a6e
  // it is not a forced solution
Shinya Kitaoka 120a6e
  if ((status->key_event_ != shortcutKey_) && found)
Shinya Kitaoka 120a6e
    return found;
Shinya Kitaoka 120a6e
  else {
Shinya Kitaoka 120a6e
    // it is forced then probably i want to find
Shinya Kitaoka 120a6e
    found = ToonzExt::findNearestSpireCorners(
Shinya Kitaoka 120a6e
        status->stroke2change_, status->w_, ret, status->cornerSize_,
Shinya Kitaoka 120a6e
        &this->getSpiresList());
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  return found;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void StraightCornerDeformation::draw(Designer *designer) {
Shinya Kitaoka 120a6e
  StrokeDeformationImpl::draw(0);
Shinya Kitaoka 120a6e
  designer->draw(this);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
bool StraightCornerDeformation::check_(const ContextStatus *status) {
Shinya Kitaoka 120a6e
  assert(status && "Not status available");
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TStroke *s = status->stroke2change_;
Shinya Kitaoka 120a6e
  double w   = status->w_;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // check extremes in another way.
Shinya Kitaoka 120a6e
  if (!s->isSelfLoop() && areAlmostEqual(w, 0.0) || areAlmostEqual(w, 1.0)) {
Shinya Kitaoka 120a6e
    return isAStraightCorner(s, w, &this->getStraightsList());
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  ToonzExt::Interval ret;
Shinya Kitaoka 120a6e
  if (ToonzExt::findNearestStraightCorners(status->stroke2change_, status->w_,
Shinya Kitaoka 120a6e
                                           ret, &this->getStraightsList()) &&
Shinya Kitaoka 120a6e
      isAStraightCorner(s, w, &this->getStraightsList())) {
Shinya Kitaoka 120a6e
    if (ret.first > ret.second) {
Shinya Kitaoka 120a6e
      assert(s->isSelfLoop());
Shinya Kitaoka 120a6e
      if ((ret.first < w && w <= 1.0) || (0.0 <= w && w < ret.second))
Shinya Kitaoka 120a6e
        return true;
Shinya Kitaoka 120a6e
    } else {
Shinya Kitaoka 120a6e
      if (ret.first < w && w < ret.second) return true;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  return false;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
double StraightCornerDeformation::findActionLength() {
Shinya Kitaoka 120a6e
  return stroke2manipulate_->getLength();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
StraightCornerDeformation *StraightCornerDeformation::instance() {
Shinya Kitaoka 120a6e
  static StraightCornerDeformation singleton;
Shinya Kitaoka 120a6e
  return &singleton;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
//  End Of File
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------