Skip to content

Commit

Permalink
Tidies formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
ianmcgregor committed Dec 17, 2015
1 parent 28dcc18 commit b9be46f
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 51 deletions.
97 changes: 49 additions & 48 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,48 +18,50 @@ var standaloneName = 'Boid',

// log
function logError(msg) {
console.log(chalk.bold.red('[ERROR] ' + msg.toString()));
console.log(chalk.bold.red('[ERROR] ' + msg.toString()));
}

// bundler
var bundler = watchify(browserify({
entries: ['src/' + entryFileName],
standalone: standaloneName,
debug: true,
cache: {},
packageCache: {}
}), {poll: true});
entries: ['src/' + entryFileName],
standalone: standaloneName,
debug: true,
cache: {},
packageCache: {}
}));

function bundle() {
return bundler
.bundle()
.on('error', logError)
.pipe(source(bundleFileName))
.pipe(buffer())
.pipe(gulp.dest('./dist/'))
.pipe(rename({ extname: '.min.js' }))
.pipe(uglify())
.pipe(strip())
.pipe(gulp.dest('./dist/'));
return bundler
.bundle()
.on('error', logError)
.pipe(source(bundleFileName))
.pipe(buffer())
.pipe(gulp.dest('./dist/'))
.pipe(rename({
extname: '.min.js'
}))
.pipe(uglify())
.pipe(strip())
.pipe(gulp.dest('./dist/'));
}

bundler.on('update', bundle); // on any dep update, runs the bundler
gulp.task('bundle', ['jshint'], bundle);

function bundleRelease(minify) {
var bundler = browserify({
entries: ['./src/' + entryFileName],
standalone: standaloneName,
debug: !minify
});

return bundler
return browserify({
entries: ['./src/' + entryFileName],
standalone: standaloneName,
debug: !minify
})
.bundle()
.on('error', logError)
.pipe(source(bundleFileName))
.pipe(buffer())
.pipe(gulp.dest('./dist/'))
.pipe(rename({ extname: '.min.js' }))
.pipe(rename({
extname: '.min.js'
}))
.pipe(uglify())
.pipe(strip())
.pipe(gulp.dest('./dist/'));
Expand All @@ -69,41 +71,40 @@ gulp.task('release', bundleRelease);

// connect browsers
gulp.task('connect', function() {
browserSync.init({
server: {
baseDir: ['./', 'examples']
},
files: [
'dist/*',
'examples/**/*'
],
reloadDebounce: 500
});
browserSync.init({
server: {
baseDir: ['./', 'examples']
},
files: [
'dist/*',
'examples/**/*'
],
reloadDebounce: 500
});
});

// reload browsers
gulp.task('reload', function() {
browserSync.reload();
browserSync.reload();
});

// js hint
gulp.task('jshint', function() {
return gulp.src([
'./gulpfile.js',
'src/**/*.js',
'test/**/*.js',
'examples/**/*.js',
'!examples/js/highlight.pack.js'
])
.pipe(jshint())
.pipe(jshint.reporter('jshint-stylish'));
return gulp.src([
'./gulpfile.js',
'src/**/*.js',
'test/**/*.js',
'examples/**/*.js',
'!examples/js/highlight.pack.js'
])
.pipe(jshint())
.pipe(jshint.reporter('jshint-stylish'));
});

// watch
gulp.task('watch', function() {
gulp.watch('test/**/*.js', ['jshint']);
gulp.watch('examples/**/*.js', ['jshint']);
gulp.watch('src/**/*.js', ['bundle']);
gulp.watch('test/**/*.js', ['jshint']);
gulp.watch('examples/**/*.js', ['jshint']);
});

// default
Expand Down
14 changes: 11 additions & 3 deletions src/vec2.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ Vec2.prototype = {
this.x = 1;
return this;
}
if (l === 1) {
return this;
}
this.x /= l;
this.y /= l;
return this;
Expand Down Expand Up @@ -55,9 +58,14 @@ Vec2.prototype = {
},
dotProduct: function(vec) {
/*
If A and B are perpendicular (at 90 degrees to each other), the result of the dot product will be zero, because cos(Θ) will be zero.
If the angle between A and B are less than 90 degrees, the dot product will be positive (greater than zero), as cos(Θ) will be positive, and the vector lengths are always positive values.
If the angle between A and B are greater than 90 degrees, the dot product will be negative (less than zero), as cos(Θ) will be negative, and the vector lengths are always positive values
If A and B are perpendicular (at 90 degrees to each other), the result
of the dot product will be zero, because cos(Θ) will be zero.
If the angle between A and B are less than 90 degrees, the dot product
will be positive (greater than zero), as cos(Θ) will be positive, and
the vector lengths are always positive values.
If the angle between A and B are greater than 90 degrees, the dot
product will be negative (less than zero), as cos(Θ) will be negative,
and the vector lengths are always positive values
*/
return this.x * vec.x + this.y * vec.y;
},
Expand Down

0 comments on commit b9be46f

Please sign in to comment.