From 9f0c16070d0703ecfe9efc651c553d90ab0c1f81 Mon Sep 17 00:00:00 2001 From: Ivan Mahonin Date: May 01 2023 07:52:45 +0000 Subject: #assistants: fix bugs --- diff --git a/toonz/sources/include/tools/modifiers/modifiertangents.h b/toonz/sources/include/tools/modifiers/modifiertangents.h index 907aa05..8817a83 100644 --- a/toonz/sources/include/tools/modifiers/modifiertangents.h +++ b/toonz/sources/include/tools/modifiers/modifiertangents.h @@ -37,6 +37,8 @@ public: TTrackPoint calcPoint(double originalIndex) override; }; + TTrackTangent calcLastTangent(const TTrack &track) const; + void modifyTrack( const TTrack &track, const TInputSavePoint::Holder &savePoint, diff --git a/toonz/sources/include/tools/modifiers/modifiertest.h b/toonz/sources/include/tools/modifiers/modifiertest.h index f44eb29..32ab86d 100644 --- a/toonz/sources/include/tools/modifiers/modifiertest.h +++ b/toonz/sources/include/tools/modifiers/modifiertest.h @@ -46,7 +46,7 @@ public: const int count; const double radius; - TModifierTest(); + TModifierTest(int count, double radius); void modifyTrack( const TTrack &track, diff --git a/toonz/sources/include/tools/track.h b/toonz/sources/include/tools/track.h index eff0c65..dd83e29 100644 --- a/toonz/sources/include/tools/track.h +++ b/toonz/sources/include/tools/track.h @@ -145,8 +145,6 @@ class DVAPI TTrack : public TSmartObject { public: typedef long long Id; - static const double epsilon; - private: static Id m_lastId; @@ -196,11 +194,11 @@ public: inline int clampIndex(int index) const { return std::min(std::max(index, 0), size() - 1); } inline int floorIndexNoClamp(double index) const - { return (int)floor(index + epsilon); } + { return (int)floor(index + TConsts::epsilon); } inline int floorIndex(double index) const { return clampIndex(floorIndexNoClamp(index)); } inline int ceilIndexNoClamp(double index) const - { return (int)ceil(index - epsilon); } + { return (int)ceil(index - TConsts::epsilon); } inline int ceilIndex(double index) const { return clampIndex(ceilIndexNoClamp(index)); } @@ -249,13 +247,13 @@ public: inline TInputState::KeyState::Holder getKeyState(const TTrackPoint &point) const { return getKeyState(timeOffset() + point.time); } inline TInputState::KeyState::Holder getCurrentKeyState() const - { return getKeyState(current().time); } + { return getKeyState(timeOffset() + current().time); } inline TInputState::ButtonState::Holder getButtonState(double time) const { return buttonHistory.get(time); } inline TInputState::ButtonState::Holder getButtonState(const TTrackPoint &point) const { return getButtonState(timeOffset() + point.time); } inline TInputState::ButtonState::Holder getCurrentButtonState() const - { return getButtonState(current().time); } + { return getButtonState(timeOffset() + current().time); } private: template @@ -264,18 +262,18 @@ private: if (m_points.empty()) return 0.0; int a = 0; double aa = m_points[a].*Field; - if (value - aa <= 0.5*epsilon) return (double)a; + if (value - aa <= 0.5*TConsts::epsilon) return (double)a; int b = (int)m_points.size() - 1; double bb = m_points[b].*Field; - if (bb - value <= 0.5*epsilon) return (double)b; + if (bb - value <= 0.5*TConsts::epsilon) return (double)b; while(true) { int c = (a + b)/2; if (a == c) break; double cc = m_points[c].*Field; - if (cc - value > 0.5*epsilon) + if (cc - value > 0.5*TConsts::epsilon) { b = c; bb = cc; } else { a = c; aa = cc; } } - return bb - aa >= 0.5*epsilon ? (double)a + (value - aa)/(bb - aa) : (double)a; + return bb - aa >= 0.5*TConsts::epsilon ? (double)a + (value - aa)/(bb - aa) : (double)a; } public: @@ -332,8 +330,8 @@ public: } static inline TTrackPoint interpolationLinear(const TTrackPoint &p0, const TTrackPoint &p1, double l) { - if (l <= epsilon) return p0; - if (l >= 1.0 - epsilon) return p1; + if (l <= TConsts::epsilon) return p0; + if (l >= 1.0 - TConsts::epsilon) return p1; return TTrackPoint( interpolationLinear(p0.position , p1.position , l), interpolationLinear(p0.pressure , p1.pressure , l), @@ -350,12 +348,14 @@ public: const TTrackTangent &t1, double l ) { - if (l <= epsilon) return p0; - if (l >= 1.0 - epsilon) return p1; + if (l <= TConsts::epsilon) return p0; + if (l >= 1.0 - TConsts::epsilon) return p1; return TTrackPoint( interpolationSpline(p0.position , p1.position , t0.position , t1.position , l), - interpolationSpline(p0.pressure , p1.pressure , t0.pressure , t1.pressure , l), - interpolationSpline(p0.tilt , p1.tilt , t0.tilt , t1.tilt , l), + interpolationLinear(p0.pressure , p1.pressure , l), + //interpolationSpline(p0.pressure , p1.pressure , t0.pressure , t1.pressure , l), + interpolationLinear(p0.tilt , p1.tilt , l), + //interpolationSpline(p0.tilt , p1.tilt , t0.tilt , t1.tilt , l), interpolationLinear(p0.originalIndex , p1.originalIndex , l), interpolationLinear(p0.time , p1.time , l), interpolationLinear(p0.length , p1.length , l) ); diff --git a/toonz/sources/tnztools/assistant.cpp b/toonz/sources/tnztools/assistant.cpp index f245002..69e5ac8 100644 --- a/toonz/sources/tnztools/assistant.cpp +++ b/toonz/sources/tnztools/assistant.cpp @@ -56,7 +56,7 @@ TGuideline::calcTrackWeight(const TTrack &track, const TAffine &toScreen, bool & sumLength += length; double midStepLength = sumLength - 0.5*length; - if (midStepLength > TTrack::epsilon) { + if (midStepLength > TConsts::epsilon) { double weight = length*logNormalDistribuitionUnscaled(midStepLength, snapLenght, snapScale); sumWeight += weight; @@ -69,7 +69,7 @@ TGuideline::calcTrackWeight(const TTrack &track, const TAffine &toScreen, bool & if (sumLength >= maxLength) { outLongEnough = true; break; } } - return sumWeight > TTrack::epsilon + return sumWeight > TConsts::epsilon ? sumDeviation/sumWeight : std::numeric_limits::infinity(); } diff --git a/toonz/sources/tnztools/fullcolorbrushtool.cpp b/toonz/sources/tnztools/fullcolorbrushtool.cpp index ff80a93..771a9d6 100644 --- a/toonz/sources/tnztools/fullcolorbrushtool.cpp +++ b/toonz/sources/tnztools/fullcolorbrushtool.cpp @@ -135,7 +135,7 @@ FullColorBrushTool::FullColorBrushTool(std::string name) bind(TTool::RasterImage | TTool::EmptyTarget); m_inputmanager.setHandler(this); - m_modifierTest = new TModifierTest(); + m_modifierTest = new TModifierTest(5, 40); m_modifierTangents = new TModifierTangents(); m_modifierAssistants = new TModifierAssistants(); m_modifierSegmentation = new TModifierSegmentation(0.25); diff --git a/toonz/sources/tnztools/inputmanager.cpp b/toonz/sources/tnztools/inputmanager.cpp index 3930177..1ddbf00 100644 --- a/toonz/sources/tnztools/inputmanager.cpp +++ b/toonz/sources/tnztools/inputmanager.cpp @@ -10,6 +10,7 @@ // static members //***************************************************************************************** +static const bool debugInputManager = false; TInputState::TouchId TInputManager::m_lastTouchId = 0; @@ -584,13 +585,16 @@ TInputManager::keyEvent( TTimerTicks ticks, QKeyEvent *event ) { + bool wasPressed = state.isKeyPressed(key); ticks = fixTicks(ticks); state.keyEvent(press, key, ticks); processTracks(); bool result = m_handler && m_handler->inputKeyEvent(press, key, event, *this); - touchTracks(); - processTracks(); - //hoverEvent(getInputHovers()); + if (wasPressed != press) { + touchTracks(); + processTracks(); + //hoverEvent(getInputHovers()); + } return result; } @@ -602,12 +606,16 @@ TInputManager::buttonEvent( TInputState::Button button, TTimerTicks ticks ) { + bool wasPressed = state.isButtonPressed(deviceId, button); ticks = fixTicks(ticks); state.buttonEvent(press, deviceId, button, ticks); processTracks(); if (m_handler) m_handler->inputButtonEvent(press, deviceId, button, *this); - touchTracks(); - processTracks(); + if (wasPressed != press) { + touchTracks(); + processTracks(); + //hoverEvent(getInputHovers()); + } } @@ -630,6 +638,9 @@ TInputManager::hoverEvent(const THoverList &hovers) { TRectD TInputManager::calcDrawBounds() { + if (debugInputManager) + return TConsts::infiniteRectD; + TRectD bounds; for(int i = 0; i < (int)m_modifiers.size(); ++i) bounds += m_modifiers[i]->calcDrawBounds(m_tracks[i], m_hovers[i]); @@ -657,7 +668,7 @@ TInputManager::calcDrawBounds() { void TInputManager::draw() { // paint not sent sub-tracks - if (m_savePointsSent < (int)m_savePoints.size()) { + if (debugInputManager || m_savePointsSent < (int)m_savePoints.size()) { glPushAttrib(GL_ALL_ATTRIB_BITS); tglEnableBlending(); tglEnableLineSmooth(true, 0.5); @@ -667,11 +678,12 @@ TInputManager::draw() { for(TTrackList::const_iterator ti = getOutputTracks().begin(); ti != getOutputTracks().end(); ++ti) { TTrack &track = **ti; if (TrackHandler *handler = dynamic_cast(track.handler.getPointer())) { - int start = handler->saves[m_savePointsSent] - 1; + int start = debugInputManager ? 0 : handler->saves[m_savePointsSent] - 1; if (start < 0) start = 0; if (start + 1 < track.size()) { int level = m_savePointsSent; colorBlack[3] = (colorWhite[3] = 0.8); + double radius = 2.0; for(int i = start + 1; i < track.size(); ++i) { while(level < (int)handler->saves.size() && handler->saves[level] <= i) colorBlack[3] = (colorWhite[3] *= 0.8), ++level; @@ -682,12 +694,20 @@ TInputManager::draw() { double k = norm2(d); if (k > TConsts::epsilon*TConsts::epsilon) { - double k = 0.5*pixelSize/sqrt(k); + k = 0.5*pixelSize/sqrt(k); d = TPointD(-k*d.y, k*d.x); glColor4dv(colorWhite); tglDrawSegment(a - d, b - d); glColor4dv(colorBlack); tglDrawSegment(a + d, b + d); + radius = 2.0; + } else { + radius += 2.0; + } + + if (debugInputManager) { + glColor4d(0.0, 0.0, 0.0, 0.25); + tglDrawCircle(b, radius*pixelSize); } } } diff --git a/toonz/sources/tnztools/modifiers/modifierassistants.cpp b/toonz/sources/tnztools/modifiers/modifierassistants.cpp index 60001dd..c2f040f 100644 --- a/toonz/sources/tnztools/modifiers/modifierassistants.cpp +++ b/toonz/sources/tnztools/modifiers/modifierassistants.cpp @@ -12,6 +12,7 @@ #include #include #include +#include // TnzCore includes #include @@ -59,24 +60,29 @@ TModifierAssistants::scanAssistants( if (TTool *tool = handler->inputGetTool()) if (TToolViewer *viewer = tool->getViewer()) if (TApplication *application = tool->getApplication()) + if (TXshLevelHandle *levelHandle = application->getCurrentLevel()) + if (TXshLevel *level = levelHandle->getLevel()) + if (TXshSimpleLevel *simpleLevel = level->getSimpleLevel()) if (TFrameHandle *frameHandle = application->getCurrentFrame()) if (TXsheetHandle *XsheetHandle = application->getCurrentXsheet()) if (TXsheet *Xsheet = XsheetHandle->getXsheet()) { + TPointD dpiScale = getCurrentDpiScale(simpleLevel, tool->getCurrentFid()); bool findGuidelines = (positions && positionsCount > 0 && outGuidelines); bool doSomething = findGuidelines || draw; int frame = frameHandle->getFrame(); int count = Xsheet->getColumnCount(); TAffine worldToTrack = viewer->getViewMatrix(); + worldToTrack.a11 /= dpiScale.x; + worldToTrack.a22 /= dpiScale.y; for(int i = 0; i < count; ++i) if (TImageP image = Xsheet->getCell(frame, i).getImage(false)) if (image->getType() == TImage::META) if (TMetaImage *metaImage = dynamic_cast(image.getPointer())) { - TAffine imageToTrack = tool->getColumnMatrix(i) - * worldToTrack; + TAffine imageToTrack = worldToTrack * tool->getColumnMatrix(i); if (draw) { glPushMatrix(); tglMultMatrix(imageToTrack); } TMetaImage::Reader reader(*metaImage); diff --git a/toonz/sources/tnztools/modifiers/modifiersegmentation.cpp b/toonz/sources/tnztools/modifiers/modifiersegmentation.cpp index dc00b39..ffde794 100644 --- a/toonz/sources/tnztools/modifiers/modifiersegmentation.cpp +++ b/toonz/sources/tnztools/modifiers/modifiersegmentation.cpp @@ -10,8 +10,8 @@ TModifierSegmentation::TModifierSegmentation(double precision): - precision(std::max(TTrack::epsilon, precision)), - precisionSqr(this->precision * this->precision) + precision(std::max(TConsts::epsilon, precision)), + precisionSqr(std::max(TConsts::epsilon, precision) * std::max(TConsts::epsilon, precision)) { } @@ -49,16 +49,19 @@ TModifierSegmentation::modifyTrack( new TTrackModifier(*track.handler) )); } - if (!track.changed() || track.handler->tracks.empty()) + if (track.handler->tracks.empty()) return; TTrack &subTrack = *track.handler->tracks.front(); outTracks.push_back(track.handler->tracks.front()); + if (!track.changed()) + return; + // remove points int start = track.size() - track.pointsAdded; if (start < 0) start = 0; - int subStart = subTrack.ceilIndex(subTrack.indexByOriginalIndex(start-1)) + 1; + int subStart = subTrack.floorIndex(subTrack.indexByOriginalIndex(start-1)) + 1; subTrack.truncate(subStart); // add points diff --git a/toonz/sources/tnztools/modifiers/modifiertangents.cpp b/toonz/sources/tnztools/modifiers/modifiertangents.cpp index 1dab9cc..f71c56e 100644 --- a/toonz/sources/tnztools/modifiers/modifiertangents.cpp +++ b/toonz/sources/tnztools/modifiers/modifiertangents.cpp @@ -13,13 +13,22 @@ TModifierTangents::Modifier::calcPoint(double originalIndex) { double frac; int i0 = original.floorIndex(originalIndex, &frac); int i1 = original.ceilIndex(originalIndex); - TTrackPoint p = i0 < 0 ? TTrackPoint() - : TTrack::interpolationSpline( - original[i0], - original[i1], - i0 < (int)tangents.size() ? tangents[i0] : TTrackTangent(), - i1 < (int)tangents.size() ? tangents[i1] : TTrackTangent(), - frac ); + + TTrackPoint p; + if (i0 >= 0) { + // calculate tangent length to make monotonic subdivisions, + // (because we don't have valid input time) + const TTrackPoint &p0 = original[i0]; + const TTrackPoint &p1 = original[i1]; + TTrackTangent t0 = i0 < (int)tangents.size() ? tangents[i0] : TTrackTangent(); + TTrackTangent t1 = i1 < (int)tangents.size() ? tangents[i1] : TTrackTangent(); + double l = fabs(p1.length - p0.length); + t0.position.x *= l; + t0.position.y *= l; + t1.position.x *= l; + t1.position.y *= l; + p = TTrack::interpolationSpline(p0, p1, t0, t1, frac); + } p.originalIndex = originalIndex; return p; } @@ -30,6 +39,22 @@ TModifierTangents::Modifier::calcPoint(double originalIndex) { //***************************************************************************************** +TTrackTangent +TModifierTangents::calcLastTangent(const TTrack &track) const { + if (track.size() < 2) return TTrackTangent(); + const TTrackPoint &p0 = track[track.size() - 2]; + const TTrackPoint &p1 = track.back(); + + // calculate tangent (with normalized position) + // with valid points time normalization does not required + double dl = p1.length - p0.length; + return TTrackTangent( + dl > TConsts::epsilon ? (p1.position - p0.position)*(1.0/dl) : TPointD(), + p1.pressure - p0.pressure, + p1.tilt - p0.tilt ); +} + + void TModifierTangents::modifyTrack( const TTrack &track, @@ -60,7 +85,7 @@ TModifierTangents::modifyTrack( if (!track.changed() && subTrack.size() == track.size() - 1) { // add temporary point - modifier->tangents.push_back(TTrackTangent()); + modifier->tangents.push_back(calcLastTangent(track)); subTrack.push_back(track.back()); } else { // apply permanent changes @@ -85,19 +110,35 @@ TModifierTangents::modifyTrack( } // add points with tangents - while(index < track.size() - 1) { - const TTrackPoint &p0 = track[index-1]; - const TTrackPoint &p1 = track[index]; - const TTrackPoint &p2 = track[index+1]; - double dt = p2.time - p0.time; - double k = dt > TTrack::epsilon ? (p1.time - p0.time)/dt : 0.5; - TTrackTangent tangent( - (p2.position - p0.position)*k, - (p2.pressure - p0.pressure)*k, - (p2.tilt - p0.tilt)*k ); - modifier->tangents.push_back(tangent); - subTrack.push_back(p1); - ++index; + if (track.size() > 2) { + while(index < track.size() - 1) { + const TTrackPoint &p0 = track[index-1]; + const TTrackPoint &p1 = track[index]; + const TTrackPoint &p2 = track[index+1]; + + // calculate tangents length by time + // for that we need read time of user input + // instead of time when message dispatched + //double dt = p2.time - p0.time; + //double k = dt > TConsts::epsilon ? (p1.time - p0.time)/dt : 0.0; + //TTrackTangent tangent( + // (p2.position - p0.position)*k, + // (p2.pressure - p0.pressure)*k, + // (p2.tilt - p0.tilt)*k ); + + // calculate tangent (with normalized position) + TPointD d = p2.position - p0.position; + double k = norm2(d); + k = k > TConsts::epsilon*TConsts::epsilon ? 1.0/sqrt(k) : 0.0; + TTrackTangent tangent( + d*k, + (p2.pressure - p0.pressure)*0.5, + (p2.tilt - p0.tilt)*0.5 ); + + modifier->tangents.push_back(tangent); + subTrack.push_back(p1); + ++index; + } } track.resetChanges(); @@ -107,7 +148,7 @@ TModifierTangents::modifyTrack( if (track.finished()) { // finish - modifier->tangents.push_back(TTrackTangent()); + modifier->tangents.push_back(calcLastTangent(track)); subTrack.push_back(track.back()); } else { // save key point diff --git a/toonz/sources/tnztools/modifiers/modifiertest.cpp b/toonz/sources/tnztools/modifiers/modifiertest.cpp index 75090d6..6a4783e 100644 --- a/toonz/sources/tnztools/modifiers/modifiertest.cpp +++ b/toonz/sources/tnztools/modifiers/modifiertest.cpp @@ -27,7 +27,7 @@ TTrackPoint TModifierTest::Modifier::calcPoint(double originalIndex) { TTrackPoint p = TTrackModifier::calcPoint(originalIndex); - if (p.length > 2.0) { + if (p.length > TConsts::epsilon) { double frac; int i0 = original.floorIndex(originalIndex, &frac); int i1 = original.ceilIndex(originalIndex); @@ -40,10 +40,10 @@ TModifierTest::Modifier::calcPoint(double originalIndex) { double s = sin(angle); double c = cos(angle); - TPointD tangent = TPointD(1.0, 0.0); // original.calcTangent(originalIndex, fabs(2.0*this->radius/speed)); - p.position.x += radius*(c*tangent.x - s*tangent.y); - p.position.y += radius*(s*tangent.x + c*tangent.y); - p.pressure *= 0.5*(1.0 + c); + TPointD tangent = original.calcTangent(originalIndex, fabs(2.0*this->radius/speed)); + p.position.x -= tangent.y*s*radius; + p.position.y += tangent.x*s*radius; + p.pressure *= 1.0 - 0.5*c; } } else { p.pressure = 0.0; @@ -58,9 +58,9 @@ TModifierTest::Modifier::calcPoint(double originalIndex) { //***************************************************************************************** -TModifierTest::TModifierTest(): - count(1), - radius(40.0) +TModifierTest::TModifierTest(int count, double radius): + count(count), + radius(radius) { } @@ -70,7 +70,7 @@ TModifierTest::modifyTrack( const TInputSavePoint::Holder &savePoint, TTrackList &outTracks ) { - const double segmentSize = M_PI/180.0*10.0; + const double segmentSize = 2.0*M_PI/10.0; if (!track.handler) { if (track.getKeyState(track.front().time).isPressed(TKey(Qt::Key_Alt))) { @@ -83,7 +83,7 @@ TModifierTest::modifyTrack( *track.handler, i*2.0*M_PI/(double)count, radius, - 2.0 ))); + 0.25 ))); } } @@ -113,8 +113,8 @@ TModifierTest::modifyTrack( for(int i = start; i < track.size(); ++i) { if (i > 0) { double dl = track[i].length - track[i-1].length; - double da = track[i].pressure > TTrack::epsilon - ? dl/(2.0*radius*track[i].pressure) : 0.0; + double da = track[i].pressure > TConsts::epsilon + ? dl/(radius*track[i].pressure) : 0.0; handler->angles.push_back(handler->angles[i-1] + da); } else { handler->angles.push_back(0.0); @@ -124,12 +124,13 @@ TModifierTest::modifyTrack( // process sub-tracks for(TTrackList::const_iterator ti = handler->tracks.begin(); ti != handler->tracks.end(); ++ti) { TTrack &subTrack = **ti; + double currentSegmentSize = segmentSize; + if (const Modifier *modifier = dynamic_cast(subTrack.modifier.getPointer())) + if (fabs(modifier->speed) > TConsts::epsilon) + currentSegmentSize = segmentSize/fabs(modifier->speed); // remove points - int subStart = subTrack.floorIndex(subTrack.indexByOriginalIndex(start)); - if (subStart < 0) subStart = 0; - if (subStart < subTrack.size() && subTrack[subStart].originalIndex + TTrack::epsilon < start) - ++subStart; + int subStart = subTrack.floorIndex(subTrack.indexByOriginalIndex(start-1)) + 1; subTrack.truncate(subStart); // add points @@ -137,8 +138,8 @@ TModifierTest::modifyTrack( if (i > 0) { double prevAngle = handler->angles[i-1]; double nextAngle = handler->angles[i]; - if (fabs(nextAngle - prevAngle) > 1.5*segmentSize) { - double step = segmentSize/fabs(nextAngle - prevAngle); + if (fabs(nextAngle - prevAngle) > 1.5*currentSegmentSize) { + double step = currentSegmentSize/fabs(nextAngle - prevAngle); double end = 1.0 - 0.5*step; for(double frac = step; frac < end; frac += step) subTrack.push_back( subTrack.modifier->calcPoint((double)i - 1.0 + frac) ); diff --git a/toonz/sources/tnztools/track.cpp b/toonz/sources/tnztools/track.cpp index 78d7d00..ae32131 100644 --- a/toonz/sources/tnztools/track.cpp +++ b/toonz/sources/tnztools/track.cpp @@ -7,7 +7,6 @@ // Static fields //***************************************************************************************** -const double TTrack::epsilon = 1e-9; TTrack::Id TTrack::m_lastId = 0; @@ -69,7 +68,7 @@ TTrack::level() const int TTrack::floorIndex(double index, double *outFrac) const { - int i = (int)floor(index + epsilon); + int i = (int)floor(index + TConsts::epsilon); if (i > size() - 1) { if (outFrac) *outFrac = 0.0; return size() - 1; @@ -85,22 +84,21 @@ TTrack::floorIndex(double index, double *outFrac) const { void TTrack::push_back(const TTrackPoint &point) { m_points.push_back(point); - if (size() == 1) return; + if (size() > 1) { + const TTrackPoint &prev = *(m_points.rbegin() + 1); + TTrackPoint &p = m_points.back(); - const TTrackPoint &prev = *(m_points.rbegin() + 1); - TTrackPoint &p = m_points.back(); + // fix originalIndex + if (p.originalIndex < prev.originalIndex) + p.originalIndex = prev.originalIndex; - // fix originalIndex - if (p.originalIndex < prev.originalIndex) - p.originalIndex = prev.originalIndex; - - // fix time - p.time = std::max(p.time, prev.time + TToolTimer::step); - - // calculate length - TPointD d = p.position - prev.position; - p.length = prev.length + sqrt(d.x*d.x + d.y*d.y); + // fix time + p.time = std::max(p.time, prev.time + TToolTimer::step); + // calculate length + TPointD d = p.position - prev.position; + p.length = prev.length + sqrt(d.x*d.x + d.y*d.y); + } ++pointsAdded; } @@ -122,13 +120,13 @@ TTrack::calcPoint(double index) const { TPointD TTrack::calcTangent(double index, double distance) const { - double minDistance = 10.0*epsilon; + double minDistance = 10.0*TConsts::epsilon; if (distance < minDistance) distance = minDistance; TTrackPoint p = calcPoint(index); TTrackPoint pp = calcPoint(indexByLength(p.length - distance)); TPointD dp = p.position - pp.position; double lenSqr = dp.x*dp.x + dp.y*dp.y; - return lenSqr > epsilon*epsilon ? dp*sqrt(1.0/lenSqr) : TPointD(); + return lenSqr > TConsts::epsilon*TConsts::epsilon ? dp*(1.0/sqrt(lenSqr)) : TPointD(); } double diff --git a/toonz/sources/toonz/sceneviewerevents.cpp b/toonz/sources/toonz/sceneviewerevents.cpp index 22945df..12058e8 100644 --- a/toonz/sources/toonz/sceneviewerevents.cpp +++ b/toonz/sources/toonz/sceneviewerevents.cpp @@ -624,7 +624,7 @@ void SceneViewer::onMove(const TMouseEvent &event) { } TObjectHandle *objHandle = TApp::instance()->getCurrentObject(); - if (tool->getToolType() & TTool::LevelTool && !objHandle->isSpline()) { + if ((tool->getToolType() & TTool::LevelTool) && !objHandle->isSpline()) { pos.x /= m_dpiScale.x; pos.y /= m_dpiScale.y; } @@ -799,7 +799,7 @@ void SceneViewer::onPress(const TMouseEvent &event) { TPointD pos = tool->getMatrix().inv() * winToWorld(m_pos); TObjectHandle *objHandle = TApp::instance()->getCurrentObject(); - if (tool->getToolType() & TTool::LevelTool && !objHandle->isSpline()) { + if ((tool->getToolType() & TTool::LevelTool) && !objHandle->isSpline()) { pos.x /= m_dpiScale.x; pos.y /= m_dpiScale.y; } @@ -904,7 +904,7 @@ void SceneViewer::onRelease(const TMouseEvent &event) { winToWorld(event.mousePos() * getDevPixRatio()); TObjectHandle *objHandle = TApp::instance()->getCurrentObject(); - if (tool->getToolType() & TTool::LevelTool && !objHandle->isSpline()) { + if ((tool->getToolType() & TTool::LevelTool) && !objHandle->isSpline()) { pos.x /= m_dpiScale.x; pos.y /= m_dpiScale.y; } @@ -1500,7 +1500,7 @@ void SceneViewer::keyPressEvent(QKeyEvent *event) { TPointD pos = tool->getMatrix().inv() * winToWorld(m_lastMousePos); TObjectHandle *objHandle = TApp::instance()->getCurrentObject(); - if (tool->getToolType() & TTool::LevelTool && !objHandle->isSpline()) { + if ((tool->getToolType() & TTool::LevelTool) && !objHandle->isSpline()) { pos.x /= m_dpiScale.x; pos.y /= m_dpiScale.y; } @@ -1587,7 +1587,7 @@ void SceneViewer::keyReleaseEvent(QKeyEvent *event) { TPointD pos = tool->getMatrix().inv() * winToWorld(m_lastMousePos); TObjectHandle *objHandle = TApp::instance()->getCurrentObject(); - if (tool->getToolType() & TTool::LevelTool && !objHandle->isSpline()) { + if ((tool->getToolType() & TTool::LevelTool) && !objHandle->isSpline()) { pos.x /= m_dpiScale.x; pos.y /= m_dpiScale.y; } @@ -1631,7 +1631,7 @@ void SceneViewer::mouseDoubleClickEvent(QMouseEvent *event) { TPointD pos = tool->getMatrix().inv() * winToWorld(event->pos() * getDevPixRatio()); TObjectHandle *objHandle = TApp::instance()->getCurrentObject(); - if (tool->getToolType() & TTool::LevelTool && !objHandle->isSpline()) { + if ((tool->getToolType() & TTool::LevelTool) && !objHandle->isSpline()) { pos.x /= m_dpiScale.x; pos.y /= m_dpiScale.y; }