diff --git a/toonz/sources/include/tools/assistant.h b/toonz/sources/include/tools/assistant.h index ac44d4c..14931aa 100644 --- a/toonz/sources/include/tools/assistant.h +++ b/toonz/sources/include/tools/assistant.h @@ -311,6 +311,7 @@ protected: double getDrawingGridAlpha() const; void drawSegment(const TPointD &p0, const TPointD &p1, double pixelSize, double alpha) const; + void drawMark(const TPointD &p, const TPointD &normal, double pixelSize, double alpha) const; void drawDot(const TPointD &p, double alpha) const; void drawPoint(const TAssistantPoint &point, double pixelSize) const; diff --git a/toonz/sources/tnztools/assistant.cpp b/toonz/sources/tnztools/assistant.cpp index a7d9e88..826ab4e 100644 --- a/toonz/sources/tnztools/assistant.cpp +++ b/toonz/sources/tnztools/assistant.cpp @@ -430,6 +430,14 @@ TAssistant::drawSegment(const TPointD &p0, const TPointD &p1, double pixelSize, //--------------------------------------------------------------------------------------------------- void +TAssistant::drawMark(const TPointD &p, const TPointD &normal, double pixelSize, double alpha) const { + TPointD d = normal*5*pixelSize; + drawSegment(p - d,p + d, pixelSize, alpha); +} + +//--------------------------------------------------------------------------------------------------- + +void TAssistant::drawDot(const TPointD &p, double alpha) const { double colorBlack[4] = { 0.0, 0.0, 0.0, alpha }; double colorWhite[4] = { 1.0, 1.0, 1.0, alpha }; diff --git a/toonz/sources/tnztools/assistants/assistantellipse.cpp b/toonz/sources/tnztools/assistants/assistantellipse.cpp index 236c6a7..db6055e 100644 --- a/toonz/sources/tnztools/assistants/assistantellipse.cpp +++ b/toonz/sources/tnztools/assistants/assistantellipse.cpp @@ -249,11 +249,9 @@ private: void drawRuler(const TAffine &ellipseMatrix, double pixelSize) const { double minStep = 10.0*pixelSize; - double alpha = getDrawingGridAlpha(); + double alpha = getDrawingAlpha(); - const TAffine &em = ellipseMatrix; - double r = sqrt(0.5*(norm2(TPointD(em.a11, em.a21)) + norm2(TPointD(em.a12, em.a22)))); - double actualMinStep = minStep/r; + TAffine em = ellipseMatrix; TAffine ellipseMatrixInv = ellipseMatrix.inv(); TPointD g0 = ellipseMatrixInv*m_grid0.position; TPointD g1 = ellipseMatrixInv*m_grid1.position; @@ -262,22 +260,55 @@ private: double ga0 = atan(g0); double ga1 = atan(g1); + // x and y radiuses + TPointD r( norm2(TPointD(em.a11, em.a21)), norm2(TPointD(em.a12, em.a22)) ); + double avgR = 0.5*(r.x + r.y); + if (avgR <= TConsts::epsilon*TConsts::epsilon) return; + avgR = sqrt(avgR); + double actualMinStep = minStep/avgR; + r.x = sqrt(r.x); + r.y = sqrt(r.y); + + // remove radiuses from ellipse matrix + double rkx = r.x > TConsts::epsilon ? 1.0/r.x : 0.0; + double rky = r.y > TConsts::epsilon ? 1.0/r.y : 0.0; + em.a11 *= rkx; em.a21 *= rkx; + em.a12 *= rky; em.a22 *= rky; + if (getPerspective()) { // draw perspective if (ga0 < 0.0) { if (ga1 > 0.0) ga1 -= M_2PI; } else { if (ga1 < 0.0) ga1 += M_2PI; } double k = 0.0, begin = 0.0, end = 0.0; if (!calcPerspectiveStep(actualMinStep, 0.0, M_2PI, 0.0, fabs(ga0), ga1, k, begin, end)) return; - for(double x = begin; fabs(x) < fabs(end); x *= k) - drawDot(ellipseMatrix * TPointD(cos(x), (ga0 < 0.0 ? -1.0 : 1.0)*sin(x))); + for(double a = begin; fabs(a) < fabs(end); a *= k) { + TPointD p( cos(a), (ga0 < 0.0 ? -1.0 : 1.0)*sin(a) ); + TPointD n( p.x*r.y, p.y*r.x ); // perp to allipse + double nl2 = norm2(n); + if (nl2 > TConsts::epsilon*TConsts::epsilon) { + p.x *= r.x; + p.y *= r.y; + n = n*(1.0/sqrt(nl2)); + drawMark(em*p, em.transformDirection(n), pixelSize, alpha); + } + } } else { // draw linear double da = ga1 - ga0; if (da < 0.0) { da = -da; std::swap(ga0, ga1); } if (ga1 - ga0 > M_PI) { da = M_2PI - da; std::swap(ga0, ga1); } if (da < actualMinStep) return; - for(double a = ga0 - floor(M_PI/da)*da; a < ga0 + M_PI; a += da) - drawDot(ellipseMatrix * TPointD(cos(a), sin(a))); + for(double a = ga0 - floor(M_PI/da)*da; a < ga0 + M_PI; a += da) { + TPointD p( cos(a), sin(a) ); + TPointD n( p.x*r.y, p.y*r.x ); // perp to allipse + double nl2 = norm2(n); + if (nl2 > TConsts::epsilon*TConsts::epsilon) { + p.x *= r.x; + p.y *= r.y; + n = n*(1.0/sqrt(nl2)); + drawMark(em*p, em.transformDirection(n), pixelSize, alpha); + } + } } } diff --git a/toonz/sources/tnztools/assistants/assistantline.cpp b/toonz/sources/tnztools/assistants/assistantline.cpp index 1b464aa..d87134f 100644 --- a/toonz/sources/tnztools/assistants/assistantline.cpp +++ b/toonz/sources/tnztools/assistants/assistantline.cpp @@ -166,7 +166,7 @@ private: if (l2 <= TConsts::epsilon*TConsts::epsilon) return; double dirLen = sqrt(l2); TPointD dirProj = direction*(1.0/l2); - TPointD markOffset = TPointD(-direction.y, direction.x)*(5*pixelSize/dirLen); + TPointD normal = TPointD(-direction.y, direction.x)*(1.0/dirLen); double xg0 = dirProj*(m_grid0.position - a); double xg1 = dirProj*(m_grid1.position - a); @@ -176,18 +176,14 @@ private: double xa0 = dirProj*(m_a.position - a); double k = 0.0, begin = 0.0, end = 0.0; if (!calcPerspectiveStep(minStep/dirLen, 0.0, 1.0, xa0, xg0, xg1, k, begin, end)) return; - for(double x = begin; fabs(x) < fabs(end); x *= k) { - TPointD p = a + direction*(xa0 + x); - drawSegment(p - markOffset, p + markOffset, pixelSize, alpha); - } + for(double x = begin; fabs(x) < fabs(end); x *= k) + drawMark(a + direction*(xa0 + x), normal, pixelSize, alpha); } else { // draw linear double dx = fabs(xg1 - xg0); if (dx*dirLen < minStep) return; - for(double x = xg0 - floor(xg0/dx)*dx; x < 1.0; x += dx) { - TPointD p = a + direction*x; - drawSegment(p - markOffset, p + markOffset, pixelSize, alpha); - } + for(double x = xg0 - floor(xg0/dx)*dx; x < 1.0; x += dx) + drawMark(a + direction*x, normal, pixelSize, alpha); } } @@ -323,7 +319,14 @@ public: success = TGuidelineLineBase::truncateRay(oneBox, bb, aa); else success = TGuidelineLineBase::truncateInfiniteLine(oneBox, aa, bb); - if (!success) return; + + if (!success) { + // line is out of screen, bud grid still can be visible + if (grid && getParallel()) + drawGrid(matrix, matrixInv, pixelSize, restrictA, restrictB, perspective); + return; + } + TPointD a = matrixInv*aa; TPointD b = matrixInv*bb;