-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathendless-curve.js
84 lines (64 loc) · 1.92 KB
/
endless-curve.js
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
var GuidedCurvePath = require('./guided-curve');
var EndlessCurve = function(nextCurve) {
this.distanceOffset = 0;
this.nextCurve = nextCurve;
GuidedCurvePath.call(this);
};
EndlessCurve.prototype = Object.create(GuidedCurvePath.prototype);
EndlessCurve.prototype.constructor = EndlessCurve;
var parent = GuidedCurvePath.prototype;
EndlessCurve.prototype.localDistance = function(globalDistance) {
return globalDistance - this.distanceOffset;
};
EndlessCurve.prototype.getLtoUmapping = function(l) {
var len = this.getLengthSafe();
return l / len;
};
EndlessCurve.prototype.fillLength = function(length) {
var p = this.localDistance(length);
var len = this.getLengthSafe();
if (p < len) {
return;
}
var newCurve = this.nextCurve();
this.add(newCurve);
this.fillLength(length);
};
EndlessCurve.prototype.getLengthSafe = function() {
if (!this.curves.length) {
return 0;
}
return this.getLength();
};
EndlessCurve.prototype.removeCurvesBefore = function(position) {
var p = this.localDistance(position);
var lengths = this.getCurveLengths();
var remove = 0;
var distanceOffset = 0;
for (var i = 0; i < lengths.length; i++) {
if (p < lengths[i]) {
break;
}
distanceOffset = lengths[i];
remove += 1;
}
if (remove) {
this.distanceOffset += distanceOffset;
this.curves = this.curves.slice(remove);
this.guideCurvePath.curves = this.guideCurvePath.curves.slice(remove);
this.cacheLengths = null;
}
};
EndlessCurve.prototype.configureStartEnd = function(position, length) {
this.fillLength(position + length);
this.removeCurvesBefore(position);
position = this.localDistance(position);
var len = this.getLengthSafe();
this.uStart = position / len;
this.uLength = length / len;
};
EndlessCurve.prototype.getBasisAt = function(u) {
var u2 = this.uStart + this.uLength * u;
return parent.getBasisAt.call(this, u2);
};
module.exports = EndlessCurve;