From d9c6f8b116bccc71fbb18db686a5c6ea975b5b39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szymon=20Aceda=C5=84ski?= Date: Sun, 22 Dec 2019 23:36:50 +0100 Subject: [PATCH 1/2] Fixed path flipping logic Calligraphy tool with tilt-sensitive pen This fixes spurious path flips when drawing with "Use the tilt of the input device to alter the angle of the pen's nib" enabled. The core issue was that the flipping logic required that the computed input angle a1 lies between -90 and 90 degrees, which was not the case when using pen tilt. I tested this in the following scenarios: - hand drawing with pen tilt enabled and all possible pen orientations in regard to path direction (incl. holding pen in awkward orientations) - drawing with fixed angle, verified that the nib angle is the same as before the change - all the cases with both Y axis flipped and not flipped --- src/ui/tools/calligraphic-tool.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/ui/tools/calligraphic-tool.cpp b/src/ui/tools/calligraphic-tool.cpp index b1bd15174a..cefd5d02d3 100644 --- a/src/ui/tools/calligraphic-tool.cpp +++ b/src/ui/tools/calligraphic-tool.cpp @@ -274,24 +274,28 @@ bool CalligraphicTool::apply(Geom::Point p) { /* Calculate angle of drawing tool */ - Geom::Point ang1; + double a1; if (this->usetilt) { // 1a. calculate nib angle from input device tilt: if (this->xtilt == 0 && this->ytilt == 0) { // to be sure that atan2 in the computation below // would not crash or return NaN. - ang1 = Geom::Point(1, 0); + a1 = 0; } else { - ang1 = Geom::Point(-this->xtilt, this->ytilt); + Geom::Point dir(-this->xtilt, this->ytilt); + a1 = atan2(dir); } } else { // 1b. fixed dc->angle (absolutely flat nib): - double const radians = ( (this->angle - 90) / 180.0 ) * M_PI; - ang1 = Geom::Point(-sin(radians), cos(radians)); + a1 = ( this->angle / 180.0 ) * M_PI; + } + a1 *= -this->desktop->yaxisdir(); + if (a1 > 0.5*M_PI) { + a1 -= M_PI; + } else if (a1 < -0.5*M_PI) { + a1 += M_PI; } - ang1.y() *= -this->desktop->yaxisdir(); - double a1 = atan2(ang1); // 2. perpendicular to dc->vel (absolutely non-flat nib): gdouble const mag_vel = Geom::L2(this->vel); -- GitLab From 2fe9569a6372a25e077e0a6db6d3c0682b8a21ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szymon=20Aceda=C5=84ski?= Date: Sat, 28 Dec 2019 19:34:22 +0100 Subject: [PATCH 2/2] review fixups --- src/ui/tools/calligraphic-tool.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ui/tools/calligraphic-tool.cpp b/src/ui/tools/calligraphic-tool.cpp index cefd5d02d3..aa5d44de78 100644 --- a/src/ui/tools/calligraphic-tool.cpp +++ b/src/ui/tools/calligraphic-tool.cpp @@ -291,9 +291,10 @@ bool CalligraphicTool::apply(Geom::Point p) { a1 = ( this->angle / 180.0 ) * M_PI; } a1 *= -this->desktop->yaxisdir(); + a1 = fmod(a1, M_PI); if (a1 > 0.5*M_PI) { a1 -= M_PI; - } else if (a1 < -0.5*M_PI) { + } else if (a1 <= -0.5*M_PI) { a1 += M_PI; } -- GitLab