mirror of
https://github.com/Bismuth-Forge/bismuth.git
synced 2024-11-05 00:54:24 +03:00
make Rect mutable and use Readonly<Rect> instead
Although readonly is quite a joke in Typescript, this is a better approach which allows both mutable and immutable patterns.
This commit is contained in:
parent
2d5e981171
commit
47fa847f7e
@ -91,7 +91,7 @@ interface IConfig {
|
|||||||
|
|
||||||
interface IDriverWindow {
|
interface IDriverWindow {
|
||||||
readonly fullScreen: boolean;
|
readonly fullScreen: boolean;
|
||||||
readonly geometry: Rect;
|
readonly geometry: Readonly<Rect>;
|
||||||
readonly id: string;
|
readonly id: string;
|
||||||
readonly maximized: boolean;
|
readonly maximized: boolean;
|
||||||
readonly shouldIgnore: boolean;
|
readonly shouldIgnore: boolean;
|
||||||
@ -106,7 +106,7 @@ interface IDriverWindow {
|
|||||||
interface ISurface {
|
interface ISurface {
|
||||||
readonly id: string;
|
readonly id: string;
|
||||||
readonly ignore: boolean;
|
readonly ignore: boolean;
|
||||||
readonly workingArea: Rect;
|
readonly workingArea: Readonly<Rect>;
|
||||||
|
|
||||||
next(): ISurface | null;
|
next(): ISurface | null;
|
||||||
}
|
}
|
||||||
|
@ -19,10 +19,13 @@
|
|||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
class Rect {
|
class Rect {
|
||||||
public readonly height: number;
|
constructor(
|
||||||
public readonly width: number;
|
public x: number,
|
||||||
public readonly x: number;
|
public y: number,
|
||||||
public readonly y: number;
|
public width: number,
|
||||||
|
public height: number,
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
public get maxX(): number { return this.x + this.width; }
|
public get maxX(): number { return this.x + this.width; }
|
||||||
public get maxY(): number { return this.y + this.height; }
|
public get maxY(): number { return this.y + this.height; }
|
||||||
@ -34,11 +37,8 @@ class Rect {
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(x: number, y: number, w: number, h: number) {
|
public clone(): Rect {
|
||||||
this.height = h;
|
return new Rect(this.x, this.y, this.width, this.height);
|
||||||
this.width = w;
|
|
||||||
this.x = x;
|
|
||||||
this.y = y;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public equals(other: Rect): boolean {
|
public equals(other: Rect): boolean {
|
||||||
@ -59,6 +59,14 @@ class Rect {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public gap_mut(left: number, right: number, top: number, bottom: number): this {
|
||||||
|
this.x += left;
|
||||||
|
this.y += top;
|
||||||
|
this.width -= (left + right);
|
||||||
|
this.height -= (top + bottom);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public includes(other: Rect): boolean {
|
public includes(other: Rect): boolean {
|
||||||
return (
|
return (
|
||||||
this.x <= other.x &&
|
this.x <= other.x &&
|
||||||
|
Loading…
Reference in New Issue
Block a user