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"
Toshihiro Shimizu 890ddd
//#include "ext/NotSimmetricBezierPotential.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
Toshihiro Shimizu 890ddd
StraightCornerDeformation::StraightCornerDeformation()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	setPotential(new LinearPotential);
Toshihiro Shimizu 890ddd
	shortcutKey_ = ContextStatus::CTRL;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
StraightCornerDeformation::~StraightCornerDeformation()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
bool StraightCornerDeformation::findExtremes_(const ContextStatus *status,
Toshihiro Shimizu 890ddd
											  Interval &ret)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	bool
Toshihiro Shimizu 890ddd
		found = ToonzExt::findNearestStraightCorners(status->stroke2change_,
Toshihiro Shimizu 890ddd
													 status->w_,
Toshihiro Shimizu 890ddd
													 ret,
Toshihiro Shimizu 890ddd
													 &this->getStraightsList());
Toshihiro Shimizu 890ddd
	// it is not a forced solution
Toshihiro Shimizu 890ddd
	if ((status->key_event_ != shortcutKey_) &&
Toshihiro Shimizu 890ddd
		found)
Toshihiro Shimizu 890ddd
		return found;
Toshihiro Shimizu 890ddd
	else {
Toshihiro Shimizu 890ddd
		// it is forced then probably i want to find
Toshihiro Shimizu 890ddd
		found = ToonzExt::findNearestSpireCorners(status->stroke2change_,
Toshihiro Shimizu 890ddd
												  status->w_,
Toshihiro Shimizu 890ddd
												  ret,
Toshihiro Shimizu 890ddd
												  status->cornerSize_,
Toshihiro Shimizu 890ddd
												  &this->getSpiresList());
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	return found;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void StraightCornerDeformation::draw(Designer *designer)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	StrokeDeformationImpl::draw(0);
Toshihiro Shimizu 890ddd
	designer->draw(this);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
bool StraightCornerDeformation::check_(const ContextStatus *status)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	assert(status && "Not status available");
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TStroke *s = status->stroke2change_;
Toshihiro Shimizu 890ddd
	double
Toshihiro Shimizu 890ddd
		w = status->w_;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// check extremes in another way.
Toshihiro Shimizu 890ddd
	if (!s->isSelfLoop() &&
Toshihiro Shimizu 890ddd
			areAlmostEqual(w, 0.0) ||
Toshihiro Shimizu 890ddd
		areAlmostEqual(w, 1.0)) {
Toshihiro Shimizu 890ddd
		return isAStraightCorner(s,
Toshihiro Shimizu 890ddd
								 w,
Toshihiro Shimizu 890ddd
								 &this->getStraightsList());
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	ToonzExt::Interval
Toshihiro Shimizu 890ddd
		ret;
Toshihiro Shimizu 890ddd
	if (ToonzExt::findNearestStraightCorners(status->stroke2change_,
Toshihiro Shimizu 890ddd
											 status->w_,
Toshihiro Shimizu 890ddd
											 ret,
Toshihiro Shimizu 890ddd
											 &this->getStraightsList()) &&
Toshihiro Shimizu 890ddd
		isAStraightCorner(s,
Toshihiro Shimizu 890ddd
						  w,
Toshihiro Shimizu 890ddd
						  &this->getStraightsList())) {
Toshihiro Shimizu 890ddd
		if (ret.first > ret.second) {
Toshihiro Shimizu 890ddd
			assert(s->isSelfLoop());
Toshihiro Shimizu 890ddd
			if ((ret.first < w &&
Toshihiro Shimizu 890ddd
				 w <= 1.0) ||
Toshihiro Shimizu 890ddd
				(0.0 <= w &&
Toshihiro Shimizu 890ddd
				 w < ret.second))
Toshihiro Shimizu 890ddd
				return true;
Toshihiro Shimizu 890ddd
		} else {
Toshihiro Shimizu 890ddd
			if (ret.first < w &&
Toshihiro Shimizu 890ddd
				w < ret.second)
Toshihiro Shimizu 890ddd
				return true;
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	return false;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
double
Toshihiro Shimizu 890ddd
StraightCornerDeformation::findActionLength()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	return stroke2manipulate_->getLength();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
StraightCornerDeformation *
Toshihiro Shimizu 890ddd
StraightCornerDeformation::instance()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	static StraightCornerDeformation singleton;
Toshihiro Shimizu 890ddd
	return &singleton;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
//  End Of File
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------