Git Product home page Git Product logo

hxpotpack's Introduction

hxpotpack

hxpotpack is the haxe port of the original potpack project.

A variation of algorithms used in rectpack2D and bin-pack, which are in turn based on this article by Blackpawn.

Ordered Example usage

import haxe.ds.Vector;
import hx.potpack.Potpack;
import hx.potpack.geom.PotpackRectangle; //or you can import "openfl.display.Rectangle" for openfl

class Test {
    static function main() {
        final boxes:Vector<PotpackRectangle> = new Vector<PotpackRectangle>(2);
        boxes.set(0, new PotpackRectangle(0, 0, 300, 50));
        boxes.set(1, new PotpackRectangle(0, 0, 100, 200));

        final data = Potpack.pack(boxes);
        trace('width: ${data.width}, height: ${data.height}, rect size: ${data.size} fill: ${data.fill}');

        // potpack mutates the boxes array: it's sorted by height,
        // and box objects are augmented with x, y coordinates:
        trace(boxes[0]); // {x: 0, y: 200, width: 300, height: 50}
        trace(boxes[1]); // {x: 0, y: 0, width: 100, height: 200}
    }
}

Unordered Example usage

import haxe.ds.Vector;
import hx.potpack.Potpack;
import hx.potpack.geom.PotpackRectangle; //or you can import "openfl.display.Rectangle" for openfl

class Test {
    static function main() {
        final boxes:Vector<PotpackRectangle> = new Vector<PotpackRectangle>(2);
        boxes.set(0, new PotpackRectangle(0, 0, 300, 50));
        boxes.set(1, new PotpackRectangle(0, 0, 100, 200));

        final data = Potpack.pack(boxes, false);
        trace('width: ${data.width}, height: ${data.height}, rect size: ${data.size} fill: ${data.fill}');

        // potpack mutates the boxes array: it's sorted by height,
        // and box objects are augmented with x, y coordinates:
        trace(boxes[0]); // {x: 0, y: 0, width: 100, height: 200}
        trace(boxes[1]); // {x: 0, y: 200, width: 300, height: 50}
    }
}

Compatibility

Compatible with all haxe projects.

There is an additional compatibility feature for OpenFL, you can use OpenFL Rectangles.

Install Release Version

Install with haxelib: haxelib install hxpotpack

Install Development Version

Install with haxelib: haxelib git hxpotpack https://github.com/barisyild/hxpotpack.git

Original project created by Mapbox

hxpotpack's People

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 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.