datasaurust 0.1.0

Blazingly fast implementation of the Datasaurus paper.
Documentation
use crate::types::Line;

// Return the list of lines that define the shape
pub fn get_shape(shape: &str, offset_x: f32, offset_y: f32) -> Vec<Line> {
    // Segments defining a cross
    let cross = vec![((20.0, 0.0), (100.0, 100.0)), ((20.0, 100.0), (100.0, 0.0))];

    // Segments defining a cat
    let cat = vec![
        ((34.84, 87.62), (43.20, 73.93)),
        ((43.20, 73.93), (56.88, 76.43)),
        ((56.88, 76.43), (70.32, 73.57)),
        ((70.32, 73.57), (81.84, 86.07)),
        ((81.84, 86.07), (86.64, 56.79)),
        ((86.64, 56.79), (85.92, 33.21)),
        ((85.92, 33.21), (74.88, 10.00)),
        ((74.88, 10.00), (60.24, 3.57)),
        ((60.24, 3.57), (42.48, 7.50)),
        ((42.48, 7.50), (35.04, 17.86)),
        ((35.04, 17.86), (29.52, 31.07)),
        ((29.52, 31.07), (28.56, 48.21)),
        ((28.56, 48.21), (29.04, 68.93)),
        ((29.04, 68.93), (34.84, 87.62)),
        ((57.88, 36.55), (56.64, 27.86)),
        ((56.64, 27.86), (50.16, 22.86)),
        ((50.16, 22.86), (45.12, 28.21)),
        ((57.16, 29.40), (60.96, 23.57)),
        ((60.96, 23.57), (66.96, 23.93)),
        ((66.96, 23.93), (70.56, 27.50)),
        ((46.71, 58.59), (46.70, 54.19)),
        ((46.70, 54.19), (46.71, 58.59)),
        ((66.85, 57.97), (66.83, 54.19)),
        ((66.83, 54.19), (66.85, 57.97)),
    ];

    // Segments defining a cat silhouette
    let cat_silhouette = vec![
        ((22.87, 46.36), (27.94, 63.86)),
        ((27.94, 63.86), (38.84, 80.95)),
        ((38.84, 80.95), (49.81, 93.42)),
        ((49.81, 93.42), (59.57, 95.59)),
        ((59.57, 95.59), (58.88, 85.30)),
        ((58.88, 85.30), (56.08, 72.34)),
        ((56.08, 72.34), (54.40, 68.27)),
        ((67.25, 87.29), (80.10, 93.59)),
        ((80.10, 93.59), (75.19, 72.98)),
        ((75.19, 72.98), (78.51, 66.20)),
        ((78.51, 66.20), (79.22, 43.04)),
        ((79.22, 43.04), (80.13, 38.58)),
        ((80.13, 38.58), (82.26, 34.38)),
        ((82.26, 34.38), (81.62, 29.12)),
        ((81.62, 29.12), (71.70, 18.02)),
        ((71.70, 18.02), (56.09, 19.75)),
        ((60.97, 81.55), (75.19, 72.98)),
        ((59.56, 19.27), (61.48, 1.01)),
    ];

    // Segments defining a dog
    let dog = vec![
        ((33.94, 68.38), (32.23, 59.31)),
        ((32.23, 59.31), (31.99, 43.60)),
        ((31.99, 43.60), (34.82, 31.32)),
        ((34.82, 31.32), (40.61, 22.52)),
        ((40.61, 22.52), (50.18, 17.21)),
        ((50.18, 17.21), (63.24, 17.60)),
        ((63.24, 17.60), (74.58, 24.78)),
        ((74.58, 24.78), (79.28, 35.03)),
        ((79.28, 35.03), (82.28, 33.21)),
        ((82.28, 33.21), (87.30, 35.58)),
        ((87.30, 35.58), (89.49, 43.97)),
        ((89.49, 43.97), (89.47, 57.12)),
        ((89.47, 57.12), (85.84, 70.72)),
        ((85.84, 70.72), (76.61, 82.35)),
        ((76.61, 82.35), (63.18, 87.43)),
        ((63.18, 87.43), (40.34, 86.04)),
        ((40.34, 86.04), (28.44, 72.76)),
        ((28.44, 72.76), (23.65, 57.93)),
        ((23.65, 57.93), (23.18, 42.47)),
        ((23.18, 42.47), (26.20, 36.53)),
        ((26.20, 36.53), (30.63, 33.14)),
        ((30.63, 33.14), (34.53, 33.71)),
        ((56.60, 43.65), (56.22, 35.58)),
        ((56.22, 35.58), (50.38, 29.80)),
        ((50.38, 29.80), (43.65, 31.80)),
        ((43.65, 31.80), (41.89, 39.84)),
        ((56.22, 35.58), (61.84, 29.71)),
        ((61.84, 29.71), (67.63, 30.86)),
        ((67.63, 30.86), (70.33, 35.56)),
        ((70.33, 35.56), (71.07, 41.55)),
        ((45.03, 60.05), (45.16, 54.23)),
        ((67.52, 59.27), (67.52, 54.31)),
        ((79.28, 35.03), (80.61, 55.40)),
        ((80.61, 55.40), (76.70, 69.06)),
    ];

    let rabbit = vec![
        ((53.97, 62.73), (46.38, 60.13)),
        ((46.38, 60.13), (43.50, 57.79)),
        ((43.50, 57.79), (30.67, 37.51)),
        ((30.67, 37.51), (30.70, 34.63)),
        ((30.70, 34.63), (33.28, 33.16)),
        ((33.28, 33.16), (33.80, 28.80)),
        ((33.80, 28.80), (37.89, 24.62)),
        ((37.89, 24.62), (46.00, 23.00)),
        ((46.00, 23.00), (50.84, 23.08)),
        ((45.85, 46.09), (48.24, 45.91)),
        ((48.24, 45.91), (50.88, 47.84)),
        ((58.27, 55.02), (59.42, 61.48)),
        ((59.42, 61.48), (61.47, 67.76)),
        ((61.47, 67.76), (65.65, 74.51)),
        ((65.65, 74.51), (71.28, 80.21)),
        ((71.28, 80.21), (75.39, 82.48)),
        ((75.39, 82.48), (76.50, 75.59)),
        ((76.50, 75.59), (74.63, 67.89)),
        ((74.63, 67.89), (71.57, 60.89)),
        ((71.57, 60.89), (67.48, 55.27)),
        ((67.48, 55.27), (65.26, 53.07)),
        ((70.18, 55.95), (74.03, 51.48)),
        ((74.03, 51.48), (78.83, 40.44)),
        ((78.83, 40.44), (83.50, 41.85)),
        ((83.50, 41.85), (88.53, 43.01)),
        ((46.00, 23.00), (48.51, 15.35)),
        ((48.51, 15.35), (52.58, 8.25)),
        ((52.58, 8.25), (54.31, 6.75)),
    ];

    let penguin = vec![
        ((32.30, 39.45), (32.56, 51.24)),
        ((32.56, 51.24), (37.91, 64.35)),
        ((37.91, 64.35), (44.56, 73.01)),
        ((44.56, 73.01), (54.65, 76.74)),
        ((54.65, 76.74), (67.78, 72.08)),
        ((67.78, 72.08), (75.94, 56.31)),
        ((75.94, 56.31), (78.85, 37.03)),
        ((78.85, 37.03), (76.70, 23.82)),
        ((76.70, 23.82), (68.41, 16.78)),
        ((68.41, 16.78), (60.83, 13.81)),
        ((60.83, 13.81), (49.76, 14.05)),
        ((49.76, 14.05), (42.83, 15.74)),
        ((42.83, 15.74), (34.89, 23.17)),
        ((34.89, 23.17), (31.84, 32.37)),
        ((31.69, 44.87), (25.90, 45.16)),
        ((25.90, 45.16), (23.55, 41.56)),
        ((23.55, 41.56), (25.80, 35.32)),
        ((25.80, 35.32), (31.84, 32.37)),
        ((78.28, 45.64), (85.34, 43.72)),
        ((85.34, 43.72), (86.54, 40.09)),
        ((86.54, 40.09), (84.33, 35.39)),
        ((84.33, 35.39), (77.77, 30.21)),
        ((38.36, 20.49), (41.99, 38.37)),
        ((41.99, 38.37), (38.92, 46.05)),
        ((38.92, 46.05), (38.14, 53.71)),
        ((38.14, 53.71), (41.53, 61.06)),
        ((41.53, 61.06), (47.48, 64.00)),
        ((47.48, 64.00), (54.38, 61.68)),
        ((54.38, 61.68), (62.28, 64.07)),
        ((62.28, 64.07), (68.38, 62.24)),
        ((68.38, 62.24), (72.06, 53.66)),
        ((72.06, 53.66), (71.24, 45.85)),
        ((71.24, 45.85), (68.29, 40.50)),
        ((68.29, 40.50), (72.48, 20.44)),
        ((42.83, 15.74), (45.33, 11.27)),
        ((45.33, 11.27), (50.76, 10.59)),
        ((50.76, 10.59), (52.90, 14.25)),
        ((57.95, 13.39), (60.07, 10.20)),
        ((60.07, 10.20), (63.90, 10.54)),
        ((63.90, 10.54), (66.20, 13.50)),
        ((66.20, 13.50), (68.41, 16.78)),
        ((51.65, 49.05), (52.61, 44.23)),
        ((52.61, 44.23), (55.67, 42.24)),
        ((55.67, 42.24), (57.95, 45.43)),
        ((57.95, 45.43), (58.83, 50.21)),
        ((58.83, 50.21), (56.99, 52.31)),
        ((56.99, 52.31), (53.23, 52.60)),
        ((44.73, 54.22), (46.65, 56.63)),
        ((46.65, 56.63), (49.21, 53.39)),
        ((49.21, 53.39), (49.24, 53.80)),
        ((61.12, 54.26), (63.53, 56.84)),
        ((63.53, 56.84), (65.21, 53.40)),
    ];

    let whale = vec![
        ((30.68, 73.59), (48.41, 68.64)),
        ((48.41, 68.64), (55.63, 64.07)),
        ((55.63, 64.07), (60.69, 56.39)),
        ((60.69, 56.39), (65.26, 64.66)),
        ((65.26, 64.66), (74.61, 70.46)),
        ((74.61, 70.46), (90.69, 73.94)),
        ((90.69, 73.94), (87.11, 61.55)),
        ((87.11, 61.55), (84.00, 55.57)),
        ((84.00, 55.57), (68.38, 46.83)),
        ((68.38, 46.83), (66.10, 40.54)),
        ((66.10, 40.54), (67.27, 29.70)),
        ((30.68, 73.59), (33.00, 63.53)),
        ((33.00, 63.53), (38.78, 53.37)),
        ((38.78, 53.37), (51.65, 47.34)),
        ((51.65, 47.34), (54.31, 43.26)),
        ((54.31, 43.26), (53.53, 30.02)),
        ((29.93, 25.08), (34.37, 27.57)),
        ((34.37, 27.57), (39.06, 27.73)),
        ((39.06, 27.73), (44.66, 24.94)),
        ((44.66, 24.94), (51.79, 27.55)),
        ((51.79, 27.55), (54.64, 27.39)),
        ((54.64, 27.39), (60.07, 24.04)),
        ((60.07, 24.04), (67.77, 27.56)),
        ((67.77, 27.56), (69.74, 27.55)),
        ((69.74, 27.55), (75.83, 24.12)),
        ((75.83, 24.12), (83.63, 27.17)),
        ((83.63, 27.17), (86.39, 27.25)),
        ((86.39, 27.25), (91.27, 24.81)),
    ];

    let mut lines = match shape {
        "cat" => cat,
        "cat_s" => cat_silhouette,
        "dog" => dog,
        "rabbit" => rabbit,
        "cross" => cross,
        "penguin" => penguin,
        "whale" => whale,
        _ => panic!("Unknown shape"),
    };

    // Offset the segments if needed
    if offset_x != 0.0 || offset_y != 0.0 {
        lines.iter_mut().for_each(|line| {
            line.0 = (line.0 .0 + offset_x, line.0 .1 + offset_y);
            line.1 = (line.1 .0 + offset_x, line.1 .1 + offset_y);
        });
    }

    lines
}