@@ -404,64 +404,64 @@ export class OperationService {
404
404
}
405
405
}
406
406
407
- // const reverse : Operation = {
408
- // name: 'reverse section ',
409
- // dx: 'uses the second draft input to reverse the first image. ',
410
- // params: [
411
- // {name: 'left offset',
412
- // min: 0,
413
- // max: 10000,
414
- // value: 0,
415
- // dx: "the amount to offset the added inputs from the left"
416
- // },
417
- // {name: 'top offset',
418
- // min: 0,
419
- // max: 10000,
420
- // value: 0,
421
- // dx: "the amount to offset the overlaying inputs from the top"
422
- // }
423
- // ],
424
- // max_inputs: 100,
425
- // perform: (inputs: Array<Draft>, input_params: Array<number>):Array<Draft> => {
426
-
427
- // if(inputs.length < 1) return [] ;
428
-
429
- // const first: Draft = inputs.shift();
430
-
431
- // const outputs: Array<Draft> = [];
432
-
433
-
434
- // let width: number = utilInstance.getMaxWarps(inputs) + input_params[0];
435
- // let height: number = utilInstance.getMaxWefts(inputs) + input_params[1];
436
- // if(first.warps > width) width = first.warps;
437
- // if(first.wefts > height) height = first.wefts;
438
-
439
- // //initialize the base container with the first draft at 0,0, unset for anythign wider
440
- // const init_draft: Draft = new Draft({wefts: height, warps: width});
407
+ const knockout : Operation = {
408
+ name : 'knockout ' ,
409
+ dx : 'overlays the input drafts. Flips the value of overlapping cells of the same value, effectively knocking out the image of the second draft upon the first ' ,
410
+ params : [
411
+ { name : 'left offset' ,
412
+ min : 0 ,
413
+ max : 10000 ,
414
+ value : 0 ,
415
+ dx : "the amount to offset the added inputs from the left"
416
+ } ,
417
+ { name : 'top offset' ,
418
+ min : 0 ,
419
+ max : 10000 ,
420
+ value : 0 ,
421
+ dx : "the amount to offset the overlaying inputs from the top"
422
+ }
423
+ ] ,
424
+ max_inputs : 100 ,
425
+ perform : ( inputs : Array < Draft > , input_params : Array < number > ) => {
426
+
427
+ if ( inputs . length < 1 ) return Promise . resolve ( [ ] ) ;
428
+
429
+ const first : Draft = inputs . shift ( ) ;
430
+
431
+ const outputs : Array < Draft > = [ ] ;
432
+
433
+
434
+ let width : number = utilInstance . getMaxWarps ( inputs ) + input_params [ 0 ] ;
435
+ let height : number = utilInstance . getMaxWefts ( inputs ) + input_params [ 1 ] ;
436
+ if ( first . warps > width ) width = first . warps ;
437
+ if ( first . wefts > height ) height = first . wefts ;
438
+
439
+ //initialize the base container with the first draft at 0,0, unset for anythign wider
440
+ const init_draft : Draft = new Draft ( { wefts : height , warps : width } ) ;
441
441
442
- // first.pattern.forEach((row, i) => {
443
- // row.forEach((cell, j) => {
444
- // init_draft.pattern[i][j].setHeddle(cell.getHeddle());
445
- // });
446
- // });
447
-
448
- // //now merge in all of the additional inputs offset by the inputs
449
- // const d: Draft = inputs.reduce((acc, input) => {
450
- // input.pattern.forEach((row, i) => {
451
- // row.forEach((cell, j) => {
452
- // //if i or j is less than input params
453
- // const adj_i: number = i+input_params[1];
454
- // const adj_j: number = j+input_params[0];
455
- // acc.pattern[adj_i][adj_j].setHeddle(utilInstance.computeFilter('neq', cell.getHeddle(), acc.pattern[adj_i][adj_j].getHeddle()));
456
- // });
457
- // });
458
- // return acc;
459
-
460
- // }, init_draft);
461
- // outputs.push(d);
462
- // return outputs;
463
- // }
464
- // }
442
+ first . pattern . forEach ( ( row , i ) => {
443
+ row . forEach ( ( cell , j ) => {
444
+ init_draft . pattern [ i ] [ j ] . setHeddle ( cell . getHeddle ( ) ) ;
445
+ } ) ;
446
+ } ) ;
447
+
448
+ //now merge in all of the additional inputs offset by the inputs
449
+ const d : Draft = inputs . reduce ( ( acc , input ) => {
450
+ input . pattern . forEach ( ( row , i ) => {
451
+ row . forEach ( ( cell , j ) => {
452
+ //if i or j is less than input params
453
+ const adj_i : number = i + input_params [ 1 ] ;
454
+ const adj_j : number = j + input_params [ 0 ] ;
455
+ acc . pattern [ adj_i ] [ adj_j ] . setHeddle ( utilInstance . computeFilter ( 'neq' , cell . getHeddle ( ) , acc . pattern [ adj_i ] [ adj_j ] . getHeddle ( ) ) ) ;
456
+ } ) ;
457
+ } ) ;
458
+ return acc ;
459
+
460
+ } , init_draft ) ;
461
+ outputs . push ( d ) ;
462
+ return Promise . resolve ( outputs ) ;
463
+ }
464
+ }
465
465
466
466
const mask : Operation = {
467
467
name : 'mask' ,
@@ -862,6 +862,64 @@ export class OperationService {
862
862
}
863
863
864
864
}
865
+
866
+ const crop : Operation = {
867
+ name : 'crop' ,
868
+ dx : 'crops to a region of the input draft. The crop size and placement is given by the parameters' ,
869
+ params : [
870
+ { name : 'left' ,
871
+ min : 0 ,
872
+ max : 10000 ,
873
+ value : 0 ,
874
+ dx : 'number of pics from the left to start the cut'
875
+ } ,
876
+ { name : 'top' ,
877
+ min : 0 ,
878
+ max : 10000 ,
879
+ value : 0 ,
880
+ dx : 'number of pics from the top to start the cut'
881
+ } ,
882
+ { name : 'width' ,
883
+ min : 1 ,
884
+ max : 10000 ,
885
+ value : 10 ,
886
+ dx : 'total width of cut'
887
+ } ,
888
+ { name : 'height' ,
889
+ min : 1 ,
890
+ max : 10000 ,
891
+ value : 10 ,
892
+ dx : 'height of the cutting box'
893
+ }
894
+ ] ,
895
+ max_inputs : 1 ,
896
+ perform : ( inputs : Array < Draft > , input_params : Array < number > ) => {
897
+
898
+
899
+
900
+ const outputs : Array < Draft > = inputs . map ( input => {
901
+ const new_warps = input_params [ 2 ] ;
902
+ const new_wefts = input_params [ 3 ] ;
903
+
904
+ const d : Draft = new Draft ( { warps : new_warps , wefts : new_wefts } ) ;
905
+
906
+ //unset all cells to default
907
+ d . pattern . forEach ( ( row , i ) => {
908
+ row . forEach ( ( cell , j ) => {
909
+
910
+ if ( ( i + input_params [ 1 ] >= input . pattern . length ) || ( j + input_params [ 0 ] >= input . pattern [ 0 ] . length ) ) cell . setHeddle ( null ) ;
911
+ else cell . setHeddle ( input . pattern [ i + input_params [ 1 ] ] [ j + input_params [ 0 ] ] . getHeddle ( ) ) ;
912
+
913
+ } ) ;
914
+ } ) ;
915
+
916
+ return d ;
917
+ } ) ;
918
+
919
+ return Promise . resolve ( outputs ) ;
920
+ }
921
+
922
+ }
865
923
866
924
const rib : Operation = {
867
925
name : 'rib' ,
@@ -1071,7 +1129,7 @@ export class OperationService {
1071
1129
}
1072
1130
}
1073
1131
1074
- const mirrorx : Operation = {
1132
+ const flipx : Operation = {
1075
1133
name : 'flip horiz' ,
1076
1134
dx : 'generates an output that is the left-right mirror of the input' ,
1077
1135
params : [ ] ,
@@ -1086,7 +1144,7 @@ export class OperationService {
1086
1144
}
1087
1145
}
1088
1146
1089
- const mirrory : Operation = {
1147
+ const flipy : Operation = {
1090
1148
name : 'flip vert' ,
1091
1149
dx : 'generates an output that is the top-bottom mirror of the input' ,
1092
1150
params : [ ] ,
@@ -1408,6 +1466,39 @@ export class OperationService {
1408
1466
1409
1467
}
1410
1468
1469
+ const jointop : Operation = {
1470
+ name : 'join top' ,
1471
+ dx : 'attaches inputs toether into one draft in a column orientation' ,
1472
+ params : [ ] ,
1473
+ max_inputs : 100 ,
1474
+ perform : ( inputs : Array < Draft > , input_params : Array < number > ) => {
1475
+
1476
+ const total :number = inputs . reduce ( ( acc , draft ) => {
1477
+ return acc + draft . wefts ;
1478
+ } , 0 ) ;
1479
+
1480
+ const max_warps :number = utilInstance . getMaxWarps ( inputs ) ;
1481
+
1482
+ const combined : { d : Draft , n : number } = inputs . reduce ( ( acc , input , ndx ) => {
1483
+
1484
+ input . pattern . forEach ( ( row , i ) => {
1485
+ row . forEach ( ( cell , j ) => {
1486
+ acc . d . pattern [ acc . n + i ] [ j ] . setHeddle ( cell . getHeddle ( ) ) ;
1487
+ } ) ;
1488
+ } ) ;
1489
+
1490
+ acc . n = input . pattern . length ;
1491
+ return acc ;
1492
+
1493
+ } , { d : new Draft ( { warps : max_warps , wefts : total } ) , n : 0 } ) ;
1494
+
1495
+
1496
+ return Promise . resolve ( [ combined . d ] ) ;
1497
+
1498
+ }
1499
+ }
1500
+
1501
+
1411
1502
const joinleft : Operation = {
1412
1503
name : 'join left' ,
1413
1504
dx : 'attaches inputs toether into one draft with each iniput side by side' ,
@@ -1544,15 +1635,16 @@ export class OperationService {
1544
1635
this . ops . push ( interlace ) ;
1545
1636
this . ops . push ( invert ) ;
1546
1637
this . ops . push ( replicate ) ;
1547
- this . ops . push ( mirrorx ) ;
1548
- this . ops . push ( mirrory ) ;
1638
+ this . ops . push ( flipx ) ;
1639
+ this . ops . push ( flipy ) ;
1549
1640
this . ops . push ( shiftx ) ;
1550
1641
this . ops . push ( shifty ) ;
1551
1642
this . ops . push ( layer ) ;
1552
1643
this . ops . push ( selvedge ) ;
1553
1644
this . ops . push ( bindweftfloats ) ;
1554
1645
this . ops . push ( bindwarpfloats ) ;
1555
1646
this . ops . push ( joinleft ) ;
1647
+ this . ops . push ( jointop ) ;
1556
1648
this . ops . push ( slope ) ;
1557
1649
this . ops . push ( tile ) ;
1558
1650
this . ops . push ( stretch ) ;
@@ -1569,7 +1661,8 @@ export class OperationService {
1569
1661
this . ops . push ( germanify ) ;
1570
1662
this . ops . push ( crackleify ) ;
1571
1663
this . ops . push ( variants ) ;
1572
- // this.ops.push(reverse);
1664
+ this . ops . push ( knockout ) ;
1665
+ this . ops . push ( crop ) ;
1573
1666
1574
1667
1575
1668
//** Give it a classification here */
@@ -1586,12 +1679,12 @@ export class OperationService {
1586
1679
1587
1680
this . classification . push (
1588
1681
{ category : 'transformations' ,
1589
- ops : [ fill , invert , mirrorx , mirrory , shiftx , shifty , rotate , slope , stretch , resize , margin ] }
1682
+ ops : [ fill , invert , flipx , flipy , shiftx , shifty , rotate , slope , stretch , resize , margin , crop ] }
1590
1683
) ;
1591
1684
1592
1685
this . classification . push (
1593
1686
{ category : 'compose' ,
1594
- ops : [ replicate , interlace , layer , tile , joinleft , selvedge , atop , overlay , mask , bindweftfloats , bindwarpfloats ] }
1687
+ ops : [ replicate , interlace , layer , tile , joinleft , jointop , selvedge , atop , overlay , mask , knockout , bindweftfloats , bindwarpfloats ] }
1595
1688
) ;
1596
1689
1597
1690
this . classification . push (
0 commit comments