Skip to content

Commit 2d83d6e

Browse files
author
tamat
committed
fixed bug in operator
1 parent a729b07 commit 2d83d6e

File tree

8 files changed

+44811
-16919
lines changed

8 files changed

+44811
-16919
lines changed

build/litegraph.core.js

Lines changed: 14297 additions & 0 deletions
Large diffs are not rendered by default.

build/litegraph.core.min.js

Lines changed: 353 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/litegraph.js

Lines changed: 9795 additions & 4408 deletions
Large diffs are not rendered by default.

build/litegraph.min.js

Lines changed: 912 additions & 12491 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/litegraph_mini.js

Lines changed: 18938 additions & 0 deletions
Large diffs are not rendered by default.

build/litegraph_mini.min.js

Lines changed: 492 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "litegraph.js",
3-
"version": "0.7.12",
3+
"version": "0.7.14",
44
"description": "A graph node editor similar to PD or UDK Blueprints. It works in an HTML5 Canvas and allows to export graphs to be included in applications.",
55
"main": "build/litegraph.js",
66
"types": "src/litegraph.d.ts",

src/nodes/math.js

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -634,11 +634,23 @@
634634
this.addProperty("A", 1);
635635
this.addProperty("B", 1);
636636
this.addProperty("OP", "+", "enum", { values: MathOperation.values });
637-
this._func = function(A,B) { return A + B; };
637+
this._func = MathOperation.funcs[this.properties.OP];
638638
this._result = []; //only used for arrays
639639
}
640640

641641
MathOperation.values = ["+", "-", "*", "/", "%", "^", "max", "min"];
642+
MathOperation.funcs = {
643+
"+": function(A,B) { return A + B; },
644+
"-": function(A,B) { return A - B; },
645+
"x": function(A,B) { return A * B; },
646+
"X": function(A,B) { return A * B; },
647+
"*": function(A,B) { return A * B; },
648+
"/": function(A,B) { return A / B; },
649+
"%": function(A,B) { return A % B; },
650+
"^": function(A,B) { return Math.pow(A, B); },
651+
"max": function(A,B) { return Math.max(A, B); },
652+
"min": function(A,B) { return Math.min(A, B); }
653+
};
642654

643655
MathOperation.title = "Operation";
644656
MathOperation.desc = "Easy math operators";
@@ -666,21 +678,11 @@
666678
{
667679
if (name != "OP")
668680
return;
669-
switch (this.properties.OP) {
670-
case "+": this._func = function(A,B) { return A + B; }; break;
671-
case "-": this._func = function(A,B) { return A - B; }; break;
672-
case "x":
673-
case "X":
674-
case "*": this._func = function(A,B) { return A * B; }; break;
675-
case "/": this._func = function(A,B) { return A / B; }; break;
676-
case "%": this._func = function(A,B) { return A % B; }; break;
677-
case "^": this._func = function(A,B) { return Math.pow(A, B); }; break;
678-
case "max": this._func = function(A,B) { return Math.max(A, B); }; break;
679-
case "min": this._func = function(A,B) { return Math.min(A, B); }; break;
680-
default:
681-
console.warn("Unknown operation: " + this.properties.OP);
682-
this._func = function(A) { return A; };
683-
break;
681+
this._func = MathOperation.funcs[this.properties.OP];
682+
if(!this._func)
683+
{
684+
console.warn("Unknown operation: " + this.properties.OP);
685+
this._func = function(A) { return A; };
684686
}
685687
}
686688

@@ -700,24 +702,26 @@
700702
B = this.properties["B"];
701703
}
702704

705+
var func = MathOperation.funcs[this.properties.OP];
706+
703707
var result;
704708
if(A.constructor === Number)
705709
{
706710
result = 0;
707-
result = this._func(A,B);
711+
result = func(A,B);
708712
}
709713
else if(A.constructor === Array)
710714
{
711715
result = this._result;
712716
result.length = A.length;
713717
for(var i = 0; i < A.length; ++i)
714-
result[i] = this._func(A[i],B);
718+
result[i] = func(A[i],B);
715719
}
716720
else
717721
{
718722
result = {};
719723
for(var i in A)
720-
result[i] = this._func(A[i],B);
724+
result[i] = func(A[i],B);
721725
}
722726
this.setOutputData(0, result);
723727
};

0 commit comments

Comments
 (0)