Skip to content

Latest commit

 

History

History
42 lines (30 loc) · 1.46 KB

README.md

File metadata and controls

42 lines (30 loc) · 1.46 KB

Squarify-rs

Build Status License

Rust implementation of the squarify algorithm.

This is a direct translation of the python implementation here. All credit goes to these developers.

Usage

Add this to your Cargo.toml:

[dependencies]
squarify = { git = "https://github.com/dweb0/squarify-rs" }

Will eventually publish to crates.io when ready.

Example

use squarify::squarify;

fn main() {
    let values = vec![500.0, 433.0, 78.0, 25.0, 25.0, 7.0];
    let rects = squarify(&values, 0.0, 0.0, 1000.0, 1000.0, None);

    for rect in rects {
        println!("{:?}", rect);
    }
    
    // Output
    // Rect { x: 0.0, y: 0.0, dx: 1000.0000000000001, dy: 468.16479400749057 }
    // Rect { x: 0.0, y: 468.16479400749057, dx: 1000.0000000000001, dy: 405.43071161048687 }
    // Rect { x: 0.0, y: 873.5955056179774, dx: 1000.0000000000001, dy: 73.03370786516854 }
    // Rect { x: 0.0, y: 946.629213483146, dx: 1000.0000000000001, dy: 23.40823970037453 }
    // Rect { x: 0.0, y: 970.0374531835206, dx: 1000.0000000000001, dy: 23.40823970037453 }
    // Rect { x: 0.0, y: 993.4456928838952, dx: 1000.0000000000001, dy: 6.5543071161048685 }
}