From a04d2b01c6bcfe65b2ac2120ef3c515b3a405b39 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Tue, 17 Jan 2023 02:16:30 +0100 Subject: [PATCH] Timeline: hunt down and fix a numeric-wrap problem Sometimes, fractional seconds in the ZoomWindow metric can build up to numerator and denominator values in the 64-bit integer domain. Thus the division and truncation of the Window pixel with value must be done in int64_t, while the result value is then guaranteed to be a small integer < 100000 This caused the canvas to flicker and jump in size and the resulting scrollbar change caused various cascading effects on the further layout calculations... --- src/stage/model/canvas-hook.hpp | 5 +++++ src/stage/model/zoom-metric.hpp | 20 +++++++++++++++-- src/stage/timeline/display-manager.hpp | 5 ++++- wiki/thinkPad.ichthyo.mm | 30 ++++++++++++++++++++++---- 4 files changed, 53 insertions(+), 7 deletions(-) diff --git a/src/stage/model/canvas-hook.hpp b/src/stage/model/canvas-hook.hpp index b228b5fb6..4382585db 100644 --- a/src/stage/model/canvas-hook.hpp +++ b/src/stage/model/canvas-hook.hpp @@ -57,6 +57,7 @@ #include "lib/util.hpp" #include +#include ///////////////TODO namespace stage { @@ -66,6 +67,7 @@ namespace model { using lib::time::Offset; using lib::time::TimeValue; using lib::time::TimeSpan; + using std::string; //////////////////////////TODO @@ -99,6 +101,9 @@ namespace model { * @return resulting TimeValue when applying the offset within current metric */ virtual TimeValue applyScreenDelta(Time anchor, double deltaPx) const =0; +//////////////////////////////////////////////////////////////TODO +virtual string tranZ(TimeValue staTiPoi) const =0; +//////////////////////////////////////////////////////////////TODO }; diff --git a/src/stage/model/zoom-metric.hpp b/src/stage/model/zoom-metric.hpp index 187d64e58..9f71af049 100644 --- a/src/stage/model/zoom-metric.hpp +++ b/src/stage/model/zoom-metric.hpp @@ -51,6 +51,8 @@ #include "lib/meta/trait.hpp" #include "stage/model/canvas-hook.hpp" #include "stage/model/zoom-window.hpp" +#include "lib/format-obj.hpp"////////////////////////////TODO +#include "lib/format-string.hpp"/////////////////////////TODO @@ -91,7 +93,18 @@ namespace model { { return zoomWindow_.overallSpan(); } - + +//////////////////////////////////////////////////////////////TODO +string tranZ(TimeValue staTiPoi) const override + { + auto sta = zoomWindow_.overallSpan().start(); + Offset offi{sta, staTiPoi}; + Rat mulli = zoomWindow_.px_per_sec() * _FSecs(offi); + int64_t casti = rational_cast (mulli); + static util::_Fmt formi{"Offset(%d, %d) = %d ⟼ px = %s ⟼ %s"}; + return formi % _raw(sta) % _raw(staTiPoi) % _raw(offi) % util::toString(mulli) % casti; + } +//////////////////////////////////////////////////////////////TODO int translateTimeToPixels (TimeValue startTimePoint) const override { @@ -101,7 +114,10 @@ namespace model { int translateScreenDelta (Offset timeOffset) const override { - return rational_cast (zoomWindow_.px_per_sec() * _FSecs(timeOffset)); + auto pxOffset = rational_cast (zoomWindow_.px_per_sec() * _FSecs(timeOffset)); + // // use 64-bit for the division to prevent numeric-wrap... + REQUIRE (abs (pxOffset) <= std::numeric_limits::max()); + return int(pxOffset); } TimeValue diff --git a/src/stage/timeline/display-manager.hpp b/src/stage/timeline/display-manager.hpp index 3b4b0cdf4..9890e7e5d 100644 --- a/src/stage/timeline/display-manager.hpp +++ b/src/stage/timeline/display-manager.hpp @@ -99,6 +99,7 @@ namespace timeline { using lib::time::TimeValue; class TrackHeadWidget; class TrackBody; + using std::string;///////////////////////////////TODO /** @@ -189,8 +190,10 @@ namespace timeline { auto covfefe2 = coveredTime(); auto end = covfefe2.end(); auto tranE = translateTimeToPixels(end); + + string buggi = tranZ(end); -cout<<"|↯| pxSpan cov1="< - + + + + + + + + + + + + + + + + + + + + + + + @@ -43712,7 +43734,7 @@ - + @@ -43861,8 +43883,8 @@ - - + +