2011-07-01 06:17:45 -04:00
|
|
|
/*
|
2013-01-28 21:03:27 -05:00
|
|
|
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
2011-07-01 06:17:45 -04:00
|
|
|
* http://paperjs.org/
|
|
|
|
*
|
2013-01-28 21:03:27 -05:00
|
|
|
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
|
2011-07-01 06:17:45 -04:00
|
|
|
* http://lehni.org/ & http://jonathanpuckey.com/
|
|
|
|
*
|
|
|
|
* Distributed under the MIT license. See LICENSE file for details.
|
|
|
|
*
|
|
|
|
* All rights reserved.
|
|
|
|
*/
|
|
|
|
|
2011-02-07 13:28:09 -05:00
|
|
|
module('Point');
|
2011-02-13 11:26:24 -05:00
|
|
|
test('new Point(10, 20)', function() {
|
2011-02-07 13:28:09 -05:00
|
|
|
var point = new Point(10, 20);
|
2013-12-07 10:26:17 -05:00
|
|
|
comparePoints(point, { x: 10, y: 20 });
|
2011-02-07 13:28:09 -05:00
|
|
|
});
|
|
|
|
|
2011-02-13 11:26:24 -05:00
|
|
|
test('new Point([10, 20])', function() {
|
2011-02-07 13:28:09 -05:00
|
|
|
var point = new Point([10, 20]);
|
2013-12-07 10:26:17 -05:00
|
|
|
comparePoints(point, { x: 10, y: 20 });
|
2011-02-07 13:28:09 -05:00
|
|
|
});
|
|
|
|
|
2011-02-13 11:26:24 -05:00
|
|
|
test('new Point({x: 10, y: 20})', function() {
|
2011-02-07 13:28:09 -05:00
|
|
|
var point = new Point({x: 10, y: 20});
|
2013-12-07 10:26:17 -05:00
|
|
|
comparePoints(point, { x: 10, y: 20 });
|
2011-02-07 13:28:09 -05:00
|
|
|
});
|
|
|
|
|
2011-02-13 11:26:24 -05:00
|
|
|
test('new Point(new Size(10, 20))', function() {
|
2011-02-07 13:28:09 -05:00
|
|
|
var point = new Point(new Size(10, 20));
|
2013-12-07 10:26:17 -05:00
|
|
|
comparePoints(point, { x: 10, y: 20 });
|
2011-02-07 13:28:09 -05:00
|
|
|
});
|
|
|
|
|
2011-02-13 11:26:24 -05:00
|
|
|
test('new Point({ width: 10, height: 20})', function() {
|
2011-02-07 13:28:09 -05:00
|
|
|
var point = new Point({width: 10, height: 20});
|
2013-12-07 10:26:17 -05:00
|
|
|
comparePoints(point, { x: 10, y: 20 });
|
2011-02-07 13:28:09 -05:00
|
|
|
});
|
|
|
|
|
2011-05-21 15:01:01 -04:00
|
|
|
test('new Point({ angle: 45, length: 20})', function() {
|
2013-12-07 10:26:17 -05:00
|
|
|
var point = new Point({ angle: 40, length: 20 });
|
|
|
|
comparePoints(point, new Point(15.32089, 12.85575));
|
2011-05-21 15:01:01 -04:00
|
|
|
});
|
|
|
|
|
2011-02-07 13:28:09 -05:00
|
|
|
module('Point vector operations');
|
|
|
|
|
2011-02-13 11:26:24 -05:00
|
|
|
test('normalize(length)', function() {
|
2013-12-07 10:26:17 -05:00
|
|
|
var point = new Point(0, 10).normalize(20);
|
|
|
|
comparePoints(point, { x: 0, y: 20 });
|
2011-02-07 13:28:09 -05:00
|
|
|
});
|
|
|
|
|
2011-02-13 11:26:24 -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;
|
2013-12-07 10:26:17 -05:00
|
|
|
comparePoints(point, { x: 0, y: 20 });
|
2011-02-07 13:28:09 -05:00
|
|
|
});
|
|
|
|
|
2011-02-13 11:26:24 -05:00
|
|
|
test('get angle', function() {
|
2011-02-11 09:02:35 -05:00
|
|
|
var angle = new Point(0, 10).angle;
|
2011-02-07 13:28:09 -05:00
|
|
|
equals(angle, 90);
|
|
|
|
});
|
|
|
|
|
2011-02-13 11:26:24 -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-13 11:26:24 -05:00
|
|
|
test('rotate(degrees)', function() {
|
2011-02-07 13:28:09 -05:00
|
|
|
var point = new Point(100, 50).rotate(90);
|
2013-12-07 10:26:17 -05:00
|
|
|
comparePoints(point, { x: -50, y: 100 });
|
2011-02-07 13:28:09 -05:00
|
|
|
});
|
|
|
|
|
2011-02-13 11:26:24 -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);
|
2013-12-07 10:26:17 -05:00
|
|
|
comparePoints(point, new Point({
|
|
|
|
angle: 92,
|
|
|
|
length: Math.sqrt(10 * 10 + 20 * 20)
|
|
|
|
}));
|
2011-02-07 13:28:09 -05:00
|
|
|
});
|
|
|
|
|
2013-06-23 19:55:14 -04:00
|
|
|
test('set angle & length', function() {
|
2013-06-23 20:22:13 -04:00
|
|
|
var point1 = new Point();
|
|
|
|
point1.length = Math.sqrt(2);
|
|
|
|
point1.angle = -45;
|
2013-06-23 19:55:14 -04:00
|
|
|
|
|
|
|
var point2 = new Point();
|
2013-06-23 20:22:13 -04:00
|
|
|
point2.angle = -45;
|
|
|
|
point2.length = Math.sqrt(2);
|
2013-06-23 19:55:14 -04:00
|
|
|
|
2013-06-23 20:22:13 -04:00
|
|
|
comparePoints(point2, point1);
|
2013-06-23 19:55:14 -04:00
|
|
|
});
|
|
|
|
|
2011-02-11 09:02:35 -05:00
|
|
|
test('getDirectedAngle(point)', function() {
|
2013-12-07 10:28:07 -05:00
|
|
|
equals(function() {
|
|
|
|
return new Point(10, 10).getDirectedAngle(new Point(1, 0));
|
|
|
|
}, -45);
|
2011-06-14 07:44:56 -04:00
|
|
|
|
2013-12-07 10:28:07 -05:00
|
|
|
equals(function() {
|
|
|
|
return new Point(-10, 10).getDirectedAngle(new Point(1, 0));
|
|
|
|
}, -135);
|
2011-06-14 07:44:56 -04:00
|
|
|
|
2013-12-07 10:28:07 -05:00
|
|
|
equals(function() {
|
|
|
|
return new Point(-10, -10).getDirectedAngle(new Point(1, 0));
|
|
|
|
}, 135);
|
2011-06-14 07:44:56 -04:00
|
|
|
|
2013-12-07 10:28:07 -05:00
|
|
|
equals(function() {
|
|
|
|
return new Point(10, -10).getDirectedAngle(new Point(1, 0));
|
|
|
|
}, 45);
|
2013-06-11 22:52:42 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
test('equals()', function() {
|
|
|
|
equals(function() {
|
|
|
|
return new Point(10, 10).equals([10, 10]);
|
|
|
|
}, true);
|
|
|
|
|
|
|
|
equals(function() {
|
|
|
|
return new Point(0, 0).equals({});
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
equals(function() {
|
|
|
|
return new Point(0, 0).equals(null);
|
|
|
|
}, false);
|
|
|
|
});
|