Unverified Commit 2970d3e4 authored by Stefan Brunecker's avatar Stefan Brunecker Committed by GitHub
Browse files

Merge pull request #6 from EmbeddedMontiArc/feature/fix-js-generator

Fix wrong bounds if non-SI unit used
parents 94d88cad a5b8ab9b
......@@ -24,6 +24,8 @@ function getOutRangeNoUnit() {
function setInRangeNoUnit(_inRangeNoUnit) {
var value = math.eval(_inRangeNoUnit);
var lower = -10 / 1;
var upper = 10 / 1;
if (value === undefined) {
throw "Could not evaluate input for _inRangeNoUnit";
......@@ -41,10 +43,10 @@ function setInRangeNoUnit(_inRangeNoUnit) {
var e_num = e;
//check range
if (math.smaller(e_num, -10 / 1)) {
if (math.smaller(e_num, lower)) {
throw "Value " + e_num + " out of range";
}
if (math.larger(e_num, 10 / 1)) {
if (math.larger(e_num, upper)) {
throw "Value " + e_num + " out of range";
}
array[i0] = e_num;
......
......@@ -24,6 +24,8 @@ function getOutRangeUnit() {
function setInRangeUnit(_inRangeUnit) {
var value = math.eval(_inRangeUnit);
var lower = math.eval("-10/3 m/s").toSI().toNumber();
var upper = math.eval("10/1 km/h").toSI().toNumber();
if (value === undefined) {
throw "Could not evaluate input for _inRangeUnit";
......@@ -46,10 +48,10 @@ function setInRangeUnit(_inRangeUnit) {
}
var e_num = e.toSI().toNumber();
//check range
if (math.smaller(e_num, -10 / 3)) {
if (math.smaller(e_num, lower)) {
throw "Value " + e_num + " out of range";
}
if (math.larger(e_num, 10 / 1)) {
if (math.larger(e_num, upper)) {
throw "Value " + e_num + " out of range";
}
array[i0] = e_num;
......
......@@ -24,6 +24,7 @@ function getAcceleration() {
function setPower(_power) {
var value = math.eval(_power);
var lower = math.eval("0/1 kg*m^2/s^3").toSI().toNumber();
if (value === undefined) {
throw "Could not evaluate input for _power";
......@@ -36,7 +37,7 @@ function setPower(_power) {
}
var value_num = value.toSI().toNumber();
//check range
if (math.smaller(value_num, 0 / 1)) {
if (math.smaller(value_num, lower)) {
throw "Value " + value_num + " out of range";
}
Module.setPower(value_num);
......
......@@ -24,6 +24,8 @@ function getOutRangeNoUnit() {
function setInRangeNoUnit(_inRangeNoUnit) {
var value = math.eval(_inRangeNoUnit);
var lower = -10 / 1;
var upper = 10 / 1;
if (value === undefined) {
throw "Could not evaluate input for _inRangeNoUnit";
......@@ -43,10 +45,10 @@ function setInRangeNoUnit(_inRangeNoUnit) {
var e_num = e;
//check range
if (math.smaller(e_num, -10 / 1)) {
if (math.smaller(e_num, lower)) {
throw "Value " + e_num + " out of range";
}
if (math.larger(e_num, 10 / 1)) {
if (math.larger(e_num, upper)) {
throw "Value " + e_num + " out of range";
}
array[i0][i1] = e_num;
......
......@@ -25,6 +25,8 @@ function getOutRangeUnit() {
function setInRangeUnit(_inRangeUnit) {
var value = math.eval(_inRangeUnit);
var lower = math.eval("-10/3 m/s").toSI().toNumber();
var upper = math.eval("10/1 km/h").toSI().toNumber();
if (value === undefined) {
throw "Could not evaluate input for _inRangeUnit";
......@@ -49,10 +51,10 @@ function setInRangeUnit(_inRangeUnit) {
}
var e_num = e.toSI().toNumber();
//check range
if (math.smaller(e_num, -10 / 3)) {
if (math.smaller(e_num, lower)) {
throw "Value " + e_num + " out of range";
}
if (math.larger(e_num, 10 / 1)) {
if (math.larger(e_num, upper)) {
throw "Value " + e_num + " out of range";
}
array[i0][i1] = e_num;
......
......@@ -24,6 +24,8 @@ function getOutRangeNoUnit() {
function setInRangeNoUnit(_inRangeNoUnit) {
var value = math.eval(_inRangeNoUnit);
var lower = -10 / 1;
var upper = 10 / 1;
if (value === undefined) {
throw "Could not evaluate input for _inRangeNoUnit";
......@@ -46,10 +48,10 @@ function setInRangeNoUnit(_inRangeNoUnit) {
var e_num = e;
//check range
if (math.smaller(e_num, -10 / 1)) {
if (math.smaller(e_num, lower)) {
throw "Value " + e_num + " out of range";
}
if (math.larger(e_num, 10 / 1)) {
if (math.larger(e_num, upper)) {
throw "Value " + e_num + " out of range";
}
array[i0][i1][i2] = e_num;
......
......@@ -24,6 +24,8 @@ function getOutRangeUnit() {
function setInRangeUnit(_inRangeUnit) {
var value = math.eval(_inRangeUnit);
var lower = math.eval("-10/3 m/s").toSI().toNumber();
var upper = math.eval("10/1 km/h").toSI().toNumber();
if (value === undefined) {
throw "Could not evaluate input for _inRangeUnit";
......@@ -51,10 +53,10 @@ function setInRangeUnit(_inRangeUnit) {
}
var e_num = e.toSI().toNumber();
//check range
if (math.smaller(e_num, -10 / 3)) {
if (math.smaller(e_num, lower)) {
throw "Value " + e_num + " out of range";
}
if (math.larger(e_num, 10 / 1)) {
if (math.larger(e_num, upper)) {
throw "Value " + e_num + " out of range";
}
array[i0][i1][i2] = e_num;
......
......@@ -24,6 +24,8 @@ function getOutRangeNoUnit() {
function setInRangeNoUnit(_inRangeNoUnit) {
var value = math.eval(_inRangeNoUnit);
var lower = -10 / 1;
var upper = 10 / 1;
if (value === undefined) {
throw "Could not evaluate input for _inRangeNoUnit";
......@@ -43,10 +45,10 @@ function setInRangeNoUnit(_inRangeNoUnit) {
var e_num = e;
//check range
if (math.smaller(e_num, -10 / 1)) {
if (math.smaller(e_num, lower)) {
throw "Value " + e_num + " out of range";
}
if (math.larger(e_num, 10 / 1)) {
if (math.larger(e_num, upper)) {
throw "Value " + e_num + " out of range";
}
array[i0][i1] = e_num;
......
......@@ -24,6 +24,8 @@ function getOutRangeUnit() {
function setInRangeUnit(_inRangeUnit) {
var value = math.eval(_inRangeUnit);
var lower = math.eval("-10/3 m/s").toSI().toNumber();
var upper = math.eval("10/1 km/h").toSI().toNumber();
if (value === undefined) {
throw "Could not evaluate input for _inRangeUnit";
......@@ -48,10 +50,10 @@ function setInRangeUnit(_inRangeUnit) {
}
var e_num = e.toSI().toNumber();
//check range
if (math.smaller(e_num, -10 / 3)) {
if (math.smaller(e_num, lower)) {
throw "Value " + e_num + " out of range";
}
if (math.larger(e_num, 10 / 1)) {
if (math.larger(e_num, upper)) {
throw "Value " + e_num + " out of range";
}
array[i0][i1] = e_num;
......
......@@ -24,6 +24,8 @@ function getOutRangeNoUnit() {
function setInRangeNoUnit(_inRangeNoUnit) {
var value = math.eval(_inRangeNoUnit);
var lower = -10 / 1;
var upper = 10 / 1;
if (value === undefined) {
throw "Could not evaluate input for _inRangeNoUnit";
......@@ -43,10 +45,10 @@ function setInRangeNoUnit(_inRangeNoUnit) {
var e_num = e;
//check range
if (math.smaller(e_num, -10 / 1)) {
if (math.smaller(e_num, lower)) {
throw "Value " + e_num + " out of range";
}
if (math.larger(e_num, 10 / 1)) {
if (math.larger(e_num, upper)) {
throw "Value " + e_num + " out of range";
}
array[i0][i1] = e_num;
......
......@@ -24,6 +24,8 @@ function getOutRangeUnit() {
function setInRangeUnit(_inRangeUnit) {
var value = math.eval(_inRangeUnit);
var lower = math.eval("-10/3 m/s").toSI().toNumber();
var upper = math.eval("10/1 km/h").toSI().toNumber();
if (value === undefined) {
throw "Could not evaluate input for _inRangeUnit";
......@@ -49,10 +51,10 @@ function setInRangeUnit(_inRangeUnit) {
}
var e_num = e.toSI().toNumber();
//check range
if (math.smaller(e_num, -10 / 3)) {
if (math.smaller(e_num, lower)) {
throw "Value " + e_num + " out of range";
}
if (math.larger(e_num, 10 / 1)) {
if (math.larger(e_num, upper)) {
throw "Value " + e_num + " out of range";
}
array[i0][i1] = e_num;
......
......@@ -24,6 +24,8 @@ function getOutRangeNoUnit() {
function setInRangeNoUnit(_inRangeNoUnit) {
var value = math.eval(_inRangeNoUnit);
var lower = -10 / 1;
var upper = 10 / 1;
if (value === undefined) {
throw "Could not evaluate input for _inRangeNoUnit";
......@@ -31,10 +33,10 @@ function setInRangeNoUnit(_inRangeNoUnit) {
var value_num = value;
//check range
if (math.smaller(value_num, -10 / 1)) {
if (math.smaller(value_num, lower)) {
throw "Value " + value_num + " out of range";
}
if (math.larger(value_num, 10 / 1)) {
if (math.larger(value_num, upper)) {
throw "Value " + value_num + " out of range";
}
Module.setInRangeNoUnit(value_num);
......
......@@ -24,6 +24,8 @@ function getOutRangeUnit() {
function setInRangeUnit(_inRangeUnit) {
var value = math.eval(_inRangeUnit);
var lower = math.eval("-10/3 m/s").toSI().toNumber();
var upper = math.eval("10/1 km/h").toSI().toNumber();
if (value === undefined) {
throw "Could not evaluate input for _inRangeUnit";
......@@ -36,10 +38,10 @@ function setInRangeUnit(_inRangeUnit) {
}
var value_num = value.toSI().toNumber();
//check range
if (math.smaller(value_num, -10 / 3)) {
if (math.smaller(value_num, lower)) {
throw "Value " + value_num + " out of range";
}
if (math.larger(value_num, 10 / 1)) {
if (math.larger(value_num, upper)) {
throw "Value " + value_num + " out of range";
}
Module.setInRangeUnit(value_num);
......
......@@ -24,6 +24,7 @@ function getOutThousandsMatrixArray() {
function setInThousandsMatrixArray(_inThousandsMatrixArray) {
var value = math.eval(_inThousandsMatrixArray);
var lower = math.eval("2/1 m").toSI().toNumber();
if (value === undefined) {
throw "Could not evaluate input for _inThousandsMatrixArray";
......@@ -52,7 +53,7 @@ function setInThousandsMatrixArray(_inThousandsMatrixArray) {
}
var e_num = e.toSI().toNumber();
//check range
if (math.smaller(e_num, 2 / 1)) {
if (math.smaller(e_num, lower)) {
throw "Value " + e_num + " out of range";
}
array[i0][i1][i2][i3] = e_num;
......
......@@ -29,12 +29,14 @@ function getK() {
function setM1(_m1) {
var value = math.eval(_m1);
var lower = math.eval("0/1 m").toSI().toNumber();
var upper = math.eval("10/1 km").toSI().toNumber();
if (value === undefined) {
throw "Could not evaluate input for _m1";
}
//check dimension
//check dimension
var dim = math.matrix([2, 3]);
if (!math.deepEqual(value.size(), dim)) {
throw "Input has dimension " + value.size() + " but expected " + dim;
......@@ -54,10 +56,10 @@ function setM1(_m1) {
var e_num = e.toSI().toNumber();
//check range
if (math.smaller(e_num, 0 / 1)) {
if (math.smaller(e_num, lower)) {
throw "Value " + e_num + " out of range";
}
if (math.larger(e_num, 10 / 1)) {
if (math.larger(e_num, upper)) {
throw "Value " + e_num + " out of range";
}
array[i0][i1] = e_num;
......@@ -68,12 +70,14 @@ function setM1(_m1) {
function setM2(_m2) {
var value = math.eval(_m2);
var lower = math.eval("5/1 Hz").toSI().toNumber();
var upper = math.eval("20/1 kHz").toSI().toNumber();
if (value === undefined) {
throw "Could not evaluate input for _m2";
}
//check dimension
//check dimension
var dim = math.matrix([3, 1]);
if (!math.deepEqual(value.size(), dim)) {
throw "Input has dimension " + value.size() + " but expected " + dim;
......@@ -93,10 +97,10 @@ function setM2(_m2) {
var e_num = e.toSI().toNumber();
//check range
if (math.smaller(e_num, 5 / 1)) {
if (math.smaller(e_num, lower)) {
throw "Value " + e_num + " out of range";
}
if (math.larger(e_num, 20 / 1)) {
if (math.larger(e_num, upper)) {
throw "Value " + e_num + " out of range";
}
array[i0][i1] = e_num;
......@@ -107,6 +111,8 @@ function setM2(_m2) {
function setC(_c) {
var value = math.eval(_c);
var lower = math.eval("-2/1 mm/h").toSI().toNumber();
var upper = math.eval("2/1 km/s").toSI().toNumber();
if (value === undefined) {
throw "Could not evaluate input for _c";
......@@ -120,10 +126,10 @@ function setC(_c) {
var value_num = value.toSI().toNumber();
//check range
if (math.smaller(value_num, -2 / 1)) {
if (math.smaller(value_num, lower)) {
throw "Value " + value_num + " out of range";
}
if (math.larger(value_num, 2 / 1)) {
if (math.larger(value_num, upper)) {
throw "Value " + value_num + " out of range";
}
Module.setC(value_num);
......
......@@ -25,9 +25,25 @@ function execute() {
<#assign varNumber = varName + "_num">
<#assign elementName = "e">
<#assign elementNumber = elementName + "_num">
<#assign lowerBoundVar = "lower">
<#assign upperBoundVar = "upper">
function ${setter.methodName}(${setter.parameterName}) {
var ${varName} = math.eval(${setter.parameterName});
<#if setter.lowerBoundValue?has_content>
<#if setter.lowerBoundUnit?has_content>
var ${lowerBoundVar} = math.eval("${setter.lowerBoundValue} ${setter.lowerBoundUnit}").toSI().toNumber();
<#else>
var ${lowerBoundVar} = ${setter.lowerBoundValue};
</#if>
</#if>
<#if setter.upperBoundValue?has_content>
<#if setter.upperBoundUnit?has_content>
var ${upperBoundVar} = math.eval("${setter.upperBoundValue} ${setter.upperBoundUnit}").toSI().toNumber();
<#else>
var ${upperBoundVar} = ${setter.upperBoundValue};
</#if>
</#if>
if (${varName} === undefined) {
throw "Could not evaluate input for ${setter.parameterName}";
......@@ -97,12 +113,12 @@ function execute() {
<#if lowerBound?has_content || upperBound?has_content>
//check range
<#if lowerBound?has_content>
if (math.smaller(${var}, ${lowerBound})) {
if (math.smaller(${var}, ${lowerBoundVar})) {
throw "Value " + ${var} + " out of range";
}
</#if>
<#if upperBound?has_content>
if (math.larger(${var}, ${upperBound})) {
if (math.larger(${var}, ${upperBoundVar})) {
throw "Value " + ${var} + " out of range";
}
</#if>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment