Scoring

Helpers for sorting possible encodings

packShapes(grid,shapes)

Finds the max-cover of shapes that fits into grid with no overlaps. Uses a modified version of the Dancing Links algorithm by Donald Knuth.

Returns { score, placements, used, unused }

  • score: number of shapes that were placed
  • placements: array of shapes and their coordinates
  • used: a Grid of tiles covered by placements
  • unused: a Grid of tiles not covered by placements

findFits(grid,shapes)

Returns all possible fits of a given shape (overlapping).

Returns [{ shape, coords: {x,y} }]

groupTiles(grid, opts)

  • opts.diagonal: boolean to allow diagonal connections (default: false)
  • opts.value: value to flood-fill (default: true)

Returns shapes

outlineShape(shape)

Outlines a shape's perimeter for smooth drawing.

Returns paths: an array of array of segments [x,y,type]. The first path is the outer path, the rest of the paths are holes.