From b927880e02d0a33aab647529108e5eca271bceb1 Mon Sep 17 00:00:00 2001 From: Lumi Pakkanen Date: Tue, 13 Feb 2024 10:29:53 +0200 Subject: [PATCH] Implement soft limits to approximation numerators and denominators ref #544 --- .../modals/modification/ApproximateByHarmonics.vue | 11 +++++++++++ .../modals/modification/ApproximateBySubharmonics.vue | 1 + 2 files changed, 12 insertions(+) diff --git a/src/components/modals/modification/ApproximateByHarmonics.vue b/src/components/modals/modification/ApproximateByHarmonics.vue index 509b06dc..28d3a33b 100644 --- a/src/components/modals/modification/ApproximateByHarmonics.vue +++ b/src/components/modals/modification/ApproximateByHarmonics.vue @@ -2,6 +2,8 @@ import Modal from '@/components/ModalDialog.vue' import type { Scale } from 'scale-workshop-core' import { useModalStore } from '@/stores/modal' +import { computed } from 'vue' +import { centsToValue } from 'xen-dev-utils' const props = defineProps<{ scale: Scale @@ -11,6 +13,14 @@ const emit = defineEmits(['update:scale', 'cancel']) const modal = useModalStore() +const maxDenominator = computed(() => { + let maxCents = 0 + for (let i = 0; i < props.scale.size; ++i) { + maxCents = Math.max(Math.abs(props.scale.getCents(i))) + } + return Math.floor(Number.MAX_SAFE_INTEGER / centsToValue(maxCents)) +}) + function modify() { emit('update:scale', props.scale.approximateHarmonics(modal.largeInteger)) } @@ -29,6 +39,7 @@ function modify() { id="approximate-harmonics-denominator" type="number" min="1" + :max="maxDenominator" class="control" v-model="modal.largeInteger" /> diff --git a/src/components/modals/modification/ApproximateBySubharmonics.vue b/src/components/modals/modification/ApproximateBySubharmonics.vue index 0fa8ed20..2ce6c925 100644 --- a/src/components/modals/modification/ApproximateBySubharmonics.vue +++ b/src/components/modals/modification/ApproximateBySubharmonics.vue @@ -29,6 +29,7 @@ function modify() { id="approximate-subharmonics-numerator" type="number" min="1" + :max="Number.MAX_SAFE_INTEGER" class="control" v-model="modal.largeInteger" />