From fdc3f600ca150f55245be454160cc974b79be929 Mon Sep 17 00:00:00 2001 From: Kseninia Mikhaylova Date: Tue, 18 Jun 2024 11:06:06 +0300 Subject: [PATCH] auto length --- components/calcValues.vue | 29 ++++++++++++++++++++--------- components/model/fence.vue | 24 +++++++++++------------- components/model/item.vue | 4 ++-- 3 files changed, 33 insertions(+), 24 deletions(-) diff --git a/components/calcValues.vue b/components/calcValues.vue index 066a7ef..b492585 100644 --- a/components/calcValues.vue +++ b/components/calcValues.vue @@ -3,16 +3,16 @@ import { getColorNameFromRal } from '@/components/ral' import type { ralTypes } from '@/components/ral' const lamelles_count = useState('lamelles_count', () => 14) -const fence_section = useState('fence_section', () => 2000 * 0.001) +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 section_count = useState('section_count', () => 10) +const section_count = useState('section_count', () => 5) const extra_section = useState('extra_section', () => 0) -const total_length = useState('total_length', () => (2000 * 8 - 100) * 0.001) +const total_length = useState('total_length', () => (1000 * 5 - 100) * 0.001) const min_length = useState('min_length', () => 1000) -const parametric = { +const parametric = reactive({ length: { min: min_length.value, max: 2400, @@ -28,7 +28,7 @@ const parametric = { max: 2400, step: 115, } -} +}) const form_state = reactive({ length: fence_section.value * 1000, fence_length: 100, @@ -37,7 +37,7 @@ const form_state = reactive({ total_length_mm: fence_section.value * 1000, full_sections: section_count.value, extra_section: 0, - auto_length: false, + auto_length: true, remove_pillar: false }) const form_refs = { @@ -63,11 +63,22 @@ const changeParametres = () => { form_state.total_length_mm = form_state.total_length * 1000 if (form_state.auto_length) { - let w = parametric.length.max + 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) - while ((tw_f % iw_f) && w > (parametric.length.min + parametric.length.step * 10)) { - w -= parametric.length.step + 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 } diff --git a/components/model/fence.vue b/components/model/fence.vue index 2a7c273..335111f 100644 --- a/components/model/fence.vue +++ b/components/model/fence.vue @@ -20,16 +20,12 @@ const pillar_size = 80 * 0.001 const pillar_one_pos = ref(fence_section.value * -0.5 - 0.015) const pillar_two_pos = ref(fence_section.value * 0.5 + pillar_size + bSize - 0.01) -watch([fence_section, lamelles_count], () => { - pillar_one_pos.value = fence_section.value * -0.5 - 0.015 - pillar_two_pos.value = fence_section.value * 0.5 + pillar_size + bSize - 0.01 -}) const scale_koef = 2.5 const show_pillar_one = ref(props.index == 1) const show_pillar_two = ref(true) -const make_translate_to_section = () => { - const one_s = (fence_section.value + pillar_size + bSize) +const make_translate_to_section = (source = fence_section.value) => { + const one_s = (source + pillar_size + bSize) let r = (props.index - 1) * one_s * scale_koef return r } @@ -64,19 +60,21 @@ for (let index = 0; index < lamelles_count.value; index++) { } const extra = ref((extra_section && props.index == (section_count.value + 1)) ? extra_section.value * 0.001 : false) if (extra.value) { - pillar_two_pos.value = extra.value * 0.5 + pillar_size + bSize - 0.01 + pillar_one_pos.value = (extra.value as number) * -0.5 - 0.015 + pillar_two_pos.value = (extra.value as number) * 0.5 + pillar_size + bSize - 0.01 } -watch([extra_section, section_count], () => { - extra.value = (extra_section && props.index == (section_count.value + 1)) ? extra_section.value * 0.001 : false +watch([section_count, fence_section, extra_section], (s) => { + extra.value = (extra_section.value && props.index == (section_count.value + 1)) ? extra_section.value * 0.001 : false if (extra_section && props.index == (section_count.value + 1)) { - // pillar_one_pos.value = extra_section.value * -0.5 - 0.015 - pillar_two_pos.value = extra.value * 0.5 + pillar_size + bSize - 0.01 + pillar_one_pos.value = (extra.value as number) * -0.5 - 0.015 + pillar_two_pos.value = (extra.value as number) * 0.5 + pillar_size + bSize - 0.01 + translate_to_section.value = make_translate_to_section(extra_section.value) } else { - // pillar_one_pos.value = fence_section.value * -0.5 - 0.015 + pillar_one_pos.value = fence_section.value * -0.5 - 0.015 pillar_two_pos.value = fence_section.value * 0.5 + pillar_size + bSize - 0.01 + translate_to_section.value = make_translate_to_section() } }) -console.log({ pillar_size, fence_section: fence_section.value })