Crate streemap[][src]

Set of tree map algorithms

Algorithms:

  • Slice and Dice 😵.
  • Binary.
  • Squarified by Bruls, Mark; Huizing, Kees; van Wijk, Jarke J. (2000).

Example:

use streemap::Rect;

const R0: Rect<f32> = Rect { x: 0., y: 0., w: 0., h: 0. };
let mut slice = [(6., R0), (6., R0), (4., R0), (3., R0), (2., R0), (2., R0), (1., R0)];
streemap::squarify(
    Rect { x: 0., y: 0., w: 6., h: 4. },
    &mut slice[..],
    |&(n, _)| n, // map item to item size
    |(_, item_r), r| *item_r = r, // set item distributed rect
);
assert_eq!(
    slice,
    [
        (6.0, Rect { x: 0.0, y: 0.0, w: 3.0, h: 2.0 }),
        (6.0, Rect { x: 0.0, y: 2.0, w: 3.0, h: 2.0 }),
        (4.0, Rect { x: 3.0, y: 0.0, w: 1.7142857, h: 2.3333333 }),
        (3.0, Rect { x: 4.714286, y: 0.0, w: 1.2857141, h: 2.3333333 }),
        (2.0, Rect { x: 3.0, y: 2.3333333, w: 1.1999999, h: 1.6666667 }),
        (2.0, Rect { x: 4.2, y: 2.3333333, w: 1.1999999, h: 1.6666667 }),
        (1.0, Rect { x: 5.3999996, y: 2.3333333, w: 0.60000014, h: 1.6666667 })
    ]
);
streemap::binary(
    Rect { x: 0., y: 0., w: 6., h: 4. },
    &mut slice[..],
    |&(n, _)| n, // map item to item size
    |(_, item_r), r| *item_r = r, // set item distributed rect
);
assert_eq!(
    slice,
    [
        (6.0, Rect { x: 0.0, y: 0.0, w: 3.0, h: 2.0 }),
        (6.0, Rect { x: 0.0, y: 2.0, w: 3.0, h: 2.0 }),
        (4.0, Rect { x: 3.0, y: 0.0, w: 3.0, h: 1.3333334 }),
        (3.0, Rect { x: 3.0, y: 1.3333334, w: 1.125, h: 2.6666665 }),
        (2.0, Rect { x: 4.125, y: 1.3333334, w: 1.875, h: 1.0666667 }),
        (2.0, Rect { x: 4.125, y: 2.4, w: 1.25, h: 1.5999999 }),
        (1.0, Rect { x: 5.375, y: 2.4, w: 0.625, h: 1.5999999 })
    ]
);

Structs

Rect

A simple rect

Functions

binary

Distribute items inside rect by splitting it recursively in 2 areas close to the same sizes.

dice

Distribute items inside rect horizontally.

ordered_pivot_by_middle

Distribute items inside rect by splitting it recursively around pivot by middle in 4 areas

ordered_pivot_by_size

Distribute items inside rect by splitting it recursively around pivot by size in 4 areas

slice

Distribute items inside rect vertically.

squarify

Distribute items inside rect while trying to get the aspect ratio as close to 1 as possible.