diff options
| author | bob <bcz@cs.brown.edu> | 2019-03-20 18:00:39 -0400 |
|---|---|---|
| committer | bob <bcz@cs.brown.edu> | 2019-03-20 18:00:39 -0400 |
| commit | a16e6592caafb601b59c3d9f7609e8c1af231eba (patch) | |
| tree | e732e34c5a9fc371bf328fdd35a08ddd196bf6af /src/client/northstar/core/brusher | |
| parent | 208a57b15e6b415659311873431dbe9d5b8d8021 (diff) | |
initial
Diffstat (limited to 'src/client/northstar/core/brusher')
| -rw-r--r-- | src/client/northstar/core/brusher/BrushLinkModel.ts | 40 | ||||
| -rw-r--r-- | src/client/northstar/core/brusher/IBaseBrushable.ts | 13 | ||||
| -rw-r--r-- | src/client/northstar/core/brusher/IBaseBrusher.ts | 11 |
3 files changed, 64 insertions, 0 deletions
diff --git a/src/client/northstar/core/brusher/BrushLinkModel.ts b/src/client/northstar/core/brusher/BrushLinkModel.ts new file mode 100644 index 000000000..e3ac43367 --- /dev/null +++ b/src/client/northstar/core/brusher/BrushLinkModel.ts @@ -0,0 +1,40 @@ +import { IBaseBrushable } from '../brusher/IBaseBrushable' +import { IBaseBrusher } from '../brusher/IBaseBrusher' +import { Utils } from '../../utils/Utils' +import { IEquatable } from '../../utils/IEquatable'; + +export class BrushLinkModel<T> implements IEquatable { + + public From: IBaseBrusher<T>; + + public To: IBaseBrushable<T>; + + public Color: number = 0; + + constructor(from: IBaseBrusher<T>, to: IBaseBrushable<T>) { + this.From = from; + this.To = to; + } + + public static overlaps(start: number, end: number, otherstart: number, otherend: number): boolean { + if (start > otherend || otherstart > end) + return false; + return true; + } + public static Connected<T>(from: IBaseBrusher<T>, to: IBaseBrushable<T>): boolean { + var connected = (Math.abs(from.Position.x + from.Size.x - to.Position.x) <= 60 && + this.overlaps(from.Position.y, from.Position.y + from.Size.y, to.Position.y, to.Position.y + to.Size.y) + ) || + (Math.abs(to.Position.x + to.Size.x - from.Position.x) <= 60 && + this.overlaps(to.Position.y, to.Position.y + to.Size.y, from.Position.y, from.Position.y + from.Size.y) + ); + return connected; + } + + public Equals(other: Object): boolean { + if (!Utils.EqualityHelper(this, other)) return false; + if (!this.From.Equals((other as BrushLinkModel<T>).From)) return false; + if (!this.To.Equals((other as BrushLinkModel<T>).To)) return false; + return true; + } +}
\ No newline at end of file diff --git a/src/client/northstar/core/brusher/IBaseBrushable.ts b/src/client/northstar/core/brusher/IBaseBrushable.ts new file mode 100644 index 000000000..07d4e7580 --- /dev/null +++ b/src/client/northstar/core/brusher/IBaseBrushable.ts @@ -0,0 +1,13 @@ +import { BrushLinkModel } from '../brusher/BrushLinkModel' +import { PIXIPoint } from '../../utils/MathUtil' +import { IEquatable } from '../../utils/IEquatable'; + +export interface IBaseBrushable<T> extends IEquatable { + BrusherModels: Array<BrushLinkModel<T>>; + BrushColors: Array<number>; + Position: PIXIPoint; + Size: PIXIPoint; +} +export function instanceOfIBaseBrushable<T>(object: any): object is IBaseBrushable<T> { + return 'BrusherModels' in object; +}
\ No newline at end of file diff --git a/src/client/northstar/core/brusher/IBaseBrusher.ts b/src/client/northstar/core/brusher/IBaseBrusher.ts new file mode 100644 index 000000000..d7ae65464 --- /dev/null +++ b/src/client/northstar/core/brusher/IBaseBrusher.ts @@ -0,0 +1,11 @@ +import { PIXIPoint } from '../../utils/MathUtil' +import { IEquatable } from '../../utils/IEquatable'; + + +export interface IBaseBrusher<T> extends IEquatable { + Position: PIXIPoint; + Size: PIXIPoint; +} +export function instanceOfIBaseBrusher<T>(object: any): object is IBaseBrusher<T> { + return 'BrushableModels' in object; +}
\ No newline at end of file |
