package grenier

  1. Overview
  2. Docs
type 'bin t
val empty : 'bin t
val add_bin : 'bin -> int -> int -> 'bin t -> 'bin t

make ~width ~height return a packer ready to place stuff in a width * height area

type 'tag box = {
  1. tag : 'tag;
  2. width : int;
  3. height : int;
  4. allow_rotation : bool;
    (*

    can the box be rotated to optimize packing

    *)
}

Input to packing is a box

val box : ?allow_rotation:bool -> 'tag -> int -> int -> 'tag box
type ('bin, 'tag) rect = {
  1. x : int;
  2. y : int;
  3. w : int;
  4. h : int;
  5. rotated : bool;
    (*

    True iff the input box was rotated. If true, w = box.height && h = box.width Otherwise, w = box.width && h = box.height

    *)
  6. bin : 'bin;
  7. box : 'tag box;
}

Output of packing is an optional rectangle

type heuristic = [
  1. | `Short_side_fit
  2. | `Long_side_fit
  3. | `Area_fit
  4. | `Bottom_left
]
val insert : 'bin t -> ?heuristic:heuristic -> 'tag box -> 'bin t * ('bin, 'tag) rect option

Online insertion of one item. Efficient but the packing is not very good.

Worst-case: O(n^3) (n is total number of items inserted).

val insert_batch : 'bin t -> ?heuristic:heuristic -> 'tag box list -> 'bin t * ('bin, 'tag) rect option list

Online insertion of a batch of items. Runtime is roughly the cost of inserting each item independently, but order of insertion is chosen to give a better packing.

Worst-case: O(n^4) (n is total number of items inserted).

val insert_global : 'bin t -> ?heuristic:heuristic -> 'tag box list -> 'bin t * ('bin, 'tag) rect option list

Offline insertion. Better packing but way too slow for real-time usage.

Worst-case: O(n^5) (n is total number of items inserted).

OCaml

Innovation. Community. Security.