crisol-plot-core 1.8.1

Crisol plot core: the egui-free math behind the plot, axis ticks, analysis, filters, and decimation.
Documentation
#![allow(missing_docs)]

//! Plot decimation baseline: thin and simplify a million-point line in a 900×600 frame.
//!
//! The headless core owns the computation, so this benchmark runs without a window or a
//! GPU. Compare a change against `cargo bench -p crisol-plot-core --bench plot_decimation`.

use std::hint::black_box;

use crisol_core::data::Bounds;
use crisol_plot_core::axis::Scale;
use crisol_plot_core::decimate::{LINE_SPACING, SIMPLIFY_TOLERANCE, simplify, thin};
use crisol_plot_core::transform::{ScreenPoint, ScreenRect, Transform};
use criterion::{Criterion, criterion_group, criterion_main};

fn million_points() -> Vec<[f64; 2]> {
    (0..1_000_000)
        .map(|index| {
            let t = index as f64 * 0.001;
            [t, (t * 0.7).sin() + (t * 3.1).cos() * 0.15]
        })
        .collect()
}

fn transform() -> Transform {
    Transform {
        frame: ScreenRect::from_min_size(ScreenPoint::ZERO, 900.0, 600.0),
        view: Bounds::from_corners([0.0, -1.5], [1000.0, 1.5]),
        x_scale: Scale::Linear,
        y_scale: Scale::Linear,
        y2: None,
    }
}

fn bench_plot(criterion: &mut Criterion) {
    let data = million_points();
    let view = transform();
    let mut group = criterion.benchmark_group("plot_decimation");
    group.sample_size(30);

    group.bench_function("thin_1m_900x600", |bencher| {
        bencher.iter(|| {
            let kept = thin(black_box(&view), black_box(&data), LINE_SPACING);
            black_box(kept);
        });
    });

    group.bench_function("simplify_1m_900x600", |bencher| {
        let screen: Vec<ScreenPoint> = data.iter().map(|point| view.to_screen(*point)).collect();
        bencher.iter(|| {
            let simple = simplify(black_box(screen.clone()), SIMPLIFY_TOLERANCE);
            black_box(simple);
        });
    });

    group.finish();
}

criterion_group!(benches, bench_plot);
criterion_main!(benches);