All files / src virtual_position.ts

78.26% Statements 36/46
50% Branches 5/10
100% Functions 3/3
78.26% Lines 36/46

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 471x 1x 1x 1x 1x 1x 1x 1x 1x 256x 256x 256x 256x 1x 1x 7x     7x 7x 7x 1x 1x 5x 1x     1x 1x     1x 1x     1x 1x     1x 1x 5x 4x 4x 5x 1x  
import {Position} from "./position";
 
/** used for macro calls */
 
export class VirtualPosition extends Position {
  public readonly vrow: number;
  public readonly vcol: number;
 
  public constructor(virtual: Position, row: number, col: number) {
    super(virtual.getRow(), virtual.getCol());
    this.vrow = row;
    this.vcol = col;
  }
 
  public equals(p: Position): boolean {
    if (!(p instanceof VirtualPosition)) {
      return false;
    }
    const casted: VirtualPosition = p as VirtualPosition;
    return super.equals(this) && this.vrow === casted.vrow && this.vcol === casted.vcol;
  }
 
  public isAfter(p: Position | VirtualPosition): boolean {
    if (p instanceof VirtualPosition) {
      if (this.getRow() > p.getRow()) {
        return true;
      }
 
      if (this.getRow() === p.getRow() && this.getCol() > p.getCol()) {
        return true;
      }
 
      if (this.getRow() === p.getRow() && this.getCol() === p.getCol() && this.vrow > p.vrow) {
        return true;
      }
 
      if (this.getRow() === p.getRow() && this.getCol() === p.getCol() && this.vrow === p.vrow && this.vcol > p.vcol) {
        return true;
      }
 
      return false;
    } else {
      return super.isAfter(p);
    }
  }
}