-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
1557 lines (1347 loc) · 31.9 KB
/
index.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
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**!
* plasm-fun
* functional plasm
*
* @copyright 2013 Enrico Marino and Federico Spini
* @license MIT
*/
/**
* Library dependencies.
*/
var f = require('f');
var plasm = require('plasm');
var globalize = require('globalize');
/**
* Expose `fun`
*/
module.exports = fun;
/**
* fun
*
* @return {Function} fun
* @api public
*/
function fun (id) {
for (var p in f) {
fun[p.toUpperCase()] = f[p];
}
fun.plasm = plasm;
fun.viewer = plasm.Viewer(id);
return fun;
}
/**
* globalize
* Globalize fun functions
*
* @return {function} fun
* @api public
*/
fun.globalize = function () {
globalize(fun);
return fun;
};
/**
* DRAW
*
* @param {plasm.Model|plasm.Struct} object to draw
* @api public
*/
fun.DRAW = function (object) {
if (!(object instanceof plasm.Model) &&
!(object instanceof plasm.Struct)) {
return;
}
object.draw(fun.viewer);
return object;
};
/**
* CANCEL
*
* @param {plasm.Model|plasm.Struct} object
* @return {plasm.Model|plasm.Struct} object
* @api public
*/
fun.CANCEL = function (object) {
if (!(object instanceof plasm.Model) &&
!(object instanceof plasm.Struct)) {
return;
}
return object.cancel();
};
/**
* K
*
* @param {Object} an object to be stored and returned
* @return {Function}
* @return {Object} the Object passed as first parameter
* @api public
*/
var K =
fun.K = function (constObject) {
return function () {
return constObject;
};
};
/**
* R
*
* @param {Array|Uint32Array} dims
* @return {Function}
* @param {Number|Array|Uint32Array} angle
* @return {Function}
* @param {plasm.Model|plasm.Struct} object
* @return {plasm.Model|plasm.Struct} rotated clone of object
* @api public
*/
var R =
fun.R =
fun.ROTATE = function (dims) {
return function (angle) {
return function (object) {
return object.clone().rotate(dims, angle);
};
};
};
/**
* S
*
* @param {Array|Uint32Array} dims
* @return {Function}
* @param {Number} values
* @return {Function}
* @param {plasm.Model|plasm.Struct} object
* @return {plasm.Model|plasm.Struct} scaled clone of object
* @api public
*/
var S =
fun.S =
fun.SCALE = function (dims) {
return function (values) {
return function (object) {
return object.clone().scale(dims, values);
};
};
};
/**
* T
*
* @param {Array|Uint32Array} dims
* @return {Function}
* @param {Number} values
* @return {Function}
* @param {plasm.Model|plasm.Struct} model
* @return {plasm.Model|plasm.Struct} translated clone of object
* @api public
*/
var T =
fun.T =
fun.TRANSLATE = function (dims) {
return function (values) {
return function (object) {
return object.clone().translate(dims, values);
};
};
};
/**
* STRUCT
*
* @param {Array} items
* @return {plasm.Model}
* @api public
*/
fun.STRUCT = function (items) {
var transformations = function (o) {return o;};
var objects = [];
// var temp = [];
items.forEach(function (item) {
if (!(item instanceof plasm.Model) &&
!(item instanceof plasm.Struct)) {
transformations = COMP2([transformations, item]);
} else {
// temp.push(APPLY([transformations, item]).clone());
objects.push(APPLY([transformations, item]));
}
});
// return new plasm.Struct(objects, temp);
return new plasm.Struct(objects);
};
/**
* Map.
*
* Map `domain` by `mapping` function.
*
* @example
*
* var domain = DOMAIN([[0,1]],[0,2*PI]);
* var mapping = function (v) { return [SIN(v[0]), COS(v[1])]; });
* var model = MAP(mapping)(domain);
* DRAW(model);
*
* @example
*
* var domain = DOMAIN([[0,1]],[0,2*PI]);
* var mapping = [
* function (v) { return SIN(v[0]); },
* function (v) { return COS(v[1]); }
* ]);
* var model = MAP(mapping)(domain)
* DRAW(model);
*
* @param {Function} mapping
* @return {Function}
* @param {plasm.Model} domain
* @return {plasm.Model}
* @api public
*/
fun.MAP = function (mapping) {
return function (domain) {
return domain.map(mapping);
};
};
/**
* extrude
*
* @param {Array|Float32Array} hlist a list of positive numbers
* or an alternation of positive and negative numbers
* @return {Function}
* @param {plasm.Model|plasm.Struct} object to extrude
* @return {plasm.Model|plasm.Struct} extrusion
* @api private
*/
var EXTRUDE =
fun.EXTRUDE = function (hlist) {
return function (object) {
return object.extrude(hlist);
};
};
/**
* EXPLODE
*
* @param {Array|Float32Array} values
* @return {Function}
* @param {plasm.Model} model
* @return {plasm.Model} exploded clone of model
* @api public
*/
var EXPLODE =
fun.EXPLODE = function (values) {
return function (model) {
return model.explode(values);
};
};
/**
* SKELETON
*
* @param {Number} dim
* @return {Function}
* @param {plasm.Model} model
* @return {plasm.Model} skeleton
* @api public
*/
var SKELETON =
fun.SKELETON = function (dim) {
return function (model) {
return model.skeleton(dim);
};
};
/**
* BOUNDARY
*
* @param {plasm.Model} model
* @return {plasm.Model} boundary
* @api public
*/
var BOUNDARY =
fun.BOUNDARY = function (model) {
return model.boundary();
};
/**
* COLOR
*
* Color.
*
* @param {Array} rgb rgb
* @param {Number} [rgb[0] = 0] r
* @param {Number} [rgb[1] = 0] g
* @param {Number} [rgb[2] = 0] b
* @param {Number} [rgb[3] = 1] a
* @return {Function}
* @param {plasm.Model | plasm.Struct} object
* @return {plasm.Model | plasm.Struct} colored object
* @api public
*/
var COLOR =
fun.COLOR = function (rgba) {
return function (object) {
return object.clone().color(rgba);
};
};
/**
* SHOW
*
* @param {plasm.Model | plasm.Struct} model to show
* @return {plasm.Model | plasm.Struct} model
* @api public
*/
var SHOW =
fun.SHOW = function (object) {
object.show();
};
/**
* HIDE
*
* @return {plasm.Model | plasm.Struct} for chaining
* @api public
*/
var HIDE =
fun.HIDE = function (object) {
object.hide();
};
/**
* SIMPLICIAL_COMPLEX
*
* @param {Array|Float32Array} points
* @return {Function}
* @param {Array|Uint32Array} cells
* @return {plasm.Model} simplicial cells
* @api public
*/
var SIMPLICIAL_COMPLEX =
fun.SIMPLICIAL_COMPLEX = function (points) {
return function (cells) {
return plasm.SimplicialComplex(points, cells);
};
};
/**
* SIMPLEX
*
* @param {number} d
* @return {plasm.Model} a simplex
* @api public
*/
var SIMPLEX =
fun.SIMPLEX = function (d) {
return plasm.geometries.simplex(d);
};
/**
* POLYLINE
*
* @param {Array} points
* @return {plasm.Model} a polyline
* @api public
*/
var POLYLINE =
fun.POLYLINE = function (points) {
return plasm.geometries.polyline(points);
};
/**
* POLYPOINT
*
* @param {Array} points
* @return {plasm.Model} a polypoint
* @api public
*/
var POLYPOINT =
fun.POLYPOINT = function (points) {
return plasm.geometries.polypoint(points);
};
/**
* SIMPLEX_GRID
*
* @param {Array} quotesList is a list of hlist made by positive numbers
* or made by an alternation of positive and negative numbers
* @return {plasm.Model} a grid of simplexes
* @api public
*/
var SIMPLEX_GRID =
fun.SIMPLEX_GRID = function (quotes) {
return plasm.geometries.simplexGrid(quotes);
};
/**
* CUBE
*
* @param {Number} dim
* @return {plasm.Model} a dim-dimendional cube
* @api public
*/
var CUBE =
fun.CUBE = function (d) {
return plasm.geometries.cube(d);
};
/**
* CUBOID
*
* @param {Array} sides
* @return {plasm.Model} a cuboidal simplicial complex
* @api public
*/
var CUBOID =
fun.CUBOID = function (sides) {
return plasm.geometries.cuboid(sides);
};
/**
* INTERVALS
*
* @param {Number} tip
* @return {Function}
* @param {Number} n
* @return {plasm.Model} intervals
* @api public
*/
var INTERVALS =
fun.INTERVALS = function (tip) {
return function (n) {
return plasm.geometries.intervals(tip, n);
};
};
/**
* DOMAIN
*
* @param {Array} ends
* @return {Function}
* @param {Number} ns
* @return {plasm.Model} domain
* @return {plasm.Model} domain
* @api public
*/
var DOMAIN =
fun.DOMAIN = function (ends) {
return function (ns) {
return plasm.geometries.domain(ends, ns);
};
};
/**
* PROD
* cartesian products
*
* @param {Array} array
* @param {plasm.Model} [array[0]] model1
* @param {plasm.Model} [array[1]] model2
* @return {plasm.Model} result
*/
var PROD1x1 =
fun.PROD1x1 = function (array) {
return array[0].prod1x1(array[1]);
};
var PROD1x2 =
fun.PROD1x2 = function (array) {
return array[0].prod1x2(array[1]);
};
var PROD2x1 =
fun.PROD2x1 = function (array) {
return array[0].prod2x1(array[1]);
};
/**
* CIRCLE
*
* @param {Number} r radius
* @return {Function}
* @param {Number} n subdivisions
* @return {plasm.Model} a circle
* @api public
*/
var CIRCLE =
fun.CIRCLE = function (r) {
var r = r || 1;
return function (n) {
return plasm.geometries.circle(r, n);
};
};
/**
* DISK
*
* @param {Number} r radius
* @return {Function}
* @param {Array} divs subdivisions
* @param {Number} [divs[0]] slices
* @param {Number} [divs[1]] stacks
* @return {plasm.Model} a disk
* @api public
*/
var DISK =
fun.DISK = function (r) {
var r = r || 1;
return function (divs) {
var divs = divs || [];
var slices = divs[0] || 24;
var stacks = divs[1] || 3;
return plasm.geometries.disk(r, slices, stacks);
};
};
/**
* CYLSURFACE
*
* @param {Array} dims
* @param {Number} [dims[0]=1] radius
* @param {Number} [dims[1]=1] height
* @return {Function}
* @param {Array} divs
* @param {Number} [divs[0]=16] slices
* @param {Number} [divs[1]=2] stacks
* @return {plasm.Model} a cylindrical surface
* @api public
*/
var CYL_SURFACE =
fun.CYL_SURFACE = function (dims) {
var dims = dims || [];
var r = dims[0] || 1;
var h = dims[1] || 1;
return function (divs) {
var divs = divs || [];
var slices = divs[0] || 12;
var stacks = divs[1] || 8;
return plasm.geometries.cylinderSurface(r, h, slices, stacks);
};
};
/**
* TORUS_SURFACE
*
* @param {Array} dims
* @param {Number} [dims[0]=0.1] r min
* @param {Number} [dims[1]=0.9] r max
* @return {Function}
* @param {Array} divs
* @param {Number} [divs[0]=12] slices
* @param {Number} [divs[1]=8] stacks
* @return {plasm.Model} a torus surface
* @api public
*/
var TORUS_SURFACE =
fun.TORUS_SURFACE = function (dims) {
var dims = dims || [];
var r_min = dims[0] || 1.0;
var r_max = dims[1] || 1.9;
return function (divs) {
var divs = divs || [];
var n = divs[0] || 12;
var m = divs[1] || 12;
return plasm.geometries.torusSurface(r_min, r_max, n, m);
};
};
/**
* TORUS_SOLID
*
* @param {Array} dims
* @param {Number} [dims[0]=0.1] r min
* @param {Number} [dims[1]=0.9] r max
* @return {Function}
* @param {Array} divs
* @param {Number} [divs[0]=12] n
* @param {Number} [divs[1]=8] m
* @param {Number} [divs[1]=8] p
* @return {plasm.Model} a torus surface
* @api public
*/
var TORUS_SOLID =
fun.TORUS_SOLID = function (dims) {
var dims = dims || [];
var r_min = dims[0] || 0.1;
var r_max = dims[1] || 0.9;
return function (divs) {
var divs = divs || [];
var n = divs[0] || 12;
var m = divs[1] || 8;
var q = divs[2] || 8;
return plasm.geometries.torusSolid(r_min, r_max, n, m, q);
};
};
/**
* TRIANGLE_STRIP
*
* @param {Array} points
* @return {plasm.Model} triangle strip
* @api public
*/
var TRIANGLE_STRIP =
fun.TRIANGLE_STRIP = function (points) {
return plasm.geometries.triangleStrip(points);
};
/**
* TRIANGLEFAN
*
* @param {Array} points
* @return {plasm.Model} triangle strip
* @api public
*/
var TRIANGLE_FAN =
fun.TRIANGLE_FAN = function (points) {
return plasm.geometries.triangleFan(points);
};
/**
* HELIX
*
* @param {Number} [r=1] r
* @param {Number} [pitch=1] pitch
* @param {Number} [n=24] n
* @param {Number} [turns=1] turns
* @return {plasm.Model} helix
* @api public
*/
var HELIX =
fun.HELIX = function (r, pitch, n, turns) {
return plasm.geometries.helix(r, pitch, n, turns);
};
/**
* CUBIC_HERMITE
*
* @param {Function} sel
* @return {Function}
* @param {Array} args
* @return {Function}
* @param {Array} point
* @return {Funciton}
* @api public
*/
var CUBIC_HERMITE =
fun.CUBIC_HERMITE = function (sel) {
return function (args) {
var p1Fn = args[0];
var p2Fn = args[1];
var s1Fn = args[2];
var s2Fn = args[3];
return function (point) {
var u = sel(point);
var u2 = u * u;
var u3 = u2 * u;
var p1 = p1Fn instanceof Function ? p1Fn(point) : p1Fn;
var p2 = p2Fn instanceof Function ? p2Fn(point) : p2Fn;
var s1 = s1Fn instanceof Function ? s1Fn(point) : s1Fn;
var s2 = s2Fn instanceof Function ? s2Fn(point) : s2Fn;
var rn = p1.length;
var mapped = new Array(rn);
var i;
for (i = 0; i < rn; i += 1) {
mapped[i] = (2*u3-3*u2+1)*p1[i] + (-2*u3+3*u2)*p2[i]+(u3-2*u2+u)*s1[i]+(u3-u2)*s2[i];
}
return mapped;
};
};
};
/**
* BEZIER
*
* @param {Function} sel
* @return {Function}
* @param {Array} args
* @return {Function}
* @param {Array} point
* @return {Funciton}
* @api public
*/
var BEZIER =
fun.BEZIER = function (sel) {
return function (args) {
var n = args.length - 1;
var controldataFn = args;
return function (point) {
var t = sel(point);
var controldata = new Array(n+1);
var mapped;
var rn;
var weight;
var crtldata;
var i, k;
for (i = 0; i <= n; i += 1) {
crtldata = controldataFn[i];
controldata[i] = crtldata instanceof Function ? crtldata(point) : crtldata;
}
rn = controldata[0].length;
mapped = new Array(rn);
for (i = 0; i < rn; i += 1) {
mapped[i] = 0.0;
}
for (i = 0; i <= n; i += 1) {
weight = CHOOSE([n,i]) * POW([1-t,n-i]) * POW([t,i]);
for (k = 0; k < rn; k += 1) {
mapped[k] += weight * controldata[i][k];
}
}
return mapped;
};
};
};
/**
* CUBIC_UBSPLINE
*
* @param {Function} domain
* @return {Function}
* @param {Array} args
* @api public
*/
var CUBIC_UBSPLINE =
fun.CUBIC_UBSPLINE = function (domain) {
return function (args) {
var q1Fn = args[0];
var q2Fn = args[1];
var q3Fn = args[2];
var q4Fn = args[3];
return MAP(function (point) {
var u = S0(point);
var u2 = u * u;
var u3 = u2 * u;
var rn;
var mapped;
var i;
var q1 = q1Fn instanceof Function ? q1Fn(point) : q1Fn;
var q2 = q2Fn instanceof Function ? q2Fn(point) : q2Fn;
var q3 = q3Fn instanceof Function ? q3Fn(point) : q3Fn;
var q4 = q4Fn instanceof Function ? q4Fn(point) : q4Fn;
rn = q1.length;
mapped = new Array(rn);
for (i = 0; i < rn; i +=1) {
mapped[i] = (1.0/6.0) * ( (-u3+3*u2-3*u+1)*q1[i] + (3*u3-6*u2+4)*q2[i]+ (-3*u3+3*u2+3*u+1)*q3[i] + (u3)*q4[i]);
}
return mapped;
})(domain);
};
};
/**
* CUBIC_CARDINAL
*
* @param {Function} domain
* @param {Number} [h=1]
* @return {Function}
* @param {Array} args
* @api public
*/
var CUBIC_CARDINAL =
fun.CUBIC_CARDINAL = function (domain, h) {
var h = h !== undefined ? h : 1;
return function (args) {
var q1Fn = args[0];
var q2Fn = args[1];
var q3Fn = args[2];
var q4Fn = args[3];
return MAP(function (point) {
var u = S0(point);
var u2 = u * u;
var u3 = u2 * u;
var rn;
var mapped;
var i;
var q1 = q1Fn instanceof Function ? q1Fn(point) : q1Fn;
var q2 = q2Fn instanceof Function ? q2Fn(point) : q2Fn;
var q3 = q3Fn instanceof Function ? q3Fn(point) : q3Fn;
var q4 = q4Fn instanceof Function ? q4Fn(point) : q4Fn;
rn = q1.length;
mapped = new Array(rn);
for (i = 0; i < rn; i +=1) {
mapped[i] = (-h*u3+2*h*u2-h*u)*q1[i] +((2-h)*u3+(h-3)*u2+1)*q2[i] + ((h-2)*u3+(3-2*h)*u2+h*u)*q3[i] + (h*u3-h*u2)*q4[i];
}
return mapped;
})(domain);
};
};
/**
* SPLINE
*
* @param {Function} curve
* @return {Function}
* @param {Array} points
* @return {plasm.Struct}
* @api public
*/
var SPLINE =
fun.SPLINE = function (curve) {
return function (points) {
var segments = [];
var length = points.length;
var tip = length -4 + 1;
var slice;
var i;
for (i = 0; i < tip; i += 1) {
slice = points.slice(i,i+4);
segments.push(curve(slice));
}
return STRUCT(segments);
};
};
/**
* DE_BOORD
* Cox and De Boord coefficients
*
* @api private
*/
var DE_BOORD =
fun.DE_BOORD = function (T, i, k, t, n) {
var tmin = T[k-1];
var tmax = T[n+1];
var ret, num1, div1, num2, div2;
// DE_BOORDi1(t)
if (k === 1) {
if ((t >= T[i] && t < T[i+1]) ||
(t === tmax && t >= T[i] && t <= T[i+1])) {
return 1;
} else {
return 0;
}
}
// DE_BOORDik(t)
ret = 0;
num1 = t-T[i];
div1 = T[i+k-1]-T[i];
if (div1 !== 0) {
ret += (num1/div1) * DE_BOORD(T,i,k-1,t,n);
}
num2 = T[i+k]-t;
div2 = T[i+k]-T[i+1];
if (div2 !== 0) {
ret += (num2/div2) * DE_BOORD(T,i+1,k-1,t,n);
}
return ret;
};
/**
* BSPLINE
*
* @param {Number} degree
* @return {Function}
* @param {Array} knots
* @return {Function}
* @param {Array} controls
* @return {Funciton}
* @api public
*/
var BSPLINE =
fun.BSPLINE = function (degree) {
return function (knots) {
return function (controls) {
var n = controls.length - 1;
var m = knots.length -1;
var k = degree + 1;
// see http://www.na.iac.cnr.it/~bdv/cagd/spline/B-spline/bspline-curve.html
if (knots.length !== (n+k+1)) {
throw "Invalid point/knots/degree for bspline!";
}
return function (point) {
var t = point[0];
var points = new Array(n);
var rn;
var control;
var mapped;
var coeff;
var i, j;
for (i = 0; i <= n; i += 1) {
control = controls[i];
points[i] = control instanceof Function ? control(point) : control;
}
rn = points[0].length;
mapped = new Array(rn);
for (i = 0; i < rn; i += 1) {
mapped[i] = 0.0;
}
for (i = 0; i <= n; i += 1) {
coeff = DE_BOORD(knots,i,k,t,n);
for (j = 0; j < rn; j += 1) {
mapped[j] += points[i][j] * coeff;
}
}
return mapped;
};
};
};
};
/**
* NUBSPLINE
*
* @param {Number} degree
* @param {Number} [totpoints=80]
* @return {Function}
* @param {Array} knots
* @return {Function}
* @param {Array} point
* @return {plasm.Model}
* @api public
*/
var NUBSPLINE =
fun.NUBSPLINE = function (degree, totpoints) {
var totpoints = totpoints !== undefined ? totpoints : 80;
return function (knots) {
return function (points) {
var m = knots.length;
var tmin = SMALLEST(knots);
var tmax = BIGGEST(knots);
var tsiz = tmax - tmin;
var size = totpoints - 1;
var v = new Array(size + 1);