#texture #packing #packer #atlas #sprite #2d-game

rect_packer

A rectangle packing library. Heavily tested with random data to ensure that it always produces correct result.

4 releases

Uses old Rust 2015

0.2.1 Sep 22, 2017
0.2.0 Feb 14, 2017
0.1.1 Dec 30, 2016
0.1.0 Jul 17, 2016

#1176 in Game dev

Download history 359/week @ 2023-12-11 345/week @ 2023-12-18 434/week @ 2023-12-25 404/week @ 2024-01-01 376/week @ 2024-01-08 351/week @ 2024-01-15 454/week @ 2024-01-22 308/week @ 2024-01-29 510/week @ 2024-02-05 523/week @ 2024-02-12 779/week @ 2024-02-19 485/week @ 2024-02-26 677/week @ 2024-03-04 801/week @ 2024-03-11 597/week @ 2024-03-18 486/week @ 2024-03-25

2,624 downloads per month
Used in 15 crates (6 directly)

MIT license

19KB
393 lines

rect-packer Build Status

Pack multiple rectangles into a larger one. Can be used for packing sprites into a texture for 2d games. Uses skyline heuristic. Heavily tested with random data to ensure that it always produces correct result.

Documentation

Crates.io package

Skyline packer


MIT License


lib.rs:

Pack small rectangles into a larger one. This is useful for creating texture atlases for the efficient GPU rendering.

Usage example:

use rect_packer::Packer;

let config = rect_packer::Config {
    width: 1024,
    height: 1024,

    border_padding: 5,
    rectangle_padding: 10,
};

let rectangles = [(50, 70), (350, 210), (255, 410)];

let mut packer = Packer::new(config);
for &(width, height) in &rectangles {
    if let Some(rect) = packer.pack(width, height, false) {
        println!("Rectangle is at position ({}, {}) within the encompassing rectangle",
            rect.x,
            rect.y);
    }
}

No runtime deps