Skip to content

Commit

Permalink
align direction perfection
Browse files Browse the repository at this point in the history
  • Loading branch information
mcnuttandrew committed Feb 23, 2024
1 parent f45b8a3 commit 21f7575
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 26 deletions.
79 changes: 54 additions & 25 deletions src/controls/AlignSelection.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,46 @@
$: colors = currentPal.colors;
$: focusedColors = $focusStore.focusedColors;
$: focusSet = new Set(focusedColors);
$: focusLabs = focusedColors.map((idx) => colors[idx].toChannels());
$: colorSpace = currentPal.colorSpace;
$: zName = colorPickerConfig[colorSpace].zChannel;
$: config = colorPickerConfig[colorSpace];
$: zName = config.zChannel.toUpperCase();
$: xRev = config.xDomain[1] < config.xDomain[0];
$: yRev = config.yDomain[1] < config.yDomain[0];
$: zRev = config.zDomain[1] < config.zDomain[0];
$: isPolar = config.isPolar;
$: ALIGNS = [
{ pos: 1, name: "Left", op: Math.min },
{ pos: 1, name: "Right", op: Math.max },
{ pos: 2, name: "Top", op: Math.min },
{ pos: 2, name: "Bottom", op: Math.max },
{ pos: 0, name: `${zName} Min`, op: Math.min },
{ pos: 0, name: `${zName} Max`, op: Math.max },
{
pos: config.xChannelIndex,
name: isPolar ? "Inner Radius" : "Left",
op: xRev ? Math.max : Math.min,
},
{
pos: config.xChannelIndex,
name: isPolar ? "Outer Radius" : "Right",
op: xRev ? Math.min : Math.max,
},
{
pos: config.yChannelIndex,
name: isPolar ? "Min Angle" : "Top",
op: yRev ? Math.max : Math.min,
},
{
pos: config.yChannelIndex,
name: isPolar ? "Max Angle" : "Bottom",
op: yRev ? Math.min : Math.max,
},
{
pos: config.zChannelIndex,
name: `${zName} Min`,
op: zRev ? Math.max : Math.min,
},
{
pos: config.zChannelIndex,
name: `${zName} Max`,
op: zRev ? Math.min : Math.max,
},
];
const mapFocusedColors = (fn: (color: [number, number, number]) => any) =>
colors.map((color, idx) =>
focusSet.has(idx) ? fn(color.toChannels()) : color
);
</script>

{#if focusedColors.length > 1}
Expand All @@ -34,19 +58,24 @@
<button
class={buttonStyle}
on:click={() => {
const newCoordinate = op(...focusLabs.map((x) => x[pos]));
colorStore.setCurrentPalColors(
mapFocusedColors(([a, b, c]) => {
return Color.colorFromChannels(
[
pos === 0 ? newCoordinate : a,
pos === 1 ? newCoordinate : b,
pos === 2 ? newCoordinate : c,
],
colorSpace
);
})
const newCoordinate = op(
...colors
.map((x) => x.toChannels())
.filter((_, idx) => focusSet.has(idx))
.map((x) => x[pos])
);
const newColors = colors
.map((x) => x.toChannels())
.map((x, idx) => {
let y = x;
if (focusSet.has(idx)) {
y[pos] = newCoordinate;
}
return y;
})
.map((x) => Color.colorFromChannels(x, colorSpace));

colorStore.setCurrentPalColors(newColors);
}}
>
{name}
Expand Down
2 changes: 1 addition & 1 deletion src/linting/LintCustomizationModal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@
const newContext = currentContexts.includes(context)
? currentContexts.filter((x) => x !== context)
: [...currentContexts, context];
lintStore.setCurrentContexts(newContext);
lintStore.setCurrentContext(newContext);
}}
/>
{context}
Expand Down

0 comments on commit 21f7575

Please sign in to comment.