-
Notifications
You must be signed in to change notification settings - Fork 3
/
tile.ts
34 lines (30 loc) · 891 Bytes
/
tile.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { Constraint } from './constraint.models';
import { CoordMap } from './coord-map';
import { Edge } from './edge';
/**
* A wang tile with a probability of appearing and constraints.
*/
export class WangTile<D extends number[], DataType = unknown> {
public edges = new CoordMap<D, Edge>();
constructor(
private readonly data: DataType,
public readonly probability = 1,
) {}
/**
* Add an additional constraint to the tile's placement rules.
* @param constraint - A new constraint.
*/
public addConstraint(constraint: Constraint<D>) {
this.edges.set(constraint.coords, constraint.edge);
}
/**
* Return the string representation of the wang tile value
* @returns a string representation of the data or undefined.
*/
toString(): string {
if (this.data != null) {
return this.data.toString();
}
return 'undefined';
}
}