fix(ticks): label the tick at the origin 0, not from the atto end of the table
A range straddling zero never lands *on* zero: the walk starts at `ceil(min / stride) * stride`, which is not representable whenever the stride is not a power of two -- 0.1 and 0.2 are the everyday ones -- so the tick that means zero arrives a few ULP off and `format_si` labels it from six prefixes down. `[-1, 1]` read `-1 -500m -139a 500m 1`. Deriving the tick by multiplication rather than accumulation does not help, because the error is already in the first term. Every tick is an integer multiple of the stride, so the smallest magnitude a non-zero tick can have is the stride itself, while the residue is a few ULP of the range -- ten orders of magnitude apart. Anything inside a millionth of the stride is therefore the origin and nothing else. It is stored as exactly `0.0` rather than merely labelled so: `Axis::refresh()` re-formats a time axis from `tick.value`, where the same residue reads `3.19e-13ms`. The walk variable is left alone, since `minor_index_is_major` counts indices from `first_major` and both operands have to stay on the walk's own grid. The two narrow-y-title cases were calibrated on the defect -- the bogus `-55.5a` was a six-character label, and its width is what spent the chrome allowance and made the titled and untitled frames comparable. They are re-seated on a milli-scale range, whose `-200m` is wide for a real reason, and the zero-width strip the frame comparison depends on is now asserted rather than assumed. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
525759f9a9
commit
e337c6a60c
4 files changed
+104
-11
No files matched your search
@@ -1572,9 +1572,17 @@ PLOT_TEST(narrow_viewport_draws_no_y_title_it_cannot_fit) {
|
||||
plot::Plot plot;
|
||||
plot.set_viewport({0, 0, static_cast<plot::f32>(kNarrowW), static_cast<plot::f32>(kNarrowH)});
|
||||
plot.add_x_axis({"", {0.0, 1.0}, false, plot::AxisPlace::Bottom, false});
|
||||
plot.add_y_axis({title, {-1.0, 1.0}, false, plot::AxisPlace::Left, false});
|
||||
plot.add_y_axis({title, {-1.0, 1.0}, false, plot::AxisPlace::Right, false});
|
||||
plot.add_y_axis({title, {-1.0, 1.0}, false, plot::AxisPlace::Left, false});
|
||||
// A milli-scale range, for the *width of its labels*: a symmetric span ticks at
|
||||
// +/-step and 0, so the labels here are `-200m 0 200m` -- five characters, wide
|
||||
// enough that the label strip alone spends the whole chrome allowance and the
|
||||
// title strip is left zero wide, which is the regime asserted below. A `[-1, 1]`
|
||||
// axis labels `-1 0 1` instead and does not fill the allowance: the titled scene
|
||||
// then keeps a 9.6 px title column -- still too narrow to stage a glyph, so the
|
||||
// property holds -- but the column also pushes the label strip 9.6 px right, and
|
||||
// the frame comparison would be reading that shift rather than title ink.
|
||||
plot.add_y_axis({title, {-0.2, 0.2}, false, plot::AxisPlace::Left, false});
|
||||
plot.add_y_axis({title, {-0.2, 0.2}, false, plot::AxisPlace::Right, false});
|
||||
plot.add_y_axis({title, {-0.2, 0.2}, false, plot::AxisPlace::Left, false});
|
||||
return plot;
|
||||
};
|
||||
const auto render = [&](plot::Plot& plot) {
|
||||
@@ -1595,6 +1603,11 @@ PLOT_TEST(narrow_viewport_draws_no_y_title_it_cannot_fit) {
|
||||
// than the one column its three titled axes ask for, so no column can be staged.
|
||||
PLOT_CHECK(titled.titled_y_axis_count() == 3u);
|
||||
PLOT_CHECK(layout.y_title_area.w < r.axis_font_px() + r.style().grid_label_pad);
|
||||
// Zero wide, not merely under one column -- the labels spend the allowance whole.
|
||||
// That is this comparison's own premise as much as the clamp's: a strip with any
|
||||
// width left in it would move the label strip right in the titled scene alone, and
|
||||
// the two frames would then differ over the labels rather than over title ink.
|
||||
PLOT_CHECK(layout.y_title_area.w == 0.0f);
|
||||
// ... and the plot kept its floor in a viewport this narrow, so nothing here is
|
||||
// degenerate for some other reason.
|
||||
PLOT_CHECK(layout.axes.w >= 0.5f * static_cast<plot::f32>(kNarrowW));
|
||||
@@ -1633,9 +1646,12 @@ PLOT_TEST(narrow_viewport_draws_no_y_title_it_cannot_fit) {
|
||||
// that survive are the leading ones -- which is what "keep the leading columns"
|
||||
// means, since the renderer lays them out left to right from the strip's padding.
|
||||
PLOT_TEST(narrow_viewport_keeps_only_the_y_title_columns_that_fit) {
|
||||
// 170 px is where the clamp leaves room for exactly one column (the label strip
|
||||
// takes 51.2 px of the 85 px allowance, leaving 33.8 px against the 19.7 px a
|
||||
// column needs); the assertions below re-derive that rather than assume it.
|
||||
// 170 px is where the clamp leaves room for some of the three columns and not all
|
||||
// of them: the label strip takes 44 px of the 85 px allowance and a column needs
|
||||
// 19.7, so the 41 px left over hold two. The assertions below re-derive the count
|
||||
// from the measured strip rather than assume it, which is what lets the regime be
|
||||
// "at least one and fewer than three" instead of a pixel figure that drifts with
|
||||
// the font, the device scale or the tick labels.
|
||||
constexpr plot::u32 kNarrowW = 170;
|
||||
constexpr plot::u32 kNarrowH = 200;
|
||||
plottest::HeadlessContext ctx(kNarrowW, kNarrowH);
|
||||
@@ -1648,9 +1664,12 @@ PLOT_TEST(narrow_viewport_keeps_only_the_y_title_columns_that_fit) {
|
||||
plot::Plot p;
|
||||
p.set_viewport({0, 0, static_cast<plot::f32>(kNarrowW), static_cast<plot::f32>(kNarrowH)});
|
||||
p.add_x_axis({"", {0.0, 1.0}, false, plot::AxisPlace::Bottom, false});
|
||||
p.add_y_axis({"volts", {-1.0, 1.0}, false, plot::AxisPlace::Left, false});
|
||||
p.add_y_axis({"amps", {-1.0, 1.0}, false, plot::AxisPlace::Right, false});
|
||||
p.add_y_axis({"watts", {-1.0, 1.0}, false, plot::AxisPlace::Left, false});
|
||||
// Milli-scale for the label width, as in the zero-wide-strip case above: the strip
|
||||
// this test wants is the one that holds *some* columns and not all three, and what
|
||||
// it has left to hold them in is the allowance minus the label strip.
|
||||
p.add_y_axis({"volts", {-0.2, 0.2}, false, plot::AxisPlace::Left, false});
|
||||
p.add_y_axis({"amps", {-0.2, 0.2}, false, plot::AxisPlace::Right, false});
|
||||
p.add_y_axis({"watts", {-0.2, 0.2}, false, plot::AxisPlace::Left, false});
|
||||
r.begin_frame(kNarrowW, kNarrowH,
|
||||
{0, 0, static_cast<plot::f32>(kNarrowW), static_cast<plot::f32>(kNarrowH)});
|
||||
r.draw(p);
|
||||
|
||||
Reference in new issue
Block a user