1class MagicWandSelectGesture extends SelectGesture { 2 constructor() { 3 super(); 4 this.includePredicate_ = null; 5 this.advancePredicate_ = null; 6 this.partialCellsConsideredFloor = false; 7 } 8 9 startGesture() { 10 super.startGesture(); 11 if (!this.anchorCell_) return; 12 const anchorIsWall = this.anchorCell_.isKind(ct.walls, ct.walls.smooth); 13 this.includePredicate_ = cell => { 14 const isWall = cell.isKind(ct.walls, ct.walls.smooth); 15 if (isWall && anchorIsWall) return true; 16 if (!isWall && !anchorIsWall) return true; 17 if (anchorIsWall || !this.partialCellsConsideredFloor) return false; 18 const isPartialWall = 19 cell.isVariation(ct.walls, ct.walls.smooth, ct.walls.smooth.angled) || 20 cell.isVariation(ct.walls, ct.walls.smooth, ct.walls.smooth.oval); 21 return anchorIsWall != isPartialWall; 22 }; 23 this.advancePredicate_ = 24 cell => anchorIsWall == cell.isKind(ct.walls, ct.walls.smooth); 25 this.addCellsLinkedTo_(this.anchorCell_); 26 } 27 28 continueGesture(cell) { 29 this.addCellsLinkedTo_(cell); 30 } 31 32 addCellsLinkedTo_(cell) { 33 let front = new Set(); 34 front.add(cell); 35 this.addSelectedCell_(cell); 36 while (front.size > 0) { 37 const newFront = new Set(); 38 const newCells = new Set(); 39 for (const cell of front.values()) { 40 this.getImmediateNeighborCells(cell).forEach(neighborCell => { 41 if (neighborCell && 42 this.includePredicate_(neighborCell) && 43 !this.selectedCells_.has(neighborCell) && 44 !front.has(neighborCell)) { 45 newCells.add(neighborCell); 46 if (this.advancePredicate_(neighborCell)) { 47 newFront.add(neighborCell); 48 } 49 } 50 }); 51 } 52 newCells.forEach(cell => this.addSelectedCell_(cell)); 53 if (this.selectedCells_.size > constants.maxNumSelectedCells) return; 54 front = newFront; 55 } 56 } 57 58 getImmediateNeighborCells(cell) { 59 const result = []; 60 if (!cell) return result; 61 switch (cell.role) { 62 case 'corner': 63 case 'primary': 64 result.push(cell.getNeighbor('top', true)); 65 result.push(cell.getNeighbor('right', true)); 66 result.push(cell.getNeighbor('bottom', true)); 67 result.push(cell.getNeighbor('left', true)); 68 result.push(cell.getNeighbor('top-right', cell.role == 'primary')); 69 result.push(cell.getNeighbor('bottom-right', cell.role == 'primary')); 70 result.push(cell.getNeighbor('bottom-left', cell.role == 'primary')); 71 result.push(cell.getNeighbor('top-left', cell.role == 'primary')); 72 break; 73 case 'horizontal': 74 result.push(cell.getNeighbor('top', false)); 75 result.push(cell.getNeighbor('right', true)); 76 result.push(cell.getNeighbor('bottom', false)); 77 result.push(cell.getNeighbor('left', true)); 78 break; 79 case 'vertical': 80 result.push(cell.getNeighbor('top', true)); 81 result.push(cell.getNeighbor('right', false)); 82 result.push(cell.getNeighbor('bottom', true)); 83 result.push(cell.getNeighbor('left', false)); 84 break; 85 } 86 return result; 87 } 88}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.