use rizzma::core::color::Rgba;
use rizzma::figure::Figure;
use rizzma::skia::SkiaRenderer;
fn is_ink(r: &SkiaRenderer, x: u32, y: u32) -> bool {
let p = r.pixmap().pixel(x, y).expect("pixel in bounds");
p.alpha() > 200 && (p.red() as u16 + p.green() as u16 + p.blue() as u16) < 600
}
#[test]
fn axhline_renders_full_width_horizontal_line() {
let mut fig = Figure::new(4.0, 4.0).with_dpi(100.0);
let ax = fig.add_axes(0.1, 0.1, 0.8, 0.8);
ax.set_xlim(0.0, 1.0);
ax.set_ylim(0.0, 1.0);
ax.set_facecolor(Rgba::WHITE);
ax.axhline(0.5);
let r = fig.render();
let (w_px, h_px) = fig.size_px();
let h = h_px as u32;
let ax_x0 = (0.1 * w_px) as u32;
let ax_x1 = (0.9 * w_px) as u32;
let center_row = h / 2;
let mut best_row = center_row;
let mut best_count = 0u32;
for row in (center_row.saturating_sub(3))..=(center_row + 3).min(h - 1) {
let mut count = 0;
for x in (ax_x0 + 2)..(ax_x1 - 2) {
if is_ink(&r, x, row) {
count += 1;
}
}
if count > best_count {
best_count = count;
best_row = row;
}
}
let axes_width = ax_x1 - ax_x0;
assert!(
best_count as f64 > 0.9 * f64::from(axes_width),
"axhline should span ~full axes width: covered {best_count} of {axes_width} \
columns at row {best_row}"
);
assert!(
best_row.abs_diff(center_row) <= 3,
"line row {best_row} should be near the axes center {center_row}"
);
}