Skip to content

Commit

Permalink
fixed bug in operator
Browse files Browse the repository at this point in the history
  • Loading branch information
tamat committed Oct 5, 2023
1 parent a729b07 commit 2d83d6e
Show file tree
Hide file tree
Showing 8 changed files with 44,811 additions and 16,919 deletions.
14,297 changes: 14,297 additions & 0 deletions build/litegraph.core.js

Large diffs are not rendered by default.

353 changes: 353 additions & 0 deletions build/litegraph.core.min.js

Large diffs are not rendered by default.

14,203 changes: 9,795 additions & 4,408 deletions build/litegraph.js

Large diffs are not rendered by default.

13,403 changes: 912 additions & 12,491 deletions build/litegraph.min.js

Large diffs are not rendered by default.

18,938 changes: 18,938 additions & 0 deletions build/litegraph_mini.js

Large diffs are not rendered by default.

492 changes: 492 additions & 0 deletions build/litegraph_mini.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "litegraph.js",
"version": "0.7.12",
"version": "0.7.14",
"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.",
"main": "build/litegraph.js",
"types": "src/litegraph.d.ts",
Expand Down
42 changes: 23 additions & 19 deletions src/nodes/math.js
Original file line number Diff line number Diff line change
Expand Up @@ -634,11 +634,23 @@
this.addProperty("A", 1);
this.addProperty("B", 1);
this.addProperty("OP", "+", "enum", { values: MathOperation.values });
this._func = function(A,B) { return A + B; };
this._func = MathOperation.funcs[this.properties.OP];
this._result = []; //only used for arrays
}

MathOperation.values = ["+", "-", "*", "/", "%", "^", "max", "min"];
MathOperation.funcs = {
"+": function(A,B) { return A + B; },
"-": function(A,B) { return A - B; },
"x": function(A,B) { return A * B; },
"X": function(A,B) { return A * B; },
"*": function(A,B) { return A * B; },
"/": function(A,B) { return A / B; },
"%": function(A,B) { return A % B; },
"^": function(A,B) { return Math.pow(A, B); },
"max": function(A,B) { return Math.max(A, B); },
"min": function(A,B) { return Math.min(A, B); }
};

MathOperation.title = "Operation";
MathOperation.desc = "Easy math operators";
Expand Down Expand Up @@ -666,21 +678,11 @@
{
if (name != "OP")
return;
switch (this.properties.OP) {
case "+": this._func = function(A,B) { return A + B; }; break;
case "-": this._func = function(A,B) { return A - B; }; break;
case "x":
case "X":
case "*": this._func = function(A,B) { return A * B; }; break;
case "/": this._func = function(A,B) { return A / B; }; break;
case "%": this._func = function(A,B) { return A % B; }; break;
case "^": this._func = function(A,B) { return Math.pow(A, B); }; break;
case "max": this._func = function(A,B) { return Math.max(A, B); }; break;
case "min": this._func = function(A,B) { return Math.min(A, B); }; break;
default:
console.warn("Unknown operation: " + this.properties.OP);
this._func = function(A) { return A; };
break;
this._func = MathOperation.funcs[this.properties.OP];
if(!this._func)
{
console.warn("Unknown operation: " + this.properties.OP);
this._func = function(A) { return A; };
}
}

Expand All @@ -700,24 +702,26 @@
B = this.properties["B"];
}

var func = MathOperation.funcs[this.properties.OP];

var result;
if(A.constructor === Number)
{
result = 0;
result = this._func(A,B);
result = func(A,B);
}
else if(A.constructor === Array)
{
result = this._result;
result.length = A.length;
for(var i = 0; i < A.length; ++i)
result[i] = this._func(A[i],B);
result[i] = func(A[i],B);
}
else
{
result = {};
for(var i in A)
result[i] = this._func(A[i],B);
result[i] = func(A[i],B);
}
this.setOutputData(0, result);
};
Expand Down

0 comments on commit 2d83d6e

Please sign in to comment.