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:
parent
a40b3dd377
commit
c6e453fb00
@ -35,8 +35,8 @@ module.exports = function(RED) {
|
|||||||
if (n > node.maxin) { n = node.maxin; }
|
if (n > node.maxin) { n = node.maxin; }
|
||||||
}
|
}
|
||||||
if (node.action == "roll") {
|
if (node.action == "roll") {
|
||||||
if (n >= node.maxin) { n = (n - node.minin) % (node.maxin - node.minin) + node.minin; }
|
var divisor = node.maxin - node.minin;
|
||||||
if (n < node.minin) { n = (n - node.minin) % (node.maxin - node.minin) + node.maxin; }
|
n = ((n - node.minin) % divisor + divisor) % divisor + node.minin;
|
||||||
}
|
}
|
||||||
msg.payload = ((n - node.minin) / (node.maxin - node.minin) * (node.maxout - node.minout)) + node.minout;
|
msg.payload = ((n - node.minin) / (node.maxin - node.minin) * (node.maxout - node.minout)) + node.minout;
|
||||||
if (node.round) { msg.payload = Math.round(msg.payload); }
|
if (node.round) { msg.payload = Math.round(msg.payload); }
|
||||||
|
@ -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"
|
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) {
|
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"
|
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) {
|
it('clamps numbers within a range - over max', function(done) {
|
||||||
genericRangeTest("clamp", 0, 10, 0, 1000, false, 111, 1000, done);
|
genericRangeTest("clamp", 0, 10, 0, 1000, false, 111, 1000, done);
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user