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.
54 lines
2.2 KiB
C++
54 lines
2.2 KiB
C++
// SPDX-License-Identifier: MIT
|
|
// SPDX-FileCopyrightText: 2026 Martino Ferrari
|
|
|
|
#pragma once
|
|
#include <vector>
|
|
|
|
#include <plot/core/types.hpp>
|
|
#include <plot/plot/axis.hpp>
|
|
#include <plot/plot/ticks.hpp>
|
|
|
|
namespace plot {
|
|
|
|
/// One grid line as a segment in DATA coordinates. The renderer maps the
|
|
/// endpoints through its transform, so pan and zoom move grid lines for free --
|
|
/// baking screen coordinates in here would break that uniform-only contract.
|
|
struct GridLine {
|
|
f64 x0 = 0.0, y0 = 0.0, x1 = 0.0, y1 = 0.0;
|
|
/// The class of the tick this segment came from: a major (labelled) tick, or one
|
|
/// of the minor subdivisions between them. The renderer picks the class' colour
|
|
/// and width from it, so the tick set is the one source for grid positions and
|
|
/// `Style` the one place that decides how a class looks and whether it is drawn.
|
|
bool major = true;
|
|
};
|
|
|
|
/// Tick-aligned grid geometry: one segment per tick, spanning the perpendicular
|
|
/// axis' full range.
|
|
class Grid {
|
|
///
|
|
/// Every tick within the perpendicular range contributes a segment, whatever its
|
|
/// class, tagged by it. Whether a class is *drawn* is style rather than geometry:
|
|
/// the renderer checks `Style::grid_major_visible` / `grid_minor_visible` per class
|
|
/// before it stages a segment, which is the only switch for that behaviour (spec
|
|
/// §11). A `Grid` therefore carries both classes' geometry whatever the style says,
|
|
/// and a caller that draws it itself applies the same two switches.
|
|
public:
|
|
bool vertical = true; ///< emit lines at x ticks
|
|
bool horizontal = true; ///< emit lines at y ticks
|
|
|
|
/// Rebuilds the segments from each axis' ticks and range. Ticks outside the
|
|
/// perpendicular range (or non-finite) are skipped, so a stale tick list can
|
|
/// never draw a line off the plot area. `out`-style: clears then appends.
|
|
void build(const std::vector<Tick>& x_ticks, Range x_range,
|
|
const std::vector<Tick>& y_ticks, Range y_range);
|
|
|
|
const std::vector<GridLine>& lines() const noexcept { return lines_; }
|
|
usize size() const noexcept { return lines_.size(); }
|
|
void clear() noexcept { lines_.clear(); }
|
|
|
|
private:
|
|
std::vector<GridLine> lines_;
|
|
};
|
|
|
|
} // namespace plot
|