Skip to content

Commit dbcbe4e

Browse files
committed
adding support for custom bounds
1 parent a560ff9 commit dbcbe4e

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

js/verlet-js/verlet.js

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,18 @@ var VerletJS = function(width, height, canvas) {
5454
this.draggedEntity = null;
5555
this.selectionRadius = 20;
5656
this.highlightColor = "#4f545c";
57+
58+
this.bounds = function (particle) {
59+
if (particle.pos.y > this.height-1)
60+
particle.pos.y = this.height-1;
61+
62+
if (particle.pos.x < 0)
63+
particle.pos.x = 0;
64+
65+
if (particle.pos.x > this.width-1)
66+
particle.pos.x = this.width-1;
67+
}
68+
5769
var _this = this;
5870

5971
// prevent context menu
@@ -149,16 +161,8 @@ VerletJS.prototype.frame = function(step) {
149161
// bounds checking
150162
for (c in this.composites) {
151163
var particles = this.composites[c].particles;
152-
for (i in particles) {
153-
if (particles[i].pos.y > this.height)
154-
particles[i].pos.y = this.height;
155-
156-
if (particles[i].pos.x < 0)
157-
particles[i].pos.x = 0;
158-
159-
if (particles[i].pos.x > this.width-1)
160-
particles[i].pos.x = this.width-1;
161-
}
164+
for (i in particles)
165+
this.bounds(particles[i]);
162166
}
163167
}
164168

0 commit comments

Comments
 (0)