|
|
7a5892 |
|
|
|
7a5892 |
|
|
|
7a5892 |
#include <tools modifierline.h="" modifiers=""></tools>
|
|
|
7a5892 |
|
|
|
fa009d |
|
|
|
fa009d |
|
|
|
7a5892 |
//*****************************************************************************************
|
|
|
7a5892 |
// TModifierLine implementation
|
|
|
7a5892 |
//*****************************************************************************************
|
|
|
7a5892 |
|
|
|
fa009d |
|
|
|
7a5892 |
static inline void calcFixedAngle(const TTrackPoint &p0, TTrackPoint &p1) {
|
|
|
7a5892 |
TPointD p = p1.position - p0.position;
|
|
shun-iwasawa |
87c65e |
double l = sqrt(p.x * p.x + p.y * p.y);
|
|
|
7a5892 |
if (l < TConsts::epsilon) {
|
|
|
7a5892 |
p = TPointD();
|
|
|
7a5892 |
} else {
|
|
|
7a5892 |
double a = atan2(p.y, p.x);
|
|
shun-iwasawa |
87c65e |
a = round(a * 4 / M_PI) * M_PI / 4;
|
|
shun-iwasawa |
87c65e |
p.x = cos(a) * l;
|
|
shun-iwasawa |
87c65e |
p.y = sin(a) * l;
|
|
|
7a5892 |
}
|
|
|
7a5892 |
p1.position = p0.position + p;
|
|
|
7a5892 |
}
|
|
|
7a5892 |
|
|
|
7a5892 |
|
|
shun-iwasawa |
87c65e |
void TModifierLine::modifyTrack(const TTrack &track,
|
|
shun-iwasawa |
87c65e |
TTrackList &outTracks) {
|
|
|
7a5892 |
if (!track.handler) {
|
|
|
fa009d |
Handler *handler = new Handler();
|
|
|
fa009d |
track.handler = handler;
|
|
|
fa009d |
handler->track = new TTrack(track);
|
|
|
7a5892 |
}
|
|
|
7a5892 |
|
|
|
fa009d |
Handler *handler = dynamic_cast<handler*>(track.handler.getPointer());</handler*>
|
|
|
fa009d |
if (!handler)
|
|
|
fa009d |
return;
|
|
|
fa009d |
|
|
|
fa009d |
outTracks.push_back(handler->track);
|
|
|
fa009d |
TTrack &subTrack = *handler->track;
|
|
|
fa009d |
|
|
|
fa009d |
if (!track.changed())
|
|
|
7a5892 |
return;
|
|
shun-iwasawa |
87c65e |
|
|
|
fa009d |
subTrack.truncate(0);
|
|
|
7a5892 |
|
|
|
fa009d |
// calc max pressure
|
|
shun-iwasawa |
87c65e |
int i1 = track.size();
|
|
shun-iwasawa |
87c65e |
int i0 = i1 - track.pointsAdded;
|
|
|
fa009d |
double maxPressure = handler->maxPressure;
|
|
shun-iwasawa |
87c65e |
if (track.pointsRemoved) {
|
|
shun-iwasawa |
87c65e |
maxPressure = 0;
|
|
shun-iwasawa |
87c65e |
i0 = 0;
|
|
shun-iwasawa |
87c65e |
}
|
|
|
fa009d |
for(int i = i0; i < i1; ++i) {
|
|
|
7a5892 |
double p = track[i].pressure;
|
|
|
7a5892 |
if (maxPressure < p) maxPressure = p;
|
|
|
7a5892 |
}
|
|
|
fa009d |
handler->maxPressure = maxPressure;
|
|
|
fa009d |
|
|
|
fa009d |
if (track.size() > 0)
|
|
|
fa009d |
subTrack.push_back(subTrack.pointFromOriginal(0), false);
|
|
|
fa009d |
|
|
|
7a5892 |
if (track.size() > 1) {
|
|
|
fa009d |
TTrackPoint p = subTrack.pointFromOriginal(track.size() - 1);
|
|
|
fa009d |
if (track.getKeyState(track.back()).isPressed(TKey::control))
|
|
|
fa009d |
calcFixedAngle(subTrack.front(), p);
|
|
|
f278a5 |
subTrack.push_back(p, false);
|
|
|
7a5892 |
}
|
|
|
fa009d |
|
|
|
f278a5 |
if (track.fixedFinished())
|
|
|
f278a5 |
subTrack.fix_all();
|
|
|
f278a5 |
|
|
|
7a5892 |
track.resetChanges();
|
|
|
7a5892 |
}
|