Skip to content

Commit

Permalink
Truncate parallelotope ups and downs to match basis
Browse files Browse the repository at this point in the history
ref #643
  • Loading branch information
frostburn committed Apr 12, 2024
1 parent 1fe083a commit bbd9780
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
12 changes: 4 additions & 8 deletions src/stores/tempering.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { FIFTH, MAX_GEO_SUBGROUP_SIZE, MAX_INTERACTIVE_SUBGROUP_SIZE, OCTAVE } from '@/constants'
import { mosPatternsRank2FromCommas, mosPatternsRank2FromVals } from '@/tempering'
import { computedAndError, splitText } from '@/utils'
import { computedAndError, padEndOrTruncate, splitText } from '@/utils'
import { isBright, mosPatterns as getMosPatterns, type MosInfo } from 'moment-of-symmetry'
import { defineStore } from 'pinia'
import { parseChord, parseVals, type TimeMonzo } from 'sonic-weave'
Expand Down Expand Up @@ -372,13 +372,9 @@ export const useLatticeStore = defineStore('lattice', () => {
return parseChord(basisString.value)
}, [])

watch(basis, () => {
while (ups.length < basis.value.length) {
ups.push(1)
}
while (downs.length < basis.value.length) {
downs.push(0)
}
watch(basis, (newValue) => {
padEndOrTruncate(ups, newValue.length, 1)
padEndOrTruncate(downs, newValue.length, 0)
})

const dimensions = computed(() => {
Expand Down
7 changes: 7 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -474,3 +474,10 @@ export function syncValues(values: Record<string, Ref>) {
watch(value, (newValue) => window.localStorage.setItem(key, String(newValue)))
}
}

export function padEndOrTruncate<T>(array: T[], targetLength: number, padValue: T) {
while (array.length < targetLength) {
array.push(padValue)
}
array.length = targetLength
}

0 comments on commit bbd9780

Please sign in to comment.