Giter Site home page Giter Site logo

houmain / rect_pack Goto Github PK

View Code? Open in Web Editor NEW
6.0 1.0 1.0 48 KB

A library for packing rectangles to one or more sprite sheets/atlases with optional constraints.

License: The Unlicense

C++ 69.12% C 30.88%
sprite-sheets binpacking sprite-atlas public-domain bin-packing

rect_pack's Introduction

Multi-sheet rectangle packing

A C++17 library for packing rectangles to one or more sprite sheets/atlases with optional constraints.

It is part of the spright project and utilizing Sean T. Barrett's Skyline and Jukka Jylänki's MaxRects packing algorithm implementations.

Simply pass your sheet constraints and the rectangle sizes to the pack function. It will return one or more sheets with rectangle positions. The id can be used to correlate in- and output (there are no rectangles for sizes which did not fit).

For now the header may serve as documentation:

rect_pack.h

#include <vector>

namespace rect_pack {

enum class Method {
  Best,
  Best_Skyline,
  Best_MaxRects,
  Skyline_BottomLeft,
  Skyline_BestFit,
  MaxRects_BestShortSideFit,
  MaxRects_BestLongSideFit,
  MaxRects_BestAreaFit,
  MaxRects_BottomLeftRule,
  MaxRects_ContactPointRule
};

struct Size {
  int id;
  int width;
  int height;
};

struct Rect {
  int id;
  int x;
  int y;
  int width;
  int height;
  bool rotated;
};

struct Sheet {
  int width;
  int height;
  std::vector<Rect> rects;
};

struct Settings {
  Method method;
  int max_sheets;
  bool power_of_two;
  bool square;
  bool allow_rotate;
  int align_width;
  int border_padding;
  int over_allocate;
  int min_width;
  int min_height;
  int max_width;
  int max_height;
};

std::vector<Sheet> pack(Settings settings, std::vector<Size> sizes);

} // namespace

rect_pack's People

Contributors

houmain avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 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.