forked from paperjs/paper.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCurve.js
More file actions
119 lines (102 loc) · 2.77 KB
/
Copy pathCurve.js
File metadata and controls
119 lines (102 loc) · 2.77 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
117
118
119
/*
* 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('Curve');
test('Curve#getPointAt()', function() {
var curve = new Path.Circle({
center: [100, 100],
radius: 100
}).getFirstCurve();
var points = [
[0, new Point(0, 100)],
[0.25, new Point(7.8585, 61.07549)],
[0.5, new Point(29.28932, 29.28932)],
[0.75, new Point(61.07549, 7.8585)],
[1, new Point(100, 0)]
];
for (var i = 0; i < points.length; i++) {
var entry = points[i];
comparePoints(curve.getPointAt(entry[0], true), entry[1],
'curve.getPointAt(' + entry[0] + ', true);');
}
});
test('Curve#getTangentAt()', function() {
var curve = new Path.Circle({
center: [100, 100],
radius: 100
}).getFirstCurve();
var tangents = [
[0, new Point(0, -165.68542 )],
[0.25, new Point(60.7233, -143.56602)],
[0.5, new Point(108.57864, -108.57864)],
[0.75, new Point(143.56602, -60.7233)],
[1, new Point(165.68542, 0)]
];
for (var i = 0; i < tangents.length; i++) {
var entry = tangents[i];
comparePoints(curve.getTangentAt(entry[0], true), entry[1],
'curve.getTangentAt(' + entry[0] + ', true);');
}
});
test('Curve#getNormalAt()', function() {
var curve = new Path.Circle({
center: [100, 100],
radius: 100
}).getFirstCurve();
var normals = [
[0, new Point(-165.68542, 0)],
[0.25, new Point(-143.56602, -60.7233)],
[0.5, new Point(-108.57864, -108.57864)],
[0.75, new Point(-60.7233, -143.56602)],
[1, new Point(0, -165.68542)]
];
for (var i = 0; i < normals.length; i++) {
var entry = normals[i];
comparePoints(curve.getNormalAt(entry[0], true), entry[1],
'curve.getNormalAt(' + entry[0] + ', true);');
}
});
test('Curve#getCurvatureAt()', function() {
var curve = new Path.Circle({
center: [100, 100],
radius: 100
}).getFirstCurve();
var curvatures = [
[0, 0.009785533905932729],
[0.25, 0.010062133221584524],
[0.5, 0.009937576453041297],
[0.75, 0.010062133221584524],
[1, 0.009785533905932727]
];
for (var i = 0; i < curvatures.length; i++) {
var entry = curvatures[i];
compareNumbers(curve.getCurvatureAt(entry[0], true), entry[1],
'curve.getCurvatureAt(' + entry[0] + ', true);');
}
});
test('Curve#getCurvatureAt()', function() {
var curve = new Path.Line({
from: [100, 100],
to: [200, 200],
}).getFirstCurve();
var curvatures = [
[0, 0],
[0.25, 0],
[0.5, 0],
[0.75, 0],
[1, 0]
];
for (var i = 0; i < curvatures.length; i++) {
var entry = curvatures[i];
compareNumbers(curve.getCurvatureAt(entry[0], true), entry[1],
'curve.getCurvatureAt(' + entry[0] + ', true);');
}
});