Move simulation test for approximate equality from e18598cd62
to the test setup, so that it can be reused.
Remove unneeded helper variable frome18598cd62
as intended by7778a7b436
by using the set method. This was SVN commit r20467.
This commit is contained in:
parent
05ea4c84d8
commit
a2f7dba96c
@ -73,18 +73,14 @@ Vector2D.prototype.normalize = function()
|
||||
/**
|
||||
* Rotate a radians anti-clockwise
|
||||
*/
|
||||
Vector2D.prototype.rotate = function(a)
|
||||
Vector2D.prototype.rotate = function(angle)
|
||||
{
|
||||
let sin = Math.sin(a);
|
||||
let cos = Math.cos(a);
|
||||
let sin = Math.sin(angle);
|
||||
let cos = Math.cos(angle);
|
||||
|
||||
let x = this.x * cos + this.y * sin;
|
||||
let y = this.y * cos - this.x * sin;
|
||||
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
|
||||
return this;
|
||||
return this.set(
|
||||
this.x * cos + this.y * sin,
|
||||
this.y * cos - this.x * sin);
|
||||
};
|
||||
|
||||
// Numeric 2D info functions (non-mutating)
|
||||
|
@ -69,12 +69,8 @@ var brokenVector = {
|
||||
for (let expectedVector of unitCircle)
|
||||
{
|
||||
let computedVector = new Vector2D(1, 0).rotate(-expectedVector.angle);
|
||||
for (let s of ["x", "y"])
|
||||
if (Math.abs(expectedVector[s] - computedVector[s]) > epsilon)
|
||||
{
|
||||
TS_FAIL("Expected " + uneval(expectedVector) + " got " + uneval(computedVector));
|
||||
break;
|
||||
}
|
||||
TS_ASSERT_EQUALS_APPROX(computedVector.x, expectedVector.x, epsilon);
|
||||
TS_ASSERT_EQUALS_APPROX(computedVector.y, expectedVector.y, epsilon);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -32,6 +32,12 @@ global.TS_ASSERT_EQUALS = function TS_ASSERT_EQUALS(x, y)
|
||||
fail("Expected equal, got "+uneval(x)+" !== "+uneval(y));
|
||||
}
|
||||
|
||||
global.TS_ASSERT_EQUALS_APPROX = function TS_ASSERT_EQUALS_APPROX(x, y, maxDifference)
|
||||
{
|
||||
if (Math.abs(x - y) > maxDifference)
|
||||
fail("Expected almost equal, got " + uneval(x) + " !== " + uneval(y));
|
||||
}
|
||||
|
||||
global.TS_ASSERT_UNEVAL_EQUALS = function TS_ASSERT_UNEVAL_EQUALS(x, y)
|
||||
{
|
||||
if (!(uneval(x) === uneval(y)))
|
||||
|
Loading…
Reference in New Issue
Block a user