Skip to content

Commit 24cd6a3

Browse files
author
Saksham Saxena
committed
Merge branch 'master' into almost-eased-up
2 parents d0d9f6f + 2f521ca commit 24cd6a3

File tree

6 files changed

+57
-28
lines changed

6 files changed

+57
-28
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ Using the original metaphor of a software sketchbook, p5.js has a full set of dr
88

99
p5.js is a new interpretation, not an emulation or port, and it is in active development. An official editing environment is coming soon, as well as many more features!
1010

11-
If you already know the basics of JS or Processing, the [p5.js overview](https://github.com/processing/p5.js/wiki/p5.js-overview) wiki page is a good place to start. The [frequently asked questions](https://github.com/processing/p5.js/wiki/Frequently-Asked-Questions) might also be helpful.
11+
If you already know the basics of JavaScript or Processing, the [p5.js overview](https://github.com/processing/p5.js/wiki/p5.js-overview) wiki page is a good place to start. The [frequently asked questions](https://github.com/processing/p5.js/wiki/Frequently-Asked-Questions) might also be helpful.
1212

13-
If you have found a bug in the p5.js library, you can file it here under the [“issues” tab](https://github.com/processing/p5.js/issues).
13+
If you have found a bug in the p5.js library, you can file it here under the [“issues” tab](https://github.com/processing/p5.js/issues). An indicative template for reporting an issue is provided to assist you (and us!) better.
1414

1515
## p5.js library
1616

17-
To use p5.js, you can [download the p5.js library here](http://p5js.org/download). If you are interested in the most recent, less stable version, you can clone this repository and run `grunt` from the command line to generate the library from source. See the [development](https://github.com/processing/p5.js/wiki/Development) wiki for more information about our build process.
17+
To use the complete p5.js library, you can [download it here](http://p5js.org/download). If you are interested in the most recent, less stable version, or even simply in (**new!**) certain components of p5.js, you can clone this repository and run `grunt` from the command line to generate the library from source. See the [development](https://github.com/processing/p5.js/wiki/Development#Setup) wiki for more information about our build process to generate the complete as well as selective library.
1818

1919
## Issues
2020

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"docs": "grunt yui",
1111
"test": "grunt"
1212
},
13-
"version": "0.5.12",
13+
"version": "0.5.13",
1414
"devDependencies": {
1515
"amdclean": "~0.3.3",
1616
"browserify": "^11.0.1",

src/core/error_helpers.js

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -58,19 +58,14 @@ function report(message, func, color) {
5858
}
5959
if (func.substring(0,4) === 'load'){
6060
console.log(
61-
'%c> p5.js says: '+message+'%c'+
62-
'[https://github.com/processing/p5.js/wiki/Local-server]',
63-
'background-color:' + color + ';color:#FFF;',
64-
'background-color:transparent;color:' + color +';',
65-
'background-color:' + color + ';color:#FFF;',
66-
'background-color:transparent;color:' + color +';'
61+
'> p5.js says: '+message+
62+
'[https://github.com/processing/p5.js/wiki/Local-server]'
6763
);
6864
}
6965
else{
7066
console.log(
71-
'%c> p5.js says: '+message+'%c [http://p5js.org/reference/#p5/'+func+
72-
']', 'background-color:' + color + ';color:#FFF;',
73-
'background-color:transparent;color:' + color +';'
67+
'> p5.js says: '+message+' [http://p5js.org/reference/#p5/'+func+
68+
']'
7469
);
7570
}
7671
}
@@ -103,7 +98,7 @@ p5._friendlyFileLoadError = function (errorType, filePath) {
10398
var errorInfo = errorCases[ errorType ];
10499
var message = 'It looks like there was a problem' +
105100
' loading your ' + errorInfo.fileType + '.' +
106-
' Try checking if the file path%c [' + filePath + '] %cis correct,' +
101+
' Try checking if the file path [' + filePath + '] is correct,' +
107102
(errorInfo.message || '') + ' or running a local server.';
108103
report(message, errorInfo.method, FILE_LOAD);
109104
};
@@ -239,7 +234,7 @@ p5._friendlyParamError = function (errorObj, func) {
239234
message = 'It looks like ' + func +
240235
'() received an empty variable in spot #' + errorObj.position +
241236
' (zero-based index). If not intentional, this is often a problem' +
242-
' with scope: [link to scope].';
237+
' with scope: [https://p5js.org/examples/data-variable-scope.html].';
243238
report(message, func, ERR_PARAMS);
244239
break;
245240
case 'WRONG_CLASS':
@@ -259,21 +254,19 @@ p5._friendlyParamError = function (errorObj, func) {
259254
};
260255
function friendlyWelcome() {
261256
// p5.js brand - magenta: #ED225D
262-
var astrixBgColor = 'transparent';
263-
var astrixTxtColor = '#ED225D';
264-
var welcomeBgColor = '#ED225D';
265-
var welcomeTextColor = 'white';
257+
//var astrixBgColor = 'transparent';
258+
//var astrixTxtColor = '#ED225D';
259+
//var welcomeBgColor = '#ED225D';
260+
//var welcomeTextColor = 'white';
266261
console.log(
267-
'%c _ \n'+
262+
' _ \n'+
268263
' /\\| |/\\ \n'+
269264
' \\ ` \' / \n'+
270265
' / , . \\ \n'+
271266
' \\/|_|\\/ '+
272-
'\n\n%c> p5.js says: Welcome! '+
267+
'\n\n> p5.js says: Welcome! '+
273268
'This is your friendly debugger. ' +
274-
'To turn me off switch to using “p5.min.js”.',
275-
'background-color:'+astrixBgColor+';color:' + astrixTxtColor +';',
276-
'background-color:'+welcomeBgColor+';color:' + welcomeTextColor +';'
269+
'To turn me off switch to using “p5.min.js”.'
277270
);
278271
}
279272

@@ -392,12 +385,11 @@ function helpForMisusedAtTopLevelCode(e, log) {
392385
// * Uncaught ReferenceError: PI is not defined (Chrome)
393386

394387
if (e.message && e.message.match('\\W?'+symbol.name+'\\W') !== null) {
395-
log('%cDid you just try to use p5.js\'s ' + symbol.name +
388+
log('Did you just try to use p5.js\'s ' + symbol.name +
396389
(symbol.type === 'function' ? '() ' : ' ') + symbol.type +
397390
'? If so, you may want to ' +
398391
'move it into your sketch\'s setup() function.\n\n' +
399-
'For more details, see: ' + FAQ_URL,
400-
'color: #B40033' /* Dark magenta */);
392+
'For more details, see: ' + FAQ_URL);
401393
return true;
402394
}
403395
});

src/math/p5.Vector.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,13 @@ p5.Vector.prototype.rotate = function (a) {
636636
* </div>
637637
*/
638638
p5.Vector.prototype.angleBetween = function (v) {
639-
var angle = Math.acos(this.dot(v) / (this.mag() * v.mag()));
639+
var dotmagmag = this.dot(v) / (this.mag() * v.mag());
640+
// Mathematically speaking: the dotmagmag variable will be between -1 and 1
641+
// inclusive. Practically though it could be slightly outside this range due
642+
// to floating-point rounding issues. This can make Math.acos return NaN.
643+
//
644+
// Solution: we'll clamp the value to the -1,1 range
645+
var angle = Math.acos(Math.min(1, Math.max(-1, dotmagmag)));
640646
if (this.p5) {
641647
if (this.p5._angleMode === constants.DEGREES) {
642648
angle = polarGeometry.radiansToDegrees(angle);

test/unit/core/structure.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ suite('Structure', function() {
1414
//myp5.noLoop();
1515
var c0 = myp5.frameCount;
1616
myp5.noLoop();
17+
myp5.ellipse(0, 0, 10, 10);
1718
var c1 = myp5.frameCount;
1819
assert.equal(c0, c1);
1920
});
@@ -22,6 +23,7 @@ suite('Structure', function() {
2223
myp5.noLoop();
2324
var c0 = myp5.frameCount;
2425
myp5.loop();
26+
myp5.ellipse(0, 0, 10, 10);
2527
var c1 = myp5.frameCount;
2628
assert.notEqual(c0, c1);
2729
});

test/unit/math/p5.Vector.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,35 @@ suite('p5.Vector', function() {
114114
assert.closeTo(v.z, 0, 0.001);
115115
});
116116
});
117+
118+
suite('p5.prototype.angleBetween()', function() {
119+
test('should not trip on rounding issues in 2D space', function() {
120+
var v1 = myp5.createVector(-11, -20);
121+
var v2 = myp5.createVector(-5.5, -10);
122+
expect(v1.angleBetween(v2)).to.be.closeTo(0, 0.00001);
123+
124+
var v3 = myp5.createVector(-11, -20);
125+
var v4 = myp5.createVector(5.5, 10);
126+
expect(v3.angleBetween(v4)).to.be.closeTo(180, 0.00001);
127+
});
128+
129+
test('should not trip on rounding issues in 3D space', function() {
130+
var v1 = myp5.createVector(1, 1.1, 1.2);
131+
var v2 = myp5.createVector(2, 2.2, 2.4);
132+
133+
var angle = v1.angleBetween(v2);
134+
expect(angle).to.be.closeTo(0, 0.00001);
135+
});
136+
137+
test('should return NaN for zero vector', function() {
138+
var v1 = myp5.createVector(0, 0, 0);
139+
var v2 = myp5.createVector(2, 3, 4);
140+
141+
expect(v1.angleBetween(v2)).to.be.NaN; // jshint ignore:line
142+
expect(v2.angleBetween(v1)).to.be.NaN; // jshint ignore:line
143+
});
144+
145+
});
117146
});
118147

119148
// describe('set()', function() {

0 commit comments

Comments
 (0)