-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfenceManager.js
47 lines (38 loc) · 1.1 KB
/
fenceManager.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
// Fence Manager
class FenceManager {
constructor() {
// Points represent fence posts
this.points = [];
// First post/point to be place
this.genesisPoint = undefined;
// Convex hull / Perimeter created by fences
this.convexHull = new ConvexHull();
}
// Setup the genesis point
setGenesisPoint(x,y) {
this.genesisPoint = new GenesisPoint(x,y);
}
// Create virtual plane from genesis point if set
setupVirtualPlane() {
if(this.genesisPoint) {
line(0, this.genesisPoint.y, WIDTH, this.genesisPoint.y); // line (y = 0)
line(this.genesisPoint.x, 0, this.genesisPoint.x, HEIGHT); // line (x = 0)
}
}
// Create the Fence Boundary
constructFenceBoundary() {
if(this.points.length > 2) {
this.setupVirtualPlane();
this.convexHull.jarvisWalk(this.points);
this.points = this.convexHull.removePointsInHull(this.points);
}
}
// Adds fence post to the post collection
addFencePost(x,y) {
if(this.points.length === 0) {
console.log("Added Gensis Point");
this.setGenesisPoint(x,y);
}
this.points.push(new Point(x,y,this.genesisPoint));
}
}