diff --git a/components/calcValues.vue b/components/calcValues.vue index e5bcf0f..fe81b6a 100644 --- a/components/calcValues.vue +++ b/components/calcValues.vue @@ -4,6 +4,7 @@ import type { ralTypes } from '@/components/ral' import { predefLamelleColors, predefPillarColors } from '~/composables/useCalc'; +const lamelle_height = use_lamelle_height() const lamelles_count = use_lamelles_count() const fence_section = use_fence_section() const remove_pillar = use_remove_pillar() @@ -17,7 +18,7 @@ const min_length = use_min_length() const parametric = reactive({ length: { min: min_length.value, - max: 2466, + max: 2470, step: 1, }, total_length: { @@ -27,8 +28,8 @@ const parametric = reactive({ }, height: { min: 675, - max: 2400, - step: 115, + max: 2500, + step: lamelle_height.value * 1000, } }) const form_state = reactive({ @@ -71,31 +72,38 @@ const changeParametres = () => { } form_state.total_length_mm = form_state.total_length * 1000 - let { fence_length, total_length_mm, auto_length, length } = form_state + let { fence_length, total_length_mm, auto_length, length, full_sections } = form_state length = parseFloat(length.toString()) if (auto_length) { let w = parametric.length.min - const max_sections = Math.ceil(total_length_mm / (parametric.length.min + fence_length)) - const min_sections = Math.ceil(total_length_mm / (parametric.length.max + fence_length)) + const max_sections = Math.ceil((total_length_mm - fence_length) / (parametric.length.min + fence_length)) + const min_sections = Math.ceil((total_length_mm - fence_length) / (parametric.length.max + fence_length)) for (let index = min_sections; index <= max_sections; index++) { + full_sections = index w = (total_length_mm - fence_length * (index - 1)) / index - if (w >= parametric.length.min && w <= parametric.length.max) { + if ( + w >= parametric.length.min + && w <= parametric.length.max + && w * index <= total_length_mm + ) { break } } - form_state.length = w length = w } - form_state.full_sections = Math.floor((total_length_mm - fence_length) / (length + fence_length)) - if (((form_state.full_sections * length) + (form_state.full_sections * fence_length) + fence_length) !== total_length_mm) { - form_state.extra_section = Math.floor((total_length_mm - fence_length) % form_state.length) + if (((full_sections * length) + (full_sections * fence_length) + fence_length) <= total_length_mm) { + form_state.extra_section = Math.floor((total_length_mm - fence_length) % length) } else { form_state.extra_section = 0 } + form_state.full_sections = full_sections + form_state.length = length + form_state.fence_length = fence_length + total_length.value = form_state.total_length lamelles_count.value = lamelles fence_section.value = form_state.length * 0.001 @@ -124,110 +132,102 @@ const plurals = {