Files
Martino Ferrari ed3a8ce645 licence: MIT LICENSE and SPDX identifiers in every first-party file
The repository had no licence at all, so every source was all-rights-reserved
by default. Add the verbatim MIT text at LICENSE (Copyright (c) 2026 Martino
Ferrari) and a two-line SPDX header to each of the 113 first-party sources --
48 include/plot, 26 src, 10 adapters, 5 examples, 21 tests, 3 tools -- so the
grant travels with each file rather than relying on the root document alone.

Scripts keep their shebang on line 1; the SPDX lines follow it. Genuinely
vendored code is untouched: third_party/stb_truetype.h carries no header of
ours. src/render/embedded_mono_font.cpp is generated, so tools/fonts/gen_atlas.py
emit() now writes the two lines into its header comment and the file was
regenerated -- gen_atlas.py --check passes and the regeneration adds only those
comment lines to the previously committed file.

README's provenance section now states MIT and links LICENSE.

No code, test or public API change.
2026-09-28 22:13:40 +02:00

52 lines
1.4 KiB
C++

// SPDX-License-Identifier: MIT
// SPDX-FileCopyrightText: 2026 Martino Ferrari
#pragma once
#include <cmath>
#include <plot/core/types.hpp>
namespace plot::math {
/// Affine data->screen mapping: `screen = data * s + t`, applied after `log10`
/// when the corresponding log flag is set.
struct Transform {
f64 sx = 1.0, tx = 0.0;
f64 sy = 1.0, ty = 0.0;
bool log_x = false, log_y = false;
f64 to_screen_x(f64 x) const noexcept {
const f64 v = log_x ? log10_positive(x) : x;
return v * sx + tx;
}
f64 to_screen_y(f64 y) const noexcept {
const f64 v = log_y ? log10_positive(y) : y;
return v * sy + ty;
}
f64 to_data_x(f64 screen_x) const noexcept {
const f64 v = (screen_x - tx) / sx;
return log_x ? std::pow(10.0, v) : v;
}
f64 to_data_y(f64 screen_y) const noexcept {
const f64 v = (screen_y - ty) / sy;
return log_y ? std::pow(10.0, v) : v;
}
/// Set scale/offset so `x` and `y` map onto `[px0,px1]` and `[py0,py1]`.
/// A degenerate range is widened by +/-0.5 in the (possibly logarithmic)
/// coordinate so the resulting mapping always stays invertible.
static Transform from_range(Range x, Range y, f64 px0, f64 px1, f64 py0, f64 py1, bool lx,
bool ly) noexcept;
/// `log10` of `v`, with `v` clamped to at least 1e-300 first.
static f64 log10_positive(f64 v) noexcept;
};
} // namespace plot::math
namespace plot {
using math::Transform;
}