face-api/src/classes/Dimensions.ts

30 lines
745 B
TypeScript
Raw Normal View History

2020-12-19 17:46:41 +01:00
import { isValidNumber } from '../utils/index';
2020-08-18 13:54:53 +02:00
export interface IDimensions {
width: number
height: number
}
export class Dimensions implements IDimensions {
private _width: number
2020-12-23 17:26:55 +01:00
2020-08-18 13:54:53 +02:00
private _height: number
constructor(width: number, height: number) {
if (!isValidNumber(width) || !isValidNumber(height)) {
2020-12-23 17:26:55 +01:00
throw new Error(`Dimensions.constructor - expected width and height to be valid numbers, instead have ${JSON.stringify({ width, height })}`);
2020-08-18 13:54:53 +02:00
}
2020-12-23 17:26:55 +01:00
this._width = width;
this._height = height;
2020-08-18 13:54:53 +02:00
}
2020-12-23 17:26:55 +01:00
public get width(): number { return this._width; }
public get height(): number { return this._height; }
2020-08-18 13:54:53 +02:00
public reverse(): Dimensions {
2020-12-23 17:26:55 +01:00
return new Dimensions(1 / this.width, 1 / this.height);
2020-08-18 13:54:53 +02:00
}
2020-12-23 17:26:55 +01:00
}