getQSizeList method

List<QSize> getQSizeList(
  1. T post,
  2. int nMax
)

Retrieves or computes size options for a tile, sorted by area and aspect deviation.

Caches QSize variants within style constraints, filtering scalar tiles if disallowed. Used in buildQuilt for placement candidates, integrating with getAspect for proportion matching.

Implementation

List<QSize> getQSizeList(T post, int nMax) {
  String id = tileFaucet.getID(post);
  if (!qSizeCache.containsKey(id) || qSizeCache[id]!.length != nMax) {
    List<QSize> options = [];
    double aspect = tileFaucet.getAspect(post);
    for (int i = min(style.minTileWidth, style.maxTileWidth);
        i <= min(style.maxTileWidth, style.carpetWidth);
        i++) {
      for (int j = min(style.minTileHeight, style.maxTileHeight);
          j <= style.maxTileHeight;
          j++) {
        if (!style.allowScalarTiles && QSize(i, j, 0).canBeReduced) {
          continue;
        }

        double d = (i / j - aspect).abs();
        options.add(QSize(i, j, d));
      }
    }

    options.sort((a, b) => (a.w * a.h).compareTo(b.w * b.h));
    options.sort((a, b) => a.d.compareTo(b.d));
    qSizeCache[id] = options.take(nMax).toList();
  }

  return qSizeCache[id]!;
}