Skip to content

Commit

Permalink
Fix nLimit and setMag functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Smilebags committed Jan 15, 2017
1 parent ab67ee1 commit 051a060
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions libraries/p5.dimensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,26 +87,27 @@ p5.prototype.nEqual = function(v1,v2){ //Checks if vectors are equal
}

p5.prototype.nNormalize = function(v1){
var obj = new Object();
var obj = new nVector();
for (var i = 0; i < Object.keys(v1).length; i++){
obj[Object.keys(v1)[i]] = v1[Object.keys(v1)[i]]/nMag(v1);
obj[dimensionalSymbols[i]] = v1[dimensionalSymbols[i]]/nMag(v1);
}
return obj;
}

p5.prototype.nSetMag = function(v1, n){
v1 = nNormalize(v1);

var output = nNormalize(v1);
for (var i = 0; i < Object.keys(v1).length; i++){
output[dimensionalSymbols[i]] = output[dimensionalSymbols[i]] * n;
}
return output;
}

p5.prototype.nLimit = function(v1, n){
var output = v1;
if (nMagSq(v1) > n * n) {
v1 = nSetMag(v1, n);
}
for (var i = 0; i < Object.keys(v1).length; i++){
v1[i] = v1[i] * n;
output = nSetMag(v1, n);
}
return v1;
return output;
}

p5.prototype.nAdd = function(v1,v2) {
Expand Down

1 comment on commit 051a060

@Smilebags
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding a comment referencing #8 to keep track of changes from there.

Please sign in to comment.