2021-02-05 21:32:38 -05:00
|
|
|
import Vector2 from "./Vector2";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Wrapper for Vector2 that provides width, height and radius properties
|
|
|
|
*/
|
|
|
|
class Size extends Vector2 {
|
|
|
|
_radius;
|
|
|
|
/**
|
|
|
|
* @param {number} width
|
|
|
|
* @param {number} height
|
2021-05-25 03:35:26 -04:00
|
|
|
* @param {number} radius Used to represent hexagon sizes
|
2021-02-05 21:32:38 -05:00
|
|
|
*/
|
2021-05-25 03:35:26 -04:00
|
|
|
constructor(width: number, height: number, radius?: number) {
|
2021-02-05 21:32:38 -05:00
|
|
|
super(width, height);
|
|
|
|
this._radius = radius;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @returns {number}
|
|
|
|
*/
|
2021-05-25 03:35:26 -04:00
|
|
|
get width(): number {
|
2021-02-05 21:32:38 -05:00
|
|
|
return this.x;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {number} width
|
|
|
|
*/
|
2021-05-25 03:35:26 -04:00
|
|
|
set width(width: number) {
|
2021-02-05 21:32:38 -05:00
|
|
|
this.x = width;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @returns {number}
|
|
|
|
*/
|
2021-05-25 03:35:26 -04:00
|
|
|
get height(): number {
|
2021-02-05 21:32:38 -05:00
|
|
|
return this.y;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {number} height
|
|
|
|
*/
|
2021-05-25 03:35:26 -04:00
|
|
|
set height(height: number) {
|
2021-02-05 21:32:38 -05:00
|
|
|
this.y = height;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @returns {number}
|
|
|
|
*/
|
2021-05-25 03:35:26 -04:00
|
|
|
get radius(): number {
|
2021-02-05 21:32:38 -05:00
|
|
|
if (this._radius) {
|
|
|
|
return this._radius;
|
|
|
|
} else {
|
|
|
|
return Math.min(this.x, this.y) / 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {number} radius
|
|
|
|
*/
|
2021-05-25 03:35:26 -04:00
|
|
|
set radius(radius: number) {
|
2021-02-05 21:32:38 -05:00
|
|
|
this._radius = radius;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default Size;
|