gled-ui 2.31.1

gled's egui interface, shared by the desktop app and the browser
Documentation
use super::*;
use egui::pos2;
use gled_model::patching::definition::{EmittedColor, Model, Pixel};

fn bar() -> FixtureDefinition {
    FixtureDefinition {
        size_m: [1.0, 0.05, 0.05],
        models: vec![Model {
            name: "led".to_string(),
            size_m: [0.01, 0.03],
            svg: String::new(),
        }],
        outline: None,
        pixels: vec![Pixel {
            name: "pixel-0".to_string(),
            model: 0,
            position_m: [0.0; 3],
            rotation: 0.0,
            channels: vec![EmittedColor::Red, EmittedColor::Green, EmittedColor::Blue],
        }],
        modes: vec![gled_model::patching::definition::Mode::individual(1)],
        ..Default::default()
    }
}

/// Signal runs along a tube, so DMX in and out sit at its two ends — the
/// same axis its pixels and scale handles use. Putting them on the sides
/// makes the fixture read as if it were wired across its width.
#[test]
fn terminals_sit_at_the_ends_of_the_length_axis() {
    let definition = bar();
    let position = LayoutPosition::at(pos2(500.0, 500.0));
    let fixture = FixtureUI::new(
        FixtureId::new(),
        &position,
        &definition,
        None,
        Color32::WHITE,
        false,
        true,
        TSTransform::default(),
    );

    let input = fixture.input_terminal();
    let output = fixture.output_terminal();

    // a 1 m fixture spans 100 units, centred on its position
    assert!((input.x - 450.0).abs() < 0.5, "input at the near end");
    assert!((input.y - 500.0).abs() < 0.5, "input on the centre line");
    assert!(output.x > 550.0, "output beyond the far end");
    assert!((output.y - 500.0).abs() < 0.5, "output on the centre line");
    assert!(output.x > input.x, "signal runs along the tube");
}

/// Rotating the fixture carries its terminals with it.
#[test]
fn terminals_follow_the_fixtures_rotation() {
    let definition = bar();
    let position = LayoutPosition::new(pos2(500.0, 500.0), std::f32::consts::FRAC_PI_2, [1.0, 1.0]);
    let fixture = FixtureUI::new(
        FixtureId::new(),
        &position,
        &definition,
        None,
        Color32::WHITE,
        false,
        true,
        TSTransform::default(),
    );

    let input = fixture.input_terminal();
    // a quarter turn puts the near end above the fixture instead of left
    assert!((input.x - 500.0).abs() < 0.5);
    assert!((input.y - 450.0).abs() < 0.5);
}