preciso que você tire a espessura de centro de exibição mas em lentes negativas considere sempre 2,0 de centro já em dioptrias positivas como a espessura máxima e no centro leve a consideração a espessura de borda de 1,5 mm
1657b45 verified Download script.js from ofcCONSUULTORIA/lensthickness-wizard: direct link, hf CLI and curl.
- Browser
- Download file 5.18 kB
-
https://huggingface.co/spaces/ofcCONSUULTORIA/lensthickness-wizard/resolve/main/script.js
- Command line
-
hf download hf://spaces/ofcCONSUULTORIA/lensthickness-wizard/script.js
-
curl -L -o script.js https://huggingface.co/spaces/ofcCONSUULTORIA/lensthickness-wizard/resolve/main/script.js
5.18 kB
| document.addEventListener('DOMContentLoaded', () => { | |
| // Material options mapping | |
| const materials = { | |
| 'cr39': { name: 'CR-39', index: 1.5 }, | |
| 'policarbonato': { name: 'Policarbonato', index: 1.586 }, | |
| 'trivex': { name: 'Trivex', index: 1.53 }, | |
| 'alto_indice_1_6': { name: 'Alto Índice 1.6', index: 1.6 }, | |
| 'alto_indice_1_67': { name: 'Alto Índice 1.67', index: 1.67 }, | |
| 'alto_indice_1_74': { name: 'Alto Índice 1.74', index: 1.74 } | |
| }; | |
| // Setup material selector | |
| const materialSelect = document.createElement('select'); | |
| materialSelect.id = 'materialSelect'; | |
| materialSelect.className = 'w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500'; | |
| materialSelect.innerHTML = ` | |
| <option value="">Selecione um material...</option> | |
| ${Object.entries(materials).map(([key, mat]) => | |
| `<option value="${key}" ${key === 'cr39' ? 'selected' : ''}>${mat.name} (n = ${mat.index})</option>` | |
| ).join('')} | |
| `; | |
| materialSelect.addEventListener('change', function() { | |
| const selected = materials[this.value]; | |
| if (selected) { | |
| document.getElementById('indice_n').value = selected.index; | |
| } | |
| }); | |
| // Insert material selector before index input | |
| const indexInput = document.getElementById('indice_n'); | |
| indexInput.parentNode.insertBefore(materialSelect, indexInput); | |
| // Form submission handler | |
| const lensForm = document.getElementById('lensForm'); | |
| lensForm.addEventListener('submit', function(event) { | |
| event.preventDefault(); | |
| calcularEspessura(); | |
| }); | |
| function calcularEspessura() { | |
| // 1. Collect and convert form data | |
| const de = parseFloat(document.getElementById('esferico').value) || 0; | |
| const dc = parseFloat(document.getElementById('cilindrico').value) || 0; | |
| const eixo = parseFloat(document.getElementById('eixo').value) || 0; | |
| const indice_n = parseFloat(document.getElementById('indice_n').value); | |
| const diametro = parseFloat(document.getElementById('diametro').value); | |
| const maior_diagonal_ed = parseFloat(document.getElementById('maior_diagonal_ed').value); | |
| const dnp = parseFloat(document.getElementById('dnp').value); | |
| let espessura_centro_ec; | |
| // Auto-determine center thickness based on prescription | |
| if (de < 0) { // Negative lenses (myopia) | |
| espessura_centro_ec = 2.0; | |
| } else { // Positive lenses (hyperopia) | |
| // For positive lenses, calculate edge thickness first | |
| const decentracao = Math.abs((maior_diagonal_ed / 2) - dnp); | |
| const raio_efetivo = (maior_diagonal_ed / 2) + decentracao; | |
| const angulo_rad = Math.PI * (180 - eixo) / 180; | |
| const potencia_efetiva_meridiano = de + (dc * (Math.sin(angulo_rad)**2)); | |
| const sagita = (potencia_efetiva_meridiano * raio_efetivo**2) / (2000 * (indice_n - 1)); | |
| espessura_centro_ec = sagita + 1.5; // Edge thickness of 1.5mm for positive lenses | |
| } | |
| // 2. Data validation | |
| const resultadoDiv = document.getElementById('resultado'); | |
| const resultContent = document.getElementById('resultContent'); | |
| if (isNaN(indice_n) || isNaN(diametro) || isNaN(maior_diagonal_ed) || isNaN(dnp)) { | |
| resultadoDiv.classList.remove('hidden'); | |
| resultContent.innerHTML = `<p class="font-bold text-red-600">Erro: Preencha todos os campos obrigatórios com valores numéricos.</p>`; | |
| return; | |
| } | |
| if (indice_n <= 1) { | |
| resultadoDiv.classList.remove('hidden'); | |
| resultContent.innerHTML = `<p class="font-bold text-red-600">Erro: O Índice de Refração deve ser maior que 1.</p>`; | |
| return; | |
| } | |
| // 3. Main calculations (corrected logic) | |
| const decentracao = Math.abs((maior_diagonal_ed / 2) - dnp); | |
| const raio_efetivo = (maior_diagonal_ed / 2) + decentracao; | |
| const angulo_rad = Math.PI * (180 - eixo) / 180; | |
| const potencia_efetiva_meridiano = de + (dc * (Math.sin(angulo_rad)**2)); | |
| const sagita = (potencia_efetiva_meridiano * raio_efetivo**2) / (2000 * (indice_n - 1)); | |
| const espessura_borda = de < 0 ? (espessura_centro_ec - sagita) : 1.5; | |
| // 4. Display results | |
| resultadoDiv.classList.remove('hidden'); | |
| resultContent.innerHTML = ` | |
| <p><strong>Material:</strong> ${materialSelect.options[materialSelect.selectedIndex].text || 'Personalizado'}</p> | |
| <p><strong>Espessura no Centro:</strong> ${espessura_centro_ec.toFixed(2)} mm</p> | |
| <p class="mt-2 text-xl font-bold text-blue-800"> | |
| <strong>Espessura Máxima Estimada na Borda:</strong> | |
| <span class="text-blue-600 font-extrabold">${Math.abs(espessura_borda).toFixed(2)} mm</span> | |
| </p> | |
| ${espessura_borda < 0 ? '<p class="text-yellow-600 font-semibold">Atenção: Valor negativo indica que a lente pode ficar muito fina!</p>' : ''} | |
| `; | |
| resultadoDiv.scrollIntoView({ behavior: 'smooth' }); | |
| feather.replace(); | |
| } | |
| }); | |