Timeline: improve handling of window size changes at extreme positions

...again and again surprising how much inconsitencies can hide in just some lines of code...
This commit is contained in:
Fischlurch 2022-12-16 19:59:47 +01:00
parent 77bb156615
commit 3893968502
3 changed files with 87 additions and 36 deletions

View file

@ -171,7 +171,7 @@ namespace model {
/** the deepest zoom is to use 2px per micro-tick */
const uint ZOOM_MAX_RESOLUTION = 2 * TimeValue::SCALE;
const Rat ZOOM_MAX_RESOLUTION = 2 * TimeValue::SCALE;
namespace {// initial values (rather arbitrary)
const FSecs DEFAULT_CANVAS{23};
@ -982,8 +982,9 @@ namespace model {
duration = DEFAULT_CANVAS;
else if (duration > maxSaneWinExtension (px))
duration = maxSaneWinExtension (px);
Rat changedMetric = Rat(px) / duration;
conformWindowToMetric (changedMetric);
placeWindowRelativeToAnchor (duration);
establishWindowDuration (duration);
px_per_sec_ = conformMetricToWindow (px);
ensureInvariants (px);
}
@ -1060,7 +1061,7 @@ namespace model {
FSecs
anchorPoint() const
{
return startWin_ + scaleSafe (afterWin_-startWin_, relativeAnchor());
return startWin_ + Offset{scaleSafe (afterWin_-startWin_, relativeAnchor())};
}
/**

View file

@ -264,7 +264,7 @@ namespace test {
// so this is the deepest zoom possible....
CHECK (win.visible().duration() == TimeValue(640));
CHECK (TimeValue(640) == _t(1280,ZOOM_MAX_RESOLUTION));
CHECK (TimeValue{640} == Time{Rat(1280)/ZOOM_MAX_RESOLUTION});
// and this the absolutely smallest possible zoom window
win.calibrateExtension(2);
@ -818,26 +818,54 @@ namespace test {
CHECK (win.overallSpan().end() == Time::MAX);
/*--Test-3-----------*/
win.setOverallDuration(Duration::MAX); // now use maximally expanded canvas
Duration targetDur{99_r/100 * Duration::MAX};
win.setVisibleDuration(targetDur); // and demand the duration be expanded to 99%
win.calibrateExtension(560);
CHECK (win.visible().duration() == TimeValue(280)); // effective window dimensions unchanged
CHECK (win.px_per_sec() == 2000000_r/1); // but zoom metric slightly adapted
CHECK (win.visible().duration() > targetDur); // actual duration slightly more than requested,
CHECK (win.visible().duration() < Duration::MAX);
win.setOverallDuration(Duration::MAX); // now use maximally expanded canvas
Duration targetDur{Duration::MAX - FSecs(23)};
win.setVisibleDuration(targetDur); // and demand the duration be expanded almost full size
CHECK (win.visible().duration() == targetDur); // actual duration is the value requested
CHECK (win.visible().duration() < Duration::MAX);
CHECK (win.visible().start() == Time::MIN); // expansion was anchored at previous position
CHECK (win.visible().start() < Time::MAX); // and thus the window now clings to the lower end
CHECK (win.visible().end() == TimeValue(301415533658088775));
CHECK (win.px_per_sec() == 2019_r/2199023255552); // effective zoom metric has been sanitised numerically
CHECK (win.pxWidth() == 559); // but pixel count is matched precisely
CHECK (win.visible().end() == TimeValue(307445734538825860));
CHECK (Time::MAX - win.visible().end() == TimeValue(23*Time::SCALE));
CHECK (win.px_per_sec() == 2003_r/2199023255552); // effective zoom metric has been sanitised numerically
CHECK (win.pxWidth() == 560); // but pixel count is matched precisely
/*--Test-4-----------*/
win.setVisiblePos(Rat{std::numeric_limits<int64_t>::max()-23});
SHOW_EXPR(_raw(win.overallSpan().duration()));
SHOW_EXPR(_raw(win.visible().duration()));
SHOW_EXPR(_raw(win.visible().start()));
SHOW_EXPR(_raw(win.visible().end()));
SHOW_EXPR(win.px_per_sec());
SHOW_EXPR(win.pxWidth());
CHECK (win.visible().duration() == targetDur); // actual duration unchanged
CHECK (win.px_per_sec() == 2003_r/2199023255552);
CHECK (win.pxWidth() == 560);
CHECK (win.visible().end() == Time::MAX); // but window now slinged to the right extreme
CHECK (win.visible().start() > Time::MIN);
CHECK (win.visible().start() == TimeValue(-307445734538825860));
/*--Test-5-----------*/
win.calibrateExtension(561); // expand by 1 pixel
CHECK (win.visible().duration() > targetDur); // actual duration indeed increased
CHECK (win.visible().duration() == Duration::MAX); // and then capped at maximum
CHECK (win.visible().end() == Time::MAX); // but while initially the upper bound is increased...
CHECK (win.visible().start() == Time::MIN);
CHECK (win.px_per_sec() == 2007_r/2199023255552); // the smoothed nominal metric was also increased slightly
CHECK (win.pxWidth() == 561);
/*--Test-6-----------*/
win.setVisibleDuration(Duration::MAX - Duration(TimeValue(1))); // request slightly different window duration
CHECK (win.visible().end() == Time::MAX); // by arbitrary choice, the single µ-tick was removed at start
CHECK (win.visible().start() == Time::MIN + TimeValue(1));
CHECK (win.px_per_sec() == 2007_r/2199023255552); // the smoothed nominal metric was also increased slightly
CHECK (win.pxWidth() == 561);
win.setVisibleDuration(Duration(TimeValue(1))); // drastically zoom-in
CHECK (win.visible().duration() == TimeValue(281)); // ...but we get more than 1 µ-tick
CHECK (561_r/_FSecs(TimeValue(1)) > ZOOM_MAX_RESOLUTION); // because the requested window would exceed maximum zoom
CHECK (win.px_per_sec() == 561000000_r/281); // and this conflict was resolved by increasing the window
CHECK (win.visible().end() == Time::MAX); // while keeping it aligned to the end of the timeline
CHECK (win.pxWidth() == 561);
}

View file

@ -39613,7 +39613,7 @@
<icon BUILTIN="idea"/>
</node>
</node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1668263409355" ID="ID_1494604965" MODIFIED="1668289734659" TEXT="setVisiblePos (Rat percentage)">
<node BACKGROUND_COLOR="#e0ceaa" COLOR="#690f14" CREATED="1668263409355" ID="ID_1494604965" MODIFIED="1671216876683" TEXT="setVisiblePos (Rat percentage)">
<arrowlink COLOR="#895f96" DESTINATION="ID_759637608" ENDARROW="Default" ENDINCLINATION="124;-7;" ID="Arrow_ID_728050450" STARTARROW="None" STARTINCLINATION="168;14;"/>
<icon BUILTIN="messagebox_warning"/>
</node>
@ -39774,11 +39774,11 @@
</node>
</node>
</node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1668263629246" ID="ID_1257614207" MODIFIED="1668265511791" TEXT="mutateScale (Rat changedMetric)">
<node COLOR="#338800" CREATED="1668263629246" ID="ID_1257614207" MODIFIED="1671216867276" TEXT="mutateScale (Rat changedMetric)">
<arrowlink COLOR="#e62f5c" DESTINATION="ID_651838862" ENDARROW="Default" ENDINCLINATION="115;-4;" ID="Arrow_ID_1930230162" STARTARROW="None" STARTINCLINATION="-189;14;"/>
<arrowlink COLOR="#753c82" DESTINATION="ID_1976979366" ENDARROW="Default" ENDINCLINATION="-43;-3;" ID="Arrow_ID_226790124" STARTARROW="None" STARTINCLINATION="80;7;"/>
<linktarget COLOR="#aa6877" DESTINATION="ID_1257614207" ENDARROW="Default" ENDINCLINATION="271;-11;" ID="Arrow_ID_292335664" SOURCE="ID_1173749705" STARTARROW="None" STARTINCLINATION="314;29;"/>
<icon BUILTIN="flag-yellow"/>
<icon BUILTIN="button_ok"/>
<node COLOR="#435e98" CREATED="1668265021139" HGAP="52" ID="ID_1943948610" MODIFIED="1670517343960" TEXT="pr&#xfc;fen: sehr kleine Metrik" VSHIFT="-2">
<linktarget COLOR="#be7ca2" DESTINATION="ID_1943948610" ENDARROW="Default" ENDINCLINATION="57;-54;" ID="Arrow_ID_569700266" SOURCE="ID_680870152" STARTARROW="None" STARTINCLINATION="197;26;"/>
<icon BUILTIN="yes"/>
@ -39868,9 +39868,9 @@
<icon BUILTIN="button_ok"/>
</node>
</node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1668263652677" ID="ID_759637608" MODIFIED="1668265848826" TEXT="anchorWindowAtPosition (FSecs canvasOffset)">
<node COLOR="#338800" CREATED="1668263652677" ID="ID_759637608" MODIFIED="1671216888664" TEXT="anchorWindowAtPosition (FSecs canvasOffset)">
<linktarget COLOR="#895f96" DESTINATION="ID_759637608" ENDARROW="Default" ENDINCLINATION="124;-7;" ID="Arrow_ID_728050450" SOURCE="ID_1494604965" STARTARROW="None" STARTINCLINATION="168;14;"/>
<icon BUILTIN="flag-yellow"/>
<icon BUILTIN="button_ok"/>
<node CREATED="1668265925547" ID="ID_548541569" MODIFIED="1668265934174" TEXT="negative Werte">
<node CREATED="1668267213730" ID="ID_751640089" MODIFIED="1668267225777" TEXT="grunds&#xe4;tzlich hier vorgesehen"/>
<node CREATED="1668267238564" ID="ID_1057480192" MODIFIED="1668267248362" TEXT="startWin_ = startAll_ + (canvasOffset - partBeforeAnchor);">
@ -41244,27 +41244,32 @@
</node>
</node>
</node>
<node BACKGROUND_COLOR="#eef0c5" COLOR="#990000" CREATED="1668555072594" ID="ID_742229180" MODIFIED="1670982967576" TEXT="Ansteuern exterm gro&#xdf;er Zeit-Positionen">
<icon BUILTIN="pencil"/>
<node COLOR="#338800" CREATED="1668555072594" ID="ID_742229180" MODIFIED="1671216852441" TEXT="Ansteuern exterm gro&#xdf;er Zeit-Positionen">
<icon BUILTIN="button_ok"/>
<node COLOR="#338800" CREATED="1670982930768" ID="ID_1528129980" MODIFIED="1670982944610" TEXT="erzeugen mit Start-Pos == Time::MAX">
<icon BUILTIN="button_ok"/>
</node>
<node COLOR="#338800" CREATED="1669475536331" ID="ID_486161883" MODIFIED="1671153173786" TEXT="setVisiblePos mit extremer Time">
<icon BUILTIN="button_ok"/>
</node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1669475549345" ID="ID_234786683" MODIFIED="1670982949932" TEXT="setVisiblePos mit extremem Faktor">
<icon BUILTIN="flag-yellow"/>
<node BACKGROUND_COLOR="#fdfdcf" COLOR="#ff0000" CREATED="1671153443706" ID="ID_43785368" MODIFIED="1671153469830" TEXT="Rechnung sieht plausibel aus, aber das Ergebnis ist falsch">
<icon BUILTIN="flag-pink"/>
<node COLOR="#338800" CREATED="1669475549345" ID="ID_234786683" MODIFIED="1671216849651" TEXT="setVisiblePos mit extremem Faktor">
<icon BUILTIN="button_ok"/>
<node COLOR="#435e98" CREATED="1671153443706" ID="ID_43785368" MODIFIED="1671216714904" TEXT="Rechnung sieht plausibel aus, aber das Ergebnis ist falsch">
<icon BUILTIN="broken-line"/>
<node CREATED="1671153472181" ID="ID_1963137458" MODIFIED="1671153492750" TEXT="Offset wird auf MAX_DURATION gekappt (korrekt)"/>
<node CREATED="1671153500329" ID="ID_983458362" MODIFIED="1671153514062" TEXT="als relativer Pox-Faktor kommt 1 raus (korrekt)"/>
<node BACKGROUND_COLOR="#f0d5c5" COLOR="#990033" CREATED="1671153518751" ID="ID_180845154" MODIFIED="1671153548737" TEXT="auch partBeforeAnchor wird anscheinend korrekt berechnet?">
<node COLOR="#990033" CREATED="1671153518751" ID="ID_180845154" MODIFIED="1671216726077" TEXT="auch partBeforeAnchor wird anscheinend korrekt berechnet?">
<icon BUILTIN="help"/>
</node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1671153550626" ID="ID_1354877877" MODIFIED="1671153588403" TEXT="aber visible().end() ist dann nicht Time::MAX">
<node COLOR="#990000" CREATED="1671153550626" ID="ID_1354877877" MODIFIED="1671216842541" TEXT="aber visible().end() ist dann nicht Time::MAX">
<arrowlink COLOR="#c04288" DESTINATION="ID_1578460487" ENDARROW="Default" ENDINCLINATION="61;-23;" ID="Arrow_ID_914471115" STARTARROW="None" STARTINCLINATION="181;11;"/>
<icon BUILTIN="broken-line"/>
</node>
</node>
<node COLOR="#338800" CREATED="1671216679413" ID="ID_1318691761" MODIFIED="1671216817689" TEXT="nach &#x201e;Begradigung&#x201c; der Implementierung nun auch korrekt">
<arrowlink COLOR="#7accc0" DESTINATION="ID_1757084511" ENDARROW="Default" ENDINCLINATION="-271;-16;" ID="Arrow_ID_1766419591" STARTARROW="None" STARTINCLINATION="468;22;"/>
<icon BUILTIN="button_ok"/>
</node>
</node>
<node CREATED="1669479474484" ID="ID_1657847338" MODIFIED="1669479489366" TEXT="alle Mutatoren, die conformWindowToMetric() verwenden">
<node CREATED="1670520100834" ID="ID_636101408" MODIFIED="1670520114018" TEXT="das sind nicht viele (&#xfc;berraschenderweise)">
@ -41285,8 +41290,11 @@
<node COLOR="#338800" CREATED="1670520259018" ID="ID_591142628" MODIFIED="1671153197781" TEXT="vergr&#xf6;&#xdf;ern auf Duration::MAX - aWeng">
<icon BUILTIN="button_ok"/>
<node CREATED="1671153207589" ID="ID_1801258827" MODIFIED="1671153210390" TEXT="so lala"/>
<node CREATED="1671153211145" ID="ID_779131227" MODIFIED="1671153241103" TEXT="man bekommt nicht exakt die gesetzte Duration"/>
<node CREATED="1671153242324" ID="ID_1578460487" MODIFIED="1671153708063" TEXT="geht aber nicht besser, da Zahlen maximal giftig">
<node CREATED="1671153211145" ID="ID_779131227" MODIFIED="1671210849270" TEXT="man bekommt nicht exakt die gesetzte Duration">
<arrowlink COLOR="#6f6fbd" DESTINATION="ID_854310223" ENDARROW="Default" ENDINCLINATION="140;0;" ID="Arrow_ID_1109327091" STARTARROW="None" STARTINCLINATION="134;8;"/>
<icon BUILTIN="broken-line"/>
</node>
<node COLOR="#690f14" CREATED="1671153242324" ID="ID_1578460487" MODIFIED="1671216836261" TEXT="geht aber nicht besser, da Zahlen maximal giftig">
<richcontent TYPE="NOTE"><html>
<head>
@ -41297,14 +41305,28 @@
</p>
</body>
</html></richcontent>
<node BACKGROUND_COLOR="#f0d5c5" COLOR="#990033" CREATED="1671153715708" ID="ID_293245647" MODIFIED="1671153722052" TEXT="wirklich nicht?">
<linktarget COLOR="#c04288" DESTINATION="ID_1578460487" ENDARROW="Default" ENDINCLINATION="61;-23;" ID="Arrow_ID_914471115" SOURCE="ID_1354877877" STARTARROW="None" STARTINCLINATION="181;11;"/>
<icon BUILTIN="messagebox_warning"/>
<icon BUILTIN="button_cancel"/>
<node COLOR="#435e98" CREATED="1671153715708" ID="ID_293245647" MODIFIED="1671210765629" TEXT="wirklich nicht?">
<icon BUILTIN="help"/>
<node CREATED="1671153746581" ID="ID_965916539" MODIFIED="1671153758123" TEXT="wir brauchen doch nur die relative Positionierung"/>
<node CREATED="1671153758879" ID="ID_318897179" MODIFIED="1671153783226" TEXT="die trickreiche Limitierung und quantisierung ist &#xfc;berfl&#xfc;ssig..."/>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1671153783923" ID="ID_1591963678" MODIFIED="1671153799214" TEXT="...weil wir ja schon eine Duration haben!">
<node COLOR="#435e98" CREATED="1671153783923" ID="ID_1591963678" MODIFIED="1671210763661" TEXT="...weil wir ja schon eine Duration haben!">
<icon BUILTIN="idea"/>
</node>
</node>
<node COLOR="#435e98" CREATED="1671210766716" ID="ID_380651309" MODIFIED="1671210780555" TEXT="also eine unn&#xf6;tige Schleife">
<icon BUILTIN="yes"/>
</node>
</node>
<node COLOR="#338800" CREATED="1671210784819" ID="ID_1757084511" MODIFIED="1671216807713" TEXT="mutateDuration() direkt implementieren">
<linktarget COLOR="#7accc0" DESTINATION="ID_1757084511" ENDARROW="Default" ENDINCLINATION="-271;-16;" ID="Arrow_ID_1766419591" SOURCE="ID_1318691761" STARTARROW="None" STARTINCLINATION="468;22;"/>
<icon BUILTIN="button_ok"/>
</node>
<node COLOR="#435e98" CREATED="1671210799428" ID="ID_854310223" MODIFIED="1671210890809" STYLE="fork" TEXT="&#x27f9; gesetzte Duration wird nun exakt realisiert">
<linktarget COLOR="#6f6fbd" DESTINATION="ID_854310223" ENDARROW="Default" ENDINCLINATION="140;0;" ID="Arrow_ID_1109327091" SOURCE="ID_779131227" STARTARROW="None" STARTINCLINATION="134;8;"/>
<font NAME="SansSerif" SIZE="12"/>
</node>
</node>
</node>