moved unit conversion function

This commit is contained in:
King Kévin 2015-08-30 10:15:31 +02:00
parent 4c12df6a26
commit 450b7103a9
2 changed files with 39 additions and 40 deletions

View File

@ -91,6 +91,45 @@ function cvlp_rectangle(x, y, width, height, thickness, radius=0, round=true) {
return rectangle
}
// convert value from one unit to another
// units allowed: mm, in, mil
// returns converted value, on null if unknown unit
function convert_unit(value, from, to) {
// don't convert if the unit is the same (avoid calculation imprecisions)
if (from==to) {
return value;
}
// convert to µm
var mum = 0;
switch (from) {
case 'mm':
mum = value*1000;
break;
case 'in':
mum = value*1000*25.40;
break;
case 'mil':
mum = value*25.40;
break;
default:
return null;
}
switch (to) {
case 'mm':
mum = mum/1000;
break;
case 'in':
mum = mum/1000/25.40;
break;
case 'mil':
mum = mum/25.40;
break;
default:
return null;
}
return mum;
}
// convert JSON to SVG
function json2svg(json) {
// create svg

View File

@ -166,46 +166,6 @@
logo.unit = unit
draw()
}
// convert value from one unit to another
// units allowed: mm, in, mil
// returns converted value, on null if unknown unit
function convert_unit(value, from, to)
{
// don't convert if the unit is the same (avoid calculation imprecisions)
if (from==to) {
return value;
}
// convert to µm
var mum = 0;
switch (from) {
case 'mm':
mum = value*1000;
break;
case 'in':
mum = value*1000*25.40;
break;
case 'mil':
mum = value*25.40;
break;
default:
return null;
}
switch (to) {
case 'mm':
mum = mum/1000;
break;
case 'in':
mum = mum/1000/25.40;
break;
case 'mil':
mum = mum/25.40;
break;
default:
return null;
}
return mum;
}
</script>
<div id="svg"></div>
<p id="control">