@@ -404,64 +404,64 @@ export class OperationService {
404404 }
405405 }
406406
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 } ) ;
441441
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+ }
465465
466466 const mask : Operation = {
467467 name : 'mask' ,
@@ -862,6 +862,64 @@ export class OperationService {
862862 }
863863
864864 }
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+ }
865923
866924 const rib : Operation = {
867925 name : 'rib' ,
@@ -1071,7 +1129,7 @@ export class OperationService {
10711129 }
10721130 }
10731131
1074- const mirrorx : Operation = {
1132+ const flipx : Operation = {
10751133 name : 'flip horiz' ,
10761134 dx : 'generates an output that is the left-right mirror of the input' ,
10771135 params : [ ] ,
@@ -1086,7 +1144,7 @@ export class OperationService {
10861144 }
10871145 }
10881146
1089- const mirrory : Operation = {
1147+ const flipy : Operation = {
10901148 name : 'flip vert' ,
10911149 dx : 'generates an output that is the top-bottom mirror of the input' ,
10921150 params : [ ] ,
@@ -1408,6 +1466,39 @@ export class OperationService {
14081466
14091467 }
14101468
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+
14111502 const joinleft : Operation = {
14121503 name : 'join left' ,
14131504 dx : 'attaches inputs toether into one draft with each iniput side by side' ,
@@ -1544,15 +1635,16 @@ export class OperationService {
15441635 this . ops . push ( interlace ) ;
15451636 this . ops . push ( invert ) ;
15461637 this . ops . push ( replicate ) ;
1547- this . ops . push ( mirrorx ) ;
1548- this . ops . push ( mirrory ) ;
1638+ this . ops . push ( flipx ) ;
1639+ this . ops . push ( flipy ) ;
15491640 this . ops . push ( shiftx ) ;
15501641 this . ops . push ( shifty ) ;
15511642 this . ops . push ( layer ) ;
15521643 this . ops . push ( selvedge ) ;
15531644 this . ops . push ( bindweftfloats ) ;
15541645 this . ops . push ( bindwarpfloats ) ;
15551646 this . ops . push ( joinleft ) ;
1647+ this . ops . push ( jointop ) ;
15561648 this . ops . push ( slope ) ;
15571649 this . ops . push ( tile ) ;
15581650 this . ops . push ( stretch ) ;
@@ -1569,7 +1661,8 @@ export class OperationService {
15691661 this . ops . push ( germanify ) ;
15701662 this . ops . push ( crackleify ) ;
15711663 this . ops . push ( variants ) ;
1572- // this.ops.push(reverse);
1664+ this . ops . push ( knockout ) ;
1665+ this . ops . push ( crop ) ;
15731666
15741667
15751668 //** Give it a classification here */
@@ -1586,12 +1679,12 @@ export class OperationService {
15861679
15871680 this . classification . push (
15881681 { 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 ] }
15901683 ) ;
15911684
15921685 this . classification . push (
15931686 { 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 ] }
15951688 ) ;
15961689
15971690 this . classification . push (
0 commit comments