Skip to content

Commit

Permalink
Fix application of PlaneConstraint with parallel segments
Browse files Browse the repository at this point in the history
  • Loading branch information
milcktoast committed Oct 11, 2014
1 parent 85b70f5 commit 37b913a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/constraints/PlaneConstraint.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ PlaneConstraint.prototype._calculateNormal = function (index, p0) {

// AB and BC are parallel
if (!nLenSq) {
p0[bix] += 0.1;
p0[aix] += 0.1;
p0[biy] += 0.1;
p0[biz] += 0.1;
p0[cix] -= 0.1;

this._hasNormal = false;
return;
Expand Down
23 changes: 18 additions & 5 deletions test/constraints/PlaneConstraint.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ test('Creation', function () {
'Should create indices from int array.');
});

test('Application', function () {
function testPlane(v0, v1, v2) {
var system = ParticleSystem.create(10, 10);
var singleIndex = 3;
var single = PlaneConstraint.create(0, 1, 2, singleIndex);
Expand All @@ -33,18 +33,31 @@ test('Application', function () {
return 10;
}

system.setPosition(0, [25, 15, 10]);
system.setPosition(1, [10, 10, 10]);
system.setPosition(2, [50, 30, 10]);
system.setPosition(0, v0);
system.setPosition(1, v1);
system.setPosition(2, v2);

system.addConstraint(single);
system.addConstraint(many);
system.tick(1);
system.tick(20);

Test.assert.closeArray(many.bufferVec3, [0, 0, 1], 0.1,
'Should cache plane normal vector.');
Test.assert.close(getZ(singleIndex), 10, 0.1,
'Should constrain single set of particles to plane.');
Test.assert.closeArray(manyIndices.map(getZ), manyIndices.map(returnTen), 0.1,
'Should constrain multiple sets of particles to plane.');
}

test('Application', function () {
testPlane(
[25, 15, 10],
[10, 10, 10],
[50, 30, 10]);

// Plane with parallel segments
testPlane(
[5, 5, 10],
[10, 10, 10],
[15, 15, 10]);
});

0 comments on commit 37b913a

Please sign in to comment.