Skip to content

Commit

Permalink
Fix coloring in rank2 with size hints
Browse files Browse the repository at this point in the history
Improve parallelotope coloring semantics.

ref #329
  • Loading branch information
frostburn committed May 23, 2024
1 parent 827e6a3 commit e2fe77b
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 25 deletions.
64 changes: 42 additions & 22 deletions src/parser/__tests__/stdlib.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1541,41 +1541,61 @@ describe('SonicWeave standard library', () => {

it('supports size hints for rank-2 preimages', () => {
const scale = expand(`
rank2(10/9, 7, 0, 2/1, 1, 2\\15)
rank2(10/9 red, 7, 0, 2/1 green, 1, 2\\15)
i => i str(i)
15@
`);
expect(scale).toEqual([
'2\\15 "10/9"',
'4\\15 "100/81"',
'6\\15 "1000/729"',
'8\\15 "10000/6561"',
'10\\15 "100000/59049"',
'12\\15 "1000000/531441"',
'14\\15 "10000000/4782969"',
'15\\15 "2/1"',
'2\\15 "10/9" red',
'4\\15 "100/81" red',
'6\\15 "1000/729" red',
'8\\15 "10000/6561" red',
'10\\15 "100000/59049" red',
'12\\15 "1000000/531441" red',
'14\\15 "10000000/4782969" red',
'15\\15 "2/1" green',
]);
});

it('supports size hints for rank-3 preimages', () => {
const scale = expand(`
parallelotope([3, 5], [2, 3], niente, 2, [1892.986, 2795.938], 1196.430)
parallelotope([3 red, 5 green], [2, 3], niente, 2 blue, [1892.986, 2795.938], 1196.430)
i => i str(i)
PrimeMapping(1196.430, 1892.986, 2795.938, 3382.895)
`);
expect(scale).toEqual([
'12.804 "125/128"',
'196.682 "9/8"',
'209.486 "1125/1024"',
'306.282 "75/64"',
'403.078 "5/4"',
'599.76 "45/32"',
'696.556 "3/2"',
'709.36 "375/256"',
'806.156 "25/16"',
'1002.838 "225/128"',
'1099.634 "15/8"',
'1196.43 "2"',
'12.804 "125/128" green',
'196.682 "9/8" red',
'209.486 "1125/1024" red',
'306.282 "75/64" red',
'403.078 "5/4" green',
'599.76 "45/32" red',
'696.556 "3/2" red',
'709.36 "375/256" red',
'806.156 "25/16" green',
'1002.838 "225/128" red',
'1099.634 "15/8" red',
'1196.43 "2" blue',
]);
});

it('has sensible parallelotope coloring (without size hints)', () => {
const scale = expand(
'parallelotope([3 red, 5 green], [2, 3], niente, 2 blue)'
);
expect(scale).toEqual([
'1125/1024 red',
'9/8 red',
'75/64 red',
'5/4 green',
'45/32 red',
'375/256 red',
'3/2 red',
'25/16 green',
'225/128 red',
'15/8 red',
'125/64 green',
'2 blue',
]);
});
});
10 changes: 7 additions & 3 deletions src/stdlib/prelude.ts
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ riff rank2(generator, up, down = 0, period = 2, numPeriods = 1, generatorSizeHin
const scales = zip(scale, hint ~rdc periodSizeHint);
sort(scales, (a, b) => compare(a[1], b[1]));
[a for [a, b] of scales];
pop() vor period;
period vor pop();
repeat(numPeriods);
}
Expand Down Expand Up @@ -551,7 +551,11 @@ riff parallelotope(basis, ups = niente, downs = niente, equave = 2, basisSizeHin
const up = pop(ups);
const down = pop(downs);
popAll($$) tns~ generator ~^ [-down..up];
// Don't impose color on unity.
const axis = generator ~^ [-down..up];
axis[down] = bleach(axis[down]);
axis ~tns~ popAll($$);
}
if (basisSizeHints == niente and equaveSizeHint == niente) {
Expand All @@ -578,7 +582,7 @@ riff parallelotope(basis, ups = niente, downs = niente, equave = 2, basisSizeHin
const up = pop(ups);
const down = pop(downs);
popAll($$) tns~ generator ~^ [-down..up];
generator ~^ [-down..up] ~tns~ popAll($$);
}
const hint = popAll();
Expand Down

0 comments on commit e2fe77b

Please sign in to comment.