diff --git a/src/mosaic.test.ts b/src/mosaic.test.ts index 82627a6..a4fb6ab 100644 --- a/src/mosaic.test.ts +++ b/src/mosaic.test.ts @@ -98,6 +98,18 @@ describe('generateMosaic', () => { expect(expanded.outputLength).toBe(expanded.inputLength * 10) }) + it('不生成可能跳出正常行框的 Unicode 组合符', () => { + const outputs = Array.from({ length: 20 }, (_, seed) => + generateMosaic(SOURCE, [], { + volume: 1000, + disorder: 100, + seed, + }).output, + ).join('') + + expect(outputs).not.toMatch(/\p{Mark}/u) + }) + it('相同种子可复现,不同种子会重新侵蚀', () => { const candidates = selectKeywords(SOURCE, 14, 1) const first = generateMosaic(SOURCE, candidates, { diff --git a/src/mosaic.ts b/src/mosaic.ts index dcce973..6ceb301 100644 --- a/src/mosaic.ts +++ b/src/mosaic.ts @@ -237,8 +237,6 @@ const ENCODING_FRAGMENTS = ['Ã', 'Â', 'æ', 'å', '¤', '锟', '斤', '拷'] a const COMPLEX_HAN = ['黻', '鬯', '夔', '爨', '龘', '靐', '罅', '黹'] as const -const COMBINING_MARKS = ['\u0336', '\u0337', '\u0338', '\u035F'] as const - const HAN_PATTERN = /\p{Script=Han}/u const WORD_PATTERN = /[\p{L}\p{N}]/u @@ -395,15 +393,12 @@ function generateNoise(length: number, disorder: number, random: Random): string let output = '' let previous = '' const repeatChance = 0.02 + disorder * 0.0015 - const combiningChance = 0.02 + disorder * 0.0011 for (let index = 0; index < length; index += 1) { const shouldRepeat = previous !== '' && random() < repeatChance const glyph = shouldRepeat ? previous : chooseNoiseGlyph(random) - const combining = - random() < combiningChance ? choose(COMBINING_MARKS, random) : '' - output += `${glyph}${combining}` + output += glyph previous = glyph }