Skip to content

Commit

Permalink
Merge branch 'master' of github.com:pandrr/cables
Browse files Browse the repository at this point in the history
  • Loading branch information
undev-studio committed Feb 5, 2024
2 parents 8b2ca96 + 7ee0ba2 commit c235e14
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 16 deletions.
30 changes: 21 additions & 9 deletions src/ops/base/Ops.Math.MapRange/Ops.Math.MapRange.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ const
new_min = op.inValueFloat("new min", 0),
new_max = op.inValueFloat("new max", 1),
easing = op.inValueSelect("Easing", ["Linear", "Smoothstep", "Smootherstep"], "Linear"),
inClamp = op.inBool("Clamp", true),
result = op.outNumber("result", 0);

op.setPortGroup("Input Range", [old_min, old_max]);
op.setPortGroup("Output Range", [new_min, new_max]);

let doClamp = true;
let ease = 0;
let r = 0;

Expand All @@ -21,6 +23,13 @@ v.onChange =

exec();

inClamp.onChange =
() =>
{
doClamp = inClamp.get();
exec();
};

easing.onChange = function ()
{
if (easing.get() == "Smoothstep") ease = 1;
Expand All @@ -36,16 +45,19 @@ function exec()
const oMax = old_max.get();
let x = v.get();

if (x >= Math.max(oMax, oMin))
{
result.set(nMax);
return;
}
else
if (x <= Math.min(oMax, oMin))
if (doClamp)
{
result.set(nMin);
return;
if (x >= Math.max(oMax, oMin))
{
result.set(nMax);
return;
}
else
if (x <= Math.min(oMax, oMin))
{
result.set(nMin);
return;
}
}

let reverseInput = false;
Expand Down
25 changes: 18 additions & 7 deletions src/ops/base/Ops.Math.MapRange/Ops.Math.MapRange.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,48 @@
"layout": {
"portsIn": [
{
"type": 0,
"type": "0",
"name": "value",
"subType": "number"
},
{
"type": 0,
"type": "0",
"name": "old min",
"group": "Input Range",
"subType": "number"
},
{
"type": 0,
"type": "0",
"name": "old max",
"group": "Input Range",
"subType": "number"
},
{
"type": 0,
"type": "0",
"name": "new min",
"group": "Output Range",
"subType": "number"
},
{
"type": 0,
"type": "0",
"name": "new max",
"group": "Output Range",
"subType": "number"
},
{
"type": 0,
"type": "0",
"name": "Easing index",
"subType": "integer"
},
{
"type": "0",
"name": "Clamp",
"subType": "boolean"
}
],
"portsOut": [
{
"type": 0,
"type": "0",
"name": "result",
"subType": "number"
}
Expand Down Expand Up @@ -88,6 +93,12 @@
"type": "improvement",
"author": "pandur",
"date": 1704977985405
},
{
"message": "added option to turn off clamping, so values can be bigger then the specified min/max input range",
"type": "feature",
"author": "pandur",
"date": 1706885722609
}
]
}
2 changes: 2 additions & 0 deletions src/ops/base/Ops.Math.MapRange/Ops.Math.MapRange.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
changes a number's relative value by mapping within one range to the equivalent position in another range.
For example, given the range of 0 to 100, 50 would be halfway between. so if it were mapped to a range of 0 to 50, it would be 25 (because 25 is exactly half that range).

0 comments on commit c235e14

Please sign in to comment.