1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Fix boundary problem in range node (#1338)

* Fix boundary problem in range node

* Remove duplicated test case

* Empty commit to retry Travis CI
This commit is contained in:
Kazuhito Yokoi 2017-07-20 00:42:39 +09:00 committed by Nick O'Leary
parent a40b3dd377
commit c6e453fb00
2 changed files with 6 additions and 6 deletions

View File

@ -35,8 +35,8 @@ module.exports = function(RED) {
if (n > node.maxin) { n = node.maxin; }
}
if (node.action == "roll") {
if (n >= node.maxin) { n = (n - node.minin) % (node.maxin - node.minin) + node.minin; }
if (n < node.minin) { n = (n - node.minin) % (node.maxin - node.minin) + node.maxin; }
var divisor = node.maxin - node.minin;
n = ((n - node.minin) % divisor + divisor) % divisor + node.minin;
}
msg.payload = ((n - node.minin) / (node.maxin - node.minin) * (node.maxout - node.minout)) + node.minout;
if (node.round) { msg.payload = Math.round(msg.payload); }

View File

@ -90,14 +90,14 @@ describe('range Node', function() {
genericRangeTest("roll", 0, 10, 0, 360, true, 12.5, 90, done); // 1/4 around wrap => "one and a quarter turns"
});
it('wraps numbers around say for degree/rotation reading 1/4', function(done) {
genericRangeTest("roll", 0, 10, 0, 360, true, 12.5, 90, done); // 1/4 around wrap => "one and a quarter turns"
});
it('wraps numbers down say for degree/rotation reading 1/4', function(done) {
genericRangeTest("roll", 0, 10, 0, 360, true, -12.5, 270, done); // 1/4 backwards wrap => "one and a quarter turns backwards"
});
it('wraps numbers around say for degree/rotation reading 0', function(done) {
genericRangeTest("roll", 0, 10, 0, 360, true, -10, 0, done);
});
it('clamps numbers within a range - over max', function(done) {
genericRangeTest("clamp", 0, 10, 0, 1000, false, 111, 1000, done);
});