2011-02-07 13:28:09 -05:00
|
|
|
module('Point');
|
|
|
|
test('new Point(10, 20)', function(){
|
|
|
|
var point = new Point(10, 20);
|
|
|
|
equals(point.x, 10);
|
|
|
|
equals(point.y, 20);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('new Point([10, 20])', function(){
|
|
|
|
var point = new Point([10, 20]);
|
|
|
|
equals(point.x, 10);
|
|
|
|
equals(point.y, 20);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('new Point({x: 10, y: 20})', function(){
|
|
|
|
var point = new Point({x: 10, y: 20});
|
|
|
|
equals(point.x, 10);
|
|
|
|
equals(point.y, 20);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('new Point(new Size(10, 20))', function(){
|
|
|
|
var point = new Point(new Size(10, 20));
|
|
|
|
equals(point.x, 10);
|
|
|
|
equals(point.y, 20);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('new Point({ width: 10, height: 20})', function(){
|
|
|
|
var point = new Point({width: 10, height: 20});
|
|
|
|
equals(point.x, 10);
|
|
|
|
equals(point.y, 20);
|
|
|
|
});
|
|
|
|
|
|
|
|
module('Point vector operations');
|
|
|
|
|
2011-02-11 09:02:35 -05:00
|
|
|
test('normalize(length)', function(){
|
2011-02-07 13:28:09 -05:00
|
|
|
var point = new Point(0, 10).normalize(20)
|
|
|
|
equals(point.x, 0);
|
|
|
|
equals(point.y, 20);
|
|
|
|
});
|
|
|
|
|
2011-02-11 09:02:35 -05:00
|
|
|
test('set length', function(){
|
2011-02-07 13:28:09 -05:00
|
|
|
var point = new Point(0, 10);
|
2011-02-11 09:02:35 -05:00
|
|
|
point.length = 20;
|
2011-02-07 13:28:09 -05:00
|
|
|
equals(point.x, 0);
|
|
|
|
equals(point.y, 20);
|
|
|
|
});
|
|
|
|
|
2011-02-11 09:02:35 -05:00
|
|
|
test('get angle', function(){
|
|
|
|
var angle = new Point(0, 10).angle;
|
2011-02-07 13:28:09 -05:00
|
|
|
equals(angle, 90);
|
|
|
|
});
|
|
|
|
|
2011-02-11 09:02:35 -05:00
|
|
|
test('getAngle(point)', function(){
|
2011-02-07 13:28:09 -05:00
|
|
|
var angle = new Point(0, 10).getAngle([10, 10]);
|
|
|
|
equals(Math.round(angle), 45);
|
|
|
|
});
|
|
|
|
|
2011-02-11 09:02:35 -05:00
|
|
|
test('rotate(degrees)', function(){
|
2011-02-07 13:28:09 -05:00
|
|
|
var point = new Point(100, 50).rotate(90);
|
|
|
|
equals(Math.round(point.x), -50);
|
|
|
|
equals(Math.round(point.y), 100);
|
|
|
|
});
|
|
|
|
|
2011-02-11 09:02:35 -05:00
|
|
|
test('set angle', function(){
|
2011-02-07 13:28:09 -05:00
|
|
|
var point = new Point(10, 20);
|
2011-02-11 09:02:35 -05:00
|
|
|
point.angle = 92;
|
|
|
|
equals(point.angle, 92);
|
2011-02-07 13:28:09 -05:00
|
|
|
});
|
|
|
|
|
2011-02-11 09:02:35 -05:00
|
|
|
test('getDirectedAngle(point)', function() {
|
2011-02-07 13:28:09 -05:00
|
|
|
var angle = new Point().getDirectedAngle(new Point(10, 10));
|
|
|
|
equals(angle, -45);
|
|
|
|
});
|