forked from paperjs/paper.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPoint.js
More file actions
116 lines (93 loc) · 2.79 KB
/
Copy pathPoint.js
File metadata and controls
116 lines (93 loc) · 2.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/
*
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/
*
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved.
*/
module('Point');
test('new Point(10, 20)', function() {
var point = new Point(10, 20);
equals(point.toString(), '{ x: 10, y: 20 }');
});
test('new Point([10, 20])', function() {
var point = new Point([10, 20]);
equals(point.toString(), '{ x: 10, y: 20 }');
});
test('new Point({x: 10, y: 20})', function() {
var point = new Point({x: 10, y: 20});
equals(point.toString(), '{ x: 10, y: 20 }');
});
test('new Point(new Size(10, 20))', function() {
var point = new Point(new Size(10, 20));
equals(point.toString(), '{ x: 10, y: 20 }');
});
test('new Point({ width: 10, height: 20})', function() {
var point = new Point({width: 10, height: 20});
equals(point.toString(), '{ x: 10, y: 20 }');
});
test('new Point({ angle: 45, length: 20})', function() {
var point = new Point({angle: 40, length: 20});
equals(point.toString(), '{ x: 15.32089, y: 12.85575 }');
});
module('Point vector operations');
test('normalize(length)', function() {
var point = new Point(0, 10).normalize(20)
equals(point.toString(), '{ x: 0, y: 20 }');
});
test('set length', function() {
var point = new Point(0, 10);
point.length = 20;
equals(point.toString(), '{ x: 0, y: 20 }');
});
test('get angle', function() {
var angle = new Point(0, 10).angle;
equals(angle, 90);
});
test('getAngle(point)', function() {
var angle = new Point(0, 10).getAngle([10, 10]);
equals(Math.round(angle), 45);
});
test('rotate(degrees)', function() {
var point = new Point(100, 50).rotate(90);
equals(point.toString(), '{ x: -50, y: 100 }');
});
test('set angle', function() {
var point = new Point(10, 20);
point.angle = 92;
equals(point.angle, 92);
});
test('set angle & length', function() {
var point1 = new Point();
point1.length = Math.sqrt(2);
point1.angle = -45;
var point2 = new Point();
point2.angle = -45;
point2.length = Math.sqrt(2);
comparePoints(point2, point1);
});
test('getDirectedAngle(point)', function() {
var angle = new Point(10, 10).getDirectedAngle(new Point(1, 0));
equals(angle, -45);
var angle = new Point(-10, 10).getDirectedAngle(new Point(1, 0));
equals(angle, -135);
var angle = new Point(-10, -10).getDirectedAngle(new Point(1, 0));
equals(angle, 135);
var angle = new Point(10, -10).getDirectedAngle(new Point(1, 0));
equals(angle, 45);
});
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);
});