44 lines
No EOL
1.1 KiB
TypeScript
44 lines
No EOL
1.1 KiB
TypeScript
export class Position {
|
|
public constructor(public line: number, public column: number, public length: number) {
|
|
}
|
|
|
|
public starts(line: number, column: number): boolean {
|
|
return line === this.line && column === this.column;
|
|
}
|
|
|
|
public intersects(line: number, column: number): boolean {
|
|
return line === this.line && column > this.column && column < this.column + this.length;
|
|
}
|
|
|
|
public duplicate(): Position {
|
|
return new Position(this.line, this.column, this.length);
|
|
}
|
|
|
|
public withLength(length: number): Position {
|
|
const duplicate: Position = this.duplicate();
|
|
|
|
duplicate.length = length;
|
|
|
|
return duplicate;
|
|
}
|
|
|
|
public setColumn(column: number): Position {
|
|
this.column = column;
|
|
|
|
return this;
|
|
}
|
|
|
|
public addColumn(column: number): Position {
|
|
this.column += column;
|
|
|
|
return this;
|
|
}
|
|
|
|
public addLine(line: number): Position {
|
|
this.line += line;
|
|
|
|
return this;
|
|
}
|
|
|
|
public static none: Position = new Position(0, 0, 0);
|
|
} |