DIU Companion AR Fix

Fixed DIU matching pixel density section aspect ratio, and some internal
code cleanup
This commit is contained in:
Glenwing 2017-12-31 14:48:39 -08:00
parent aa34088de1
commit c9554f54f5
3 changed files with 82 additions and 30 deletions

View File

@ -2,8 +2,8 @@
var size = parseNum($('#INPUT_SIZE').val()); var size = parseNum($('#INPUT_SIZE').val());
var unit_select = $('#unit_select input[type="radio"]:checked').val(); var unit_select = $('#unit_select input[type="radio"]:checked').val();
var hres1 = parseNum($('#INPUT_HRES').val()); var hres1 = parseInt(parseNum($('#INPUT_HRES').val()));
var vres1 = parseNum($('#INPUT_VRES').val()); var vres1 = parseInt(parseNum($('#INPUT_VRES').val()));
var ar1 = hres1 / vres1; var ar1 = hres1 / vres1;
var diag = parseFloat(size); var diag = parseFloat(size);
@ -19,8 +19,8 @@
var d_match = Math.sqrt((height * height) * (1 + (ar2 * ar2))); var d_match = Math.sqrt((height * height) * (1 + (ar2 * ar2)));
var opt_res = parseInt(vres1 * ar2) + ' × ' + vres1; var opt_res = parseInt(vres1 * ar2) + ' × ' + vres1;
var hres_den = parseNum($('#INPUT_HRES_DENSITY').val()); var hres_den = parseInt(parseNum($('#INPUT_HRES_DENSITY').val()));
var vres_den = parseNum($('#INPUT_VRES_DENSITY').val()); var vres_den = parseInt(parseNum($('#INPUT_VRES_DENSITY').val()));
var ar_den = hres_den / vres_den; var ar_den = hres_den / vres_den;
var width2 = width * (hres_den / hres1); var width2 = width * (hres_den / hres1);
@ -34,21 +34,19 @@
*/ */
display(new UNIT(unit_select), display(new UNIT(unit_select),
[ [
['RESULT_DIAG', 1, diag.toFixed(3) , (size != '' && size != 0) ], ['RESULT_DIAG', 1, diag.toFixed(3) , (isPositive(size)) ],
['RESULT_WIDTH', 1, width.toFixed(3) , (hres1 != '' && vres1 != '' && size != '' && hres1 != 0 && vres1 != 0 && size != 0) ], ['RESULT_WIDTH', 1, width.toFixed(3) , (isPositive([size, hres1, vres1])) ],
['RESULT_HEIGHT', 1, height.toFixed(3) , (hres1 != '' && vres1 != '' && size != '' && hres1 != 0 && vres1 != 0 && size != 0) ], ['RESULT_HEIGHT', 1, height.toFixed(3) , (isPositive([size, hres1, vres1])) ],
['RESULT_AREA', 2, area.toFixed(3) , (hres1 != '' && vres1 != '' && size != '' && hres1 != 0 && vres1 != 0 && size != 0) ], ['RESULT_AREA', 2, area.toFixed(3) , (isPositive([size, hres1, vres1])) ],
['RESULT_PX_DENSITY', 3, px_density.toFixed(3), (hres1 != '' && vres1 != '' && size != '' && hres1 != 0 && vres1 != 0 && size != 0) ], ['RESULT_PX_DENSITY', 3, px_density.toFixed(3), (isPositive([size, hres1, vres1])) ],
['RESULT_D_MATCH', 1, d_match.toFixed(3) , (hres1 != '' && vres1 != '' && size != '' && hres2 != '' && vres2 != '' && hres1 != 0 && vres1 != 0 && size != 0 && hres2 != 0 && vres2 != 0) ], ['RESULT_D_MATCH', 1, d_match.toFixed(3) , (isPositive([size, hres1, vres1, hres2, vres2])) ],
['RESULT_DENSITY_SIZE', 1, size2.toFixed(3) , (hres1 != '' && vres1 != '' && size != '' && hres_den != '' && vres_den != '' && hres1 != 0 && vres1 != 0 && size != 0 && hres_den != 0 && vres_den != 0)], ['RESULT_DENSITY_SIZE', 1, size2.toFixed(3) , (isPositive([size, hres1, vres1, hres_den, vres_den])) ],
] ]
); );
if (size != '' && hres1 != '' && vres1 != '' && hres2 != '' && vres2 != '' && if (isNum([size, hres1, vres1, hres2, vres2]) && isPositive([size, hres1, vres1, hres2, vres2])) {
size != 0 && hres1 != 0 && vres1 != 0 && hres2 != 0 && vres2 != 0 && $('#RESULT_OPT_RES').html(opt_res);
isNaN(size) == false && isNaN(hres1) == false && isNaN(vres1) == false && isNaN(hres2) == false && isNaN(vres2) == false)
{ $('#RESULT_OPT_RES').html(opt_res);
if (hres2 == '21' && vres2 == '9') { if (hres2 == '21' && vres2 == '9') {
$('#21_9_warning').css('display', 'table-row'); $('#21_9_warning').css('display', 'table-row');
} }
@ -61,7 +59,7 @@
//if (hres1 != '' && vres1 != '' && hres1 != 0 && vres1 != 0 && isNaN(hres1) == false && isNaN(vres1) == false) { //if (hres1 != '' && vres1 != '' && hres1 != 0 && vres1 != 0 && isNaN(hres1) == false && isNaN(vres1) == false) {
if (Number.isNaN(parseNum(hres1)) == false && Number.isNaN(parseNum(vres1)) == false) { if (isNum([hres1, vres1]) && isPositive([hres1, vres1])) {
$('#RESULT_RATIO').html(commas(ar1.toFixed(3)) + ' (' + parseInt(hres1 / GCD(hres1, vres1)) + '<span style="vertical-align:baseline; position:relative; top:-0.05em;">:</span>' + parseInt(vres1 / GCD(hres1, vres1)) + ')'); $('#RESULT_RATIO').html(commas(ar1.toFixed(3)) + ' (' + parseInt(hres1 / GCD(hres1, vres1)) + '<span style="vertical-align:baseline; position:relative; top:-0.05em;">:</span>' + parseInt(vres1 / GCD(hres1, vres1)) + ')');
$('#RESULT_TOTAL_PX').html(commas(total_px) + ' (' + prefixGen(total_px, 2)['num'] + ' ' + prefixGen(total_px, 2)['prefix'] + 'px)'); $('#RESULT_TOTAL_PX').html(commas(total_px) + ' (' + prefixGen(total_px, 2)['num'] + ' ' + prefixGen(total_px, 2)['prefix'] + 'px)');
} }
@ -73,8 +71,8 @@
//!= '' && vres1 != '' && hres1 != 0 && vres1 != 0 && isNaN(hres1) == false && isNaN(vres1) == false //!= '' && vres1 != '' && hres1 != 0 && vres1 != 0 && isNaN(hres1) == false && isNaN(vres1) == false
if (isInt(hres1) && isInt(vres1) && isInt(hres_den) && isInt(vres_den)) { if (isInt([hres1, vres1, hres_den, vres_den]) && isPositive([hres1, vres1, hres_den, vres_den])) {
$('#RESULT_DENSITY_RATIO').html(commas(ar1.toFixed(3)) + ' (' + parseInt(hres_den / GCD(hres_den, vres_den)) + '<span style="vertical-align:baseline; position:relative; top:-0.05em;">:</span>' + parseInt(vres_den / GCD(hres_den, vres_den)) + ')'); $('#RESULT_DENSITY_RATIO').html(commas(ar_den.toFixed(3)) + ' (' + parseInt(hres_den / GCD(hres_den, vres_den)) + '<span style="vertical-align:baseline; position:relative; top:-0.05em;">:</span>' + parseInt(vres_den / GCD(hres_den, vres_den)) + ')');
} }
else { else {
$('#RESULT_DENSITY_RATIO').html(''); $('#RESULT_DENSITY_RATIO').html('');
@ -85,24 +83,77 @@
} }
// Returns false if input is a non-integer number or NaN
function isInt(num) { function isInt(num) {
return Number.isInteger(num); if (Array.isArray(num) == true) {
for (a = 0; a < num.length; a++) {
if (Number.isInteger(num[a]) == false) {
return false;
}
return true;
}
}
else
return Number.isInteger(num);
} }
// Returns false if input is not a positive number (zero, negative number, or NaN)
function isPositive(num) {
if (Array.isArray(num) == true) {
for (a = 0; a < num.length; a++) {
if (Number.isNaN(parseNum(num[a])) == true)
return false;
else if (num[a] <= 0)
return false;
}
return true;
}
else {
if (Number.isNaN(parseNum(num)) == true)
return false;
else if (num > 0)
return true;
}
}
// Returns false if input is NaN
function isNum(num) {
if (Array.isArray(num) == true) {
for (a = 0; a < num.length; a++) {
if (Number.isNaN(parseNum(num[a])) == true) {
return false;
}
return true;
}
}
else {
return !Number.isNaN(parseNum(num));
}
}
// Converts string to floating point if it has a decimal point, or integer if there is no decimal point. Also strips commas and spaces, and optionally applies absolute value.
// Cannot handle inputs with negative signs in the wrong position.
function parseNum(str) { function parseNum(str) {
if (typeof str === "string") { if (typeof str === "string") {
str = str.replace(/[^0-9.]/g, ''); str = str.replace(/[^0-9\. ]/g, ''); // Apply absolute value
if (str == '') // str = str.replace(/[^0-9\. -]/g, ''); // Allow negative numbers
// Return NaN if...
if (str == '' // input is blank
|| str.indexOf('.') != str.lastIndexOf('.') // input contains multiple decimal places
|| str.indexOf('-') != str.lastIndexOf('-') // input contains multiple minus signs
|| (str.indexOf('-') != -1 && str.indexOf('-') != 0)) { // input contains a minus sign in a position other than the first character
return NaN; return NaN;
else }
else {
if (str.indexOf('.') == -1) if (str.indexOf('.') == -1)
return parseInt(str); return parseInt(str);
else { else {
if (str.indexOf('.') == str.lastIndexOf('.')) return parseFloat(str);
return parseFloat(str);
else
return NaN;
} }
}
} }
else if (Number.isNaN(str)) else if (Number.isNaN(str))
return NaN; return NaN;

View File

@ -114,8 +114,9 @@
sup { sup {
vertical-align: baseline; vertical-align: baseline;
position: relative; position: relative;
top: -0.4em; top: -0.45em;
line-height: 0; line-height: 0;
font-size: 75%;
} }
sub { sub {
@ -211,9 +212,9 @@
<tr> <tr>
<td class="label">Secondary Display<br />Aspect Ratio:</td> <td class="label">Secondary Display<br />Aspect Ratio:</td>
<td> <td>
<input class="res_input" id="INPUT_HRES2" style="text-align:right;" type="text" onchange="update();" oninput="this.onchange()" onfocus="this.select();" /> <input class="res_input" id="INPUT_HRES2" style="width:32px; text-align:right;" type="text" onchange="update();" oninput="this.onchange()" onfocus="this.select();" />
<span>:</span> <span>:</span>
<input class="res_input" id="INPUT_VRES2" style="text-align:left;" type="text" onchange="update();" oninput="this.onchange()" onfocus="this.select();" /> <input class="res_input" id="INPUT_VRES2" style="width:32px; text-align:left;" type="text" onchange="update();" oninput="this.onchange()" onfocus="this.select();" />
</td> </td>
</tr> </tr>
<tr id="21_9_warning" style="display:none;"> <tr id="21_9_warning" style="display:none;">

View File

@ -89,7 +89,7 @@
</td></tr> </td></tr>
<tr><td><span class="title">HDMI Specification</span> <tr><td><span class="title">HDMI Specification</span>
<ul> <ul>
<li><a target="_blank" href="https://glenwing.github.io/docs/HDMI-2.0.pdf">Version 2.0 (2013&nbsp;September&nbsp;4)</a></li> <li><a target="_blank" href="https://glenwing.github.io/docs/HDMI-2.0.pdf">Version 2.0&nbsp; (2013&nbsp;September&nbsp;4)</a></li>
<li><a target="_blank" href="https://glenwing.github.io/docs/HDMI-1.4b.pdf">Version 1.4b (2011&nbsp;October&nbsp;11)</a></li> <li><a target="_blank" href="https://glenwing.github.io/docs/HDMI-1.4b.pdf">Version 1.4b (2011&nbsp;October&nbsp;11)</a></li>
<li><a target="_blank" href="https://glenwing.github.io/docs/HDMI-1.4a.pdf">Version 1.4a (2010&nbsp;March&nbsp;4)</a></li> <li><a target="_blank" href="https://glenwing.github.io/docs/HDMI-1.4a.pdf">Version 1.4a (2010&nbsp;March&nbsp;4)</a></li>
<li><a target="_blank" href="https://glenwing.github.io/docs/HDMI-1.4.pdf">Version 1.4&nbsp; (2009&nbsp;June&nbsp;5)</a></li> <li><a target="_blank" href="https://glenwing.github.io/docs/HDMI-1.4.pdf">Version 1.4&nbsp; (2009&nbsp;June&nbsp;5)</a></li>