gled-model 2.32.1

The data model of gled: projects, scenes, effects, animations, curves and assets
Documentation
//! Fixture definitions and asset collections that tests build their patches
//! from, here and in the crates that render patches (`test-support` feature).

use crate::asset::Asset;
use crate::asset_id::AssetId;
use crate::collection::{Collection, Collections};
use crate::patching::definition::{ColorOrder, FixtureDefinition, Mode, Pixel};

/// An RGB pixel named `pixel-<index>`, `x_m` right of the fixture's origin.
pub fn rgb_pixel(index: usize, x_m: f32) -> Pixel {
    Pixel::new(format!("pixel-{index}"), [x_m, 0.0, 0.0], ColorOrder::Rgb)
}

/// A bar `length_m` long and 5 cm wide of `count` RGB pixels, spread evenly
/// and centred on its origin, with the "individual" mode only.
pub fn rgb_bar(count: usize, length_m: f32) -> FixtureDefinition {
    FixtureDefinition {
        size_m: [length_m, 0.05, 0.05],
        pixels: (0..count)
            .map(|i| {
                rgb_pixel(
                    i,
                    (i as f32 + 0.5) / count as f32 * length_m - length_m / 2.0,
                )
            })
            .collect(),
        modes: vec![Mode::individual(count)],
        ..Default::default()
    }
}

/// An asset collection holding `definitions`, and their ids in order.
/// Definitions come from the asset folder, so tests supply them explicitly.
pub fn collections_with(
    definitions: Vec<FixtureDefinition>,
) -> (Collections, Vec<AssetId<FixtureDefinition>>) {
    let mut collection = Collection::<FixtureDefinition>::default();
    let ids = definitions
        .into_iter()
        .enumerate()
        .map(|(index, data)| {
            let asset = Asset {
                id: AssetId::new(),
                path: vec![format!("Definition {index}")],
                data,
            };
            let id = asset.id;
            collection.set_asset(asset);
            id
        })
        .collect();
    let mut collections = Collections::default();
    collections.insert(collection);
    (collections, ids)
}