From 36d77b3e22139868880ce30e5dde918e6874661a Mon Sep 17 00:00:00 2001 From: Kseninia Mikhaylova Date: Tue, 18 Jun 2024 12:15:50 +0300 Subject: [PATCH] calc --- components/calcModels.vue | 2 +- components/calcValues.vue | 63 ++++++++++++++++++--------------------- 2 files changed, 30 insertions(+), 35 deletions(-) diff --git a/components/calcModels.vue b/components/calcModels.vue index 856a6a9..1bcab0e 100644 --- a/components/calcModels.vue +++ b/components/calcModels.vue @@ -7,7 +7,7 @@ const section_count = useState('section_count') const fence_section = useState('fence_section') const controlsState = reactive({ - minDistance: 5, + minDistance: section_count.value * 5, maxDistance: 12, enablePan: false, maxPolarAngle: (Math.PI / 2) - 0.2, diff --git a/components/calcValues.vue b/components/calcValues.vue index b492585..dca5085 100644 --- a/components/calcValues.vue +++ b/components/calcValues.vue @@ -2,11 +2,14 @@ import { getColorNameFromRal } from '@/components/ral' import type { ralTypes } from '@/components/ral' +const predefPillarColors = ['3004', '7043', '6028', '5013', '8016', '1020', '3005', '4009'] +const predefLamelleColors = ['3009', '9003', '6027', '5024', '9001', '1012', '3007', '4007'] + const lamelles_count = useState('lamelles_count', () => 14) const fence_section = useState('fence_section', () => 1000 * 0.001) const remove_pillar = useState('remove_pillar', () => false) -const pillar_color = useState('pillar_color', () => '3009') -const lamelle_color = useState('lamelle_color', () => '3004') +const pillar_color = useState('pillar_color', () => predefPillarColors[Math.floor(Math.random() * predefPillarColors.length)] as ralTypes) +const lamelle_color = useState('lamelle_color', () => predefLamelleColors[Math.floor(Math.random() * predefLamelleColors.length)] as ralTypes) const section_count = useState('section_count', () => 5) const extra_section = useState('extra_section', () => 0) const total_length = useState('total_length', () => (1000 * 5 - 100) * 0.001) @@ -61,36 +64,33 @@ const changeParametres = () => { } } - form_state.total_length_mm = form_state.total_length * 1000 - if (form_state.auto_length) { - let w = parametric.length.min - let tw_f = (form_state.total_length_mm - form_state.fence_length) - let iw_f = (w - form_state.fence_length) - for (let index = parametric.length.max; index > parametric.length.min; index--) { - w = index - iw_f = (w - form_state.fence_length) - console.log({ - tw_f:tw_f, - iw_f:iw_f, - 'tw_f % iw_f':tw_f % iw_f - }) - if (tw_f % iw_f == 0) { - break - } else { - w += parametric.length.step - } - } - form_state.length = w - } if (form_state.total_length_mm < form_state.length) { form_state.length = form_state.total_length_mm } - const t_f = (form_state.total_length_mm - form_state.fence_length) - const i_f = (form_state.length - form_state.fence_length) - form_state.full_sections = Math.floor(t_f / i_f) - if (t_f % i_f) { - form_state.extra_section = Math.round(t_f % i_f) + form_state.total_length_mm = form_state.total_length * 1000 + const total_without_pillar = form_state.total_length_mm - form_state.fence_length + + if (form_state.auto_length) { + let w = parametric.length.min + const max_sections = Math.ceil(total_without_pillar / parametric.length.min) + const min_sections = Math.ceil(total_without_pillar / parametric.length.max) + + for (let index = min_sections; index <= max_sections; index++) { + w = (total_without_pillar / index) + form_state.fence_length + if (w >= parametric.length.min && w <= parametric.length.max) { + break + } + } + form_state.length = w + } + + const section_without_pillar = form_state.length - form_state.fence_length + + form_state.full_sections = Math.ceil(total_without_pillar / section_without_pillar) + + if (section_without_pillar * form_state.full_sections == form_state.full_sections) { + form_state.extra_section = Math.ceil(total_without_pillar % section_without_pillar) } else { form_state.extra_section = 0 } @@ -120,10 +120,6 @@ const setLamelleColor = (color: ralTypes) => { const setPillarColor = (color: ralTypes) => { pillar_color.value = color } - -const predefLamelleColors = ['3009', '9003', '6027', '5024', '9001', '1012', '3007', '4007'] -const predefPillarColors = ['3004', '7043', '6028', '5013', '8016', '1020', '3005', '4009'] - watch(form_state, changeParametres, { deep: true }) const isModalOpen = useState('modal_open', () => false) @@ -213,8 +209,7 @@ const plurals = { {{ section_count * lamelles_count }} - {{ `длиной ${form_state.length}\xa0мм` }} -