-
Notifications
You must be signed in to change notification settings - Fork 0
/
MoorNeighbourhood.js
93 lines (77 loc) · 1.74 KB
/
MoorNeighbourhood.js
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
'use strict'
/**
* Dependencies
* @ignore
*/
const Point = require('./Point')
const Constants = require('./Constants')
/**
* Constants
* @ignore
*/
const {
roomSize,
} = Constants
/**
* MoorNeighbourhood
* @ignore
*/
class MoorNeighbourhood {
constructor (points) {
Object.defineProperty(this, 'points', { value: points })
Object.defineProperty(this, 'values', {
value: this.points.map(point => point ? point.v : undefined),
enumerable: true
})
}
static getNeighbourhood(point) {
const { x, y, room } = point
const topEdge = y === 0
const leftEdge = x === 0
const bottomEdge = y === roomSize - 1
const rightEdge = x === roomSize - 1
return new MoorNeighbourhood([
topEdge || leftEdge ? Point.border : room.getCoord(x-1, y-1),
topEdge ? Point.border : room.getCoord(x, y-1),
topEdge || rightEdge ? Point.border : room.getCoord(x+1, y-1),
leftEdge ? Point.border : room.getCoord(x-1, y),
point,
rightEdge ? Point.border : room.getCoord(x+1, y),
bottomEdge || leftEdge ? Point.border : room.getCoord(x-1, y+1),
bottomEdge ? Point.border : room.getCoord(x, y+1),
bottomEdge || rightEdge ? Point.border : room.getCoord(x+1, y+1),
])
}
get pTopLeft () {
return this.points[0]
}
get pTop () {
return this.points[1]
}
get pTopRight () {
return this.points[2]
}
get pLeft () {
return this.points[3]
}
get pMiddle () {
return this.points[4]
}
get pRight () {
return this.points[5]
}
get pBottomLeft () {
return this.points[6]
}
get pBottom () {
return this.points[7]
}
get pBottomRight () {
return this.points[8]
}
}
/**
* Exports
* @ignore
*/
module.exports = MoorNeighbourhood