This commit is contained in:
mike
2026-01-23 13:16:48 +01:00
parent d0b64fac5f
commit c21ad114dc

View File

@@ -108,13 +108,6 @@ public record Export() {
for (var h = grid.hi & MASK_HI & ~cl.hi; h != X; h &= h - 1) stream.accept(Lettrix.from(64 | Long.numberOfTrailingZeros(h), grid.g)); for (var h = grid.hi & MASK_HI & ~cl.hi; h != X; h &= h - 1) stream.accept(Lettrix.from(64 | Long.numberOfTrailingZeros(h), grid.g));
return stream.build(); return stream.build();
} }
public char humanAt(int r, int c) {
int idx = c * R + r;
if (idx < 0 || idx >= 128) return '#';
boolean hasLetter = (idx < 64) ? ((grid.lo & MASK_LO & ~cl.lo) & (1L << idx)) != 0
: ((grid.hi & MASK_HI & ~cl.hi) & (1L << (idx - 64))) != 0;
return hasLetter ? LETTER(grid.g[idx]) : '#';
}
public String[] exportGrid(Slotinfo[] slots, Replacar clueChar, char emptyFallback) { public String[] exportGrid(Slotinfo[] slots, Replacar clueChar, char emptyFallback) {
var sb = INIT_GRID_OUTPUT_ARR.clone(); var sb = INIT_GRID_OUTPUT_ARR.clone();
for (var slot : slots) { for (var slot : slots) {
@@ -271,23 +264,31 @@ public record Export() {
} }
// 3) render gridv2 over cropped bounds (out-of-bounds become '#') // 3) render gridv2 over cropped bounds (out-of-bounds become '#')
var gridv2 = new String[Math.max(0, maxR - minR + 1)]; final int MINR = minR, MINC = minC;
for (int r = minR, i = 0; r <= maxR; r++, i++) { int height = Math.max(0, maxR - minR + 1);
var row = new StringBuilder(Math.max(0, maxC - minC + 1)); int width = Math.max(0, maxC - minC + 1);
for (var c = minC; c <= maxC; c++) row.append(grid.humanAt(r, c)); byte[] template = new byte[height * (width + 1)];
gridv2[i] = row.toString(); Arrays.fill(template, (byte) '#');
} for (int i = width; i < template.length; i += width + 1) template[i] = (byte) '\n';
grid.forEach(l -> {
int rr = l.row() - MINR;
int cc = l.col() - MINC;
if (rr >= 0 && rr < height && cc >= 0 && cc < width) {
template[rr * (width + 1) + cc] = (byte) l.human();
}
});
var gridv2 = new String(template).split("\n");
// 5) words output with cropped coordinates // 5) words output with cropped coordinates
int MIN_R = minR, MIN_C = minC;
val bytes = BYTES.get(); val bytes = BYTES.get();
var wordsOut = Arrays.stream(placed).map(p -> new WordOut( var wordsOut = Arrays.stream(placed).map(p -> new WordOut(
p.lemma, p.lemma,
p.startRow() - MIN_R, p.startRow() - MINR,
p.startCol() - MIN_C, p.startCol() - MINC,
p.direction(), p.direction(),
p.arrowRow() - MIN_R, p.arrowRow() - MINR,
p.arrowCol() - MIN_C, p.arrowCol() - MINC,
p.isReversed(), bytes p.isReversed(), bytes
)).toArray(WordOut[]::new); )).toArray(WordOut[]::new);
var total = 0.0001d + Arrays.stream(wordsOut).mapToDouble(WordOut::complex).sum(); var total = 0.0001d + Arrays.stream(wordsOut).mapToDouble(WordOut::complex).sum();