typescript

This commit is contained in:
Kseninia Mikhaylova 2024-06-13 10:55:29 +03:00
parent 12f7048806
commit 6cdb8290f1
2 changed files with 47 additions and 36 deletions

View File

@ -17,6 +17,7 @@ const parametric = {
},
total_length: {
min: 1,
max: undefined,
step: 0.1,
},
height: {
@ -52,43 +53,47 @@ const changeParametres = () => {
fence_section.value = form_state.length * 0.001
for (const key in form_state) {
if (parametric.hasOwnProperty(key) && parametric[key].max) {
if (form_state[key] > parametric[key].max) {
form_state[key] = parametric[key].max
if (parametric.hasOwnProperty(key)) {
const key_p = key as keyof typeof parametric
const key_s = key as keyof typeof form_state
if (parametric[key_p].max) {
if (form_state[key_s] > parametric[key_p].max) {
form_state[key_s] = parametric[key_p].max
}
}
if (parametric[key_p].min) {
if (form_state[key_s] < parametric[key_p].min) {
form_state[key_s] = parametric[key_p].min
}
}
}
if (parametric.hasOwnProperty(key) && parametric[key].min) {
if (form_state[key] < parametric[key].min) {
form_state[key] = parametric[key].min
form_state.total_length_mm = form_state.total_length * 1000
if (auto_section_width.value) {
let w = parametric.length.max
while (((form_state.total_length_mm % w) > 0) && w > (parametric.length.min + parametric.length.step * 10)) {
w -= parametric.length.step
}
form_state.length = w
}
}
form_state.total_length_mm = form_state.total_length * 1000
if (auto_section_width.value) {
let w = parametric.length.max
while (((form_state.total_length_mm % w) > 0) && w > (parametric.length.min + parametric.length.step * 10)) {
w -= parametric.length.step
if (form_state.total_length_mm < form_state.length) {
form_state.length = form_state.total_length_mm
}
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)
section_count.value = form_state.full_sections
if (t_f % i_f) {
form_state.extra_section = Math.round(t_f % i_f)
} else {
form_state.extra_section = 0
}
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)
section_count.value = form_state.full_sections
if (t_f % i_f) {
form_state.extra_section = Math.round(t_f % i_f)
} else {
form_state.extra_section = 0
}
form_refs.total_length.value.setCustomValidity('')
if (form_state.extra_section && form_state.extra_section < parametric.length.min) {
form_refs.total_length.value.setCustomValidity('Расчет невозможен')
form_refs.total_length.value.setCustomValidity('')
if (form_state.extra_section && form_state.extra_section < parametric.length.min) {
form_refs.total_length.value.setCustomValidity('Расчет невозможен')
}
}
}
@ -100,13 +105,18 @@ const setPillarColor = (color: ralTypes) => {
}
const increment = (field: keyof typeof form_state, value: number) => {
if (form_state.hasOwnProperty(field)) {
let v = (form_state[field] + value * parametric[field].step ?? 1)
const key_p = field as keyof typeof parametric
let v = (form_state[field] + value * parametric[key_p].step ?? 1)
if (parametric.hasOwnProperty(field)) {
if (v > parametric[field].max) {
v = parametric[field].max
if (parametric[key_p].max) {
if (v > parametric[key_p].max) {
v = parametric[key_p].max
}
}
if (v < parametric[field].min) {
v = parametric[field].min
if (parametric[key_p].min) {
if (v < parametric[key_p].min) {
v = parametric[key_p].min
}
}
}
form_state[field] = parseFloat(v.toFixed(2))

View File

@ -23,7 +23,8 @@ const pbrTexture = await useTexture({
const repeat = 5
for (const key in pbrTexture) {
if (Object.prototype.hasOwnProperty.call(pbrTexture, key)) {
const element = pbrTexture[key];
const key_p = key as keyof typeof pbrTexture
const element = pbrTexture[key_p]
if (element && element.wrapS) {
element.wrapS = RepeatWrapping
element.wrapT = RepeatWrapping