Giter VIP home page Giter VIP logo

algorithm-binpack-2d's Introduction

NAME
    Algorithm::BinPack::2D - efficiently pack items into rectangles

SYNOPSIS
    `Algorithm::BinPack::2D' efficiently packs items into bins. The bins are
    given a maximum width and height, and items are packed in with as little
    empty space as possible. An example use would be backing up small images
    to concatenated images, while minimizing the number of images required.

        my $bp = Algorithm::BinPack::2D->new(binwidth => 512, binheight => 512);

        $bp->add_item(label => "one.png",   width =>  30, height =>  10);
        $bp->add_item(label => "two.png",   width => 200, height =>  40);
        $bp->add_item(label => "three.png", width =>  30, height => 300);
        $bp->add_item(label => "four.png",  width => 400, height => 100);

        for ($bp->pack_bins) {
            print "Bin width: ", $_->{width}, " x ", $_->{height}, "\n";
            print "     Item: ", $_->{label}, "\n" for @{ $_->{items} };
        }
    =cut

METHODS
    new     Creates a new `Algorithm::BinPack::2D' object. The maximum bin
            width and height is specified as a named argument 'binwidth' and
            'binheight', and is required.

                my $bp = Algorithm::BinPack::2D->new(binwidth => 512, binheight => 512);

    add_item
            Adds an item to be packed into a bin. Required named arguments
            are 'label', 'width' and 'height', but any others can be
            specified, and will be saved.

                $bp->add_item(label => 'one',  width => 1, height => 1);

    pack_bins
            Packs the items into bins. This method tries to leave as little
            empty space in each bin as possible. It returns a list of
            hashrefs with the key 'width' containing the total bin width,
            'height' containing the total bin height, and 'items' containing
            an arrayref holding the items in the bin. Each item is in turn a
            hashref containing the keys 'label', 'x', 'y', 'width' and
            'height'.

                for my $bin ($bp->pack_bins) {
                    print "Bin width: ", $bin->{width}, " x ", $bin->{height}, "\n";

                    for my $item (@{ $bin->{items} }) {
                        printf "  %-6s %-20s\n", $_, $item->{$_} for keys %{ $item };
                        print  "  ---\n";
                    }
                }

SEE ALSO
    `Algorithm::BinPack'

AUTHOR
    Tasuku SUENAGA a.k.a. gunyarakun <tasuku-s-cpan ATAT titech.ac>

LICENSE
    Copyright (C) Tasuku SUENAGA a.k.a. gunyarakun

    This library is free software; you can redistribute it and/or modify it
    under the same terms as Perl itself. =cut

algorithm-binpack-2d's People

Contributors

gunyarakun avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.