b09795ccff
- Add `persistence.rs` for stable serialization of dock layouts without runtime identifiers. - Introduce `preview.rs` for geometry handling of dock drop previews. - Create `sizing.rs` to manage content-aware sizing policies and constraint solving for dock panels. - Implement `welcome.rs` to provide a welcome surface when no documents are open, featuring New and Open actions.
73 lines
2.0 KiB
Rust
73 lines
2.0 KiB
Rust
use hcie_engine_api::{BrushStyle, BrushTip, Engine};
|
|
|
|
#[test]
|
|
fn bitmap_brush_stamp_shape() {
|
|
let mut engine = Engine::new(64, 64);
|
|
// 4x4 solid white square bitmap stamp
|
|
let mut pixels = vec![0u8; 16];
|
|
for i in 0..16 {
|
|
pixels[i] = 255;
|
|
}
|
|
let brush = BrushTip {
|
|
style: BrushStyle::Bitmap,
|
|
size: 8.0,
|
|
opacity: 1.0,
|
|
hardness: 1.0,
|
|
spacing: 1.0,
|
|
bitmap_pixels: pixels,
|
|
bitmap_w: 4,
|
|
bitmap_h: 4,
|
|
..Default::default()
|
|
};
|
|
engine.set_brush_tip(brush);
|
|
engine.begin_stroke(engine.active_layer_id(), 20.0, 20.0);
|
|
engine.stroke_to(engine.active_layer_id(), 20.0, 20.0, 1.0);
|
|
engine.end_stroke(engine.active_layer_id());
|
|
let output = engine.get_composite_pixels();
|
|
|
|
// Check that the painted area is roughly 4x4, not a circular blob.
|
|
// Count alpha > 0 pixels and bounding box.
|
|
let mut min_x = 63;
|
|
let mut max_x = 0;
|
|
let mut min_y = 63;
|
|
let mut max_y = 0;
|
|
let mut count = 0;
|
|
for y in 0..64 {
|
|
for x in 0..64 {
|
|
let a = output[(y * 64 + x) * 4 + 3];
|
|
if a > 0 {
|
|
count += 1;
|
|
if x < min_x {
|
|
min_x = x;
|
|
}
|
|
if x > max_x {
|
|
max_x = x;
|
|
}
|
|
if y < min_y {
|
|
min_y = y;
|
|
}
|
|
if y > max_y {
|
|
max_y = y;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
let w = (max_x - min_x + 1) as i32;
|
|
let h = (max_y - min_y + 1) as i32;
|
|
// Should fit inside ~8x8 because size=8 and stamp 4x4 scaled up
|
|
assert!(
|
|
w <= 8 && h <= 8,
|
|
"bitmap dab bounding box {}x{} too large for 4x4 stamp",
|
|
w,
|
|
h
|
|
);
|
|
assert!(count >= 8, "bitmap dab should paint some pixels");
|
|
// Square-ish: aspect ratio not too far from 1 (was very low for circle vs square?)
|
|
assert!(
|
|
w.abs_diff(h) <= 2,
|
|
"bitmap dab bounding box should be roughly square, got {}x{}",
|
|
w,
|
|
h
|
|
);
|
|
}
|