-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
214 lines (167 loc) · 5.03 KB
/
test.js
File metadata and controls
214 lines (167 loc) · 5.03 KB
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
import fs from "fs";
import { parseQuadtree, Quadtree } from "./quadtree.js";
import { parseProject, Project, Layer, Area, Structure } from "./project.js";
/**
* 쿼드트리 테스트 1
* - 여러 모양을 쿼드트리에 그림
*/
function quadtreeTest1() {
const qt = new Quadtree(0);
// 7. 전체 배경 텍스처 느낌의 큰 원 (value: 2)
qt.drawCircle(0.5, 0.5, 0.5, 1);
// 1. 별 모양 중앙 (value: 1)
qt.drawPoly([
[0.5, 0.1],
[0.6175, 0.3412],
[0.875, 0.3412],
[0.675, 0.5412],
[0.7587, 0.825],
[0.5, 0.66],
[0.2412, 0.825],
[0.325, 0.5412],
[0.125, 0.3412],
[0.3825, 0.3412]
], 2);
// 2. 좌측 하단 원 (value: 3)
qt.drawCircle(0.2, 0.2, 0.15, 3);
// 3. 우측 하단 직사각형 (value: 4)
qt.drawRect(0.75, 0.75, 0.95, 0.95, 4);
// 4. 중심에 겹쳐지는 작은 원 (value: 5)
qt.drawCircle(0.5, 0.5, 0.15, 5);
// 5. 좌하단 장식용 직사각형 (value: 6)
qt.drawRect(0.05, 0.8, 0.2, 0.95, 6);
// 6. 우상단 큰 원 (value: 7)
qt.drawCircle(0.8, 0.2, 0.18, 7);
console.log(JSON.stringify(qt.jsonify()));
}
/**
* 쿼드트리 테스트 2
* - 두 개의 원을 그린 후 겹침 제거
*/
function quadtreeTest2() {
const qt = new Quadtree(0);
qt.drawCircle(0.5, 0.5, 0.4, 1);
const qf = new Quadtree(0);
qf.drawCircle(1.0, 0.5, 0.5, 2);
qt.excludeOverlap(qf, 3);
console.log(JSON.stringify(qt.toJSON()));
}
/**
* 타원 그리기 테스트
*/
function quadtreeTest3() {
const qt = new Quadtree(0);
qt.drawCircle(0.5, 0.5, 0.2, 1, 2);
console.log(JSON.stringify(qt.toJSON()));
}
/**
* 빼기 테스트
*/
function quadtreeTest4() {
const qt = new Quadtree(0);
qt.drawCircle(0.5, 0.5, 0.5, 1);
qt.drawPoly([
[0.5, 0.1],
[0.6175, 0.3412],
[0.875, 0.3412],
[0.675, 0.5412],
[0.7587, 0.825],
[0.5, 0.66],
[0.2412, 0.825],
[0.325, 0.5412],
[0.125, 0.3412],
[0.3825, 0.3412]
], 2);
qt.drawCircle(0.2, 0.2, 0.15, 3);
qt.drawRect(0.75, 0.75, 0.95, 0.95, 4);
qt.drawCircle(0.5, 0.5, 0.15, 5);
qt.drawRect(0.05, 0.8, 0.2, 0.95, 6);
qt.drawCircle(0.8, 0.2, 0.18, 7);
const qta = parseQuadtree(qt.toJSON());
qta.drawCircle(0.5, 0.5, 0.4, 8);
const result = qta.difference(qt)
console.log(JSON.stringify(result.toJSON()));
}
function quadtreeTest5() {
const qt = new Quadtree(0);
qt.drawCircle(0.5, 0.5, 0.5, 1);
qt.drawCircle(0.5, 0.5, 0.4, 0);
qt.drawCircle(0.5, 0.5, 0.3, 1);
qt.drawCircle(0.5, 0.5, 0.2, 0);
qt.floodFillAt(0.5, 0.15, 2);
console.log(JSON.stringify(qt.toJSON()));
}
quadtreeTest5();
/**
* 프로젝트 전체 테스트
* - 지형, 날씨, 국가 레이어 구성 및 구조체 생성
*/
function projectTest1() {
// 지형 레이어
const bl = new Layer("Terrain");
const blaroc = new Area("Ocean", "blue");
bl.addArea(blaroc);
const blarla = new Area("Land", "green");
bl.addArea(blarla);
const blst1fig = new Quadtree(blaroc.id);
blst1fig.drawRect(0.5, 0.0, 1.0, 1.0, blarla.id);
const blst1 = new Structure(0, blst1fig);
bl.addStructure(blst1);
// 국가 레이어
const co = new Layer("Country");
const coarno = new Area("No Country", "transparent");
co.addArea(coarno);
const coarza = new Area("Zasoque", "yellow");
co.addArea(coarza);
const cost1fig = new Quadtree(coarno.id);
cost1fig.drawRect(0.5, 0.0, 1.0, 0.5, coarza.id);
const cost1 = new Structure(0, cost1fig);
co.addStructure(cost1);
bl.addChildLayer(co);
// 날씨 레이어
const we = new Layer("Weather");
const wearno = new Area("Good", "transparent");
we.addArea(wearno);
const wearza = new Area("Snow", "white");
we.addArea(wearza);
const west1fig = new Quadtree(wearno.id);
west1fig.drawRect(0.0, 0.0, 1.0, 0.5, wearza.id);
const west1 = new Structure(0, west1fig);
we.addStructure(west1);
const west2fig = new Quadtree(wearno.id);
west2fig.drawRect(0.25, 0.0, 0.75, 0.5, wearza.id);
const west2 = new Structure(1, west2fig);
we.addStructure(west2);
bl.addChildLayer(we);
// 프로젝트 생성
const pr = new Project("Sat Worldmap", bl);
console.log(pr.stringify());
}
/**
* 프로젝트 불러오기 테스트
*/
function projectTest2() {
fs.readFile("./tmp/output1.json", "utf-8", (err, data) => {
const pr = parseProject(data);
console.log(pr.stringify());
console.log(pr.baseLayer.structures[0].figure);
})
}
function projectTest3() {
fs.readFile("./tmp/satqt.json", "utf-8", (err, data) => {
const layer = new Layer("아벨리카 이전 지형");
const oceanarea = new Area("바다", "grey");
const landarea = new Area("육지", "lightgrey");
layer.addArea(oceanarea);
layer.addArea(landarea);
data = data
.replace(/1/gi, JSON.stringify(landarea.id))
.replace(/0/gi, JSON.stringify(oceanarea.id));
const qt = parseQuadtree(JSON.parse(data));
const structure = layer.createStructureByYear(0);
structure.figure.overlap(qt);
layer.addStructure(structure);
const proj = new Project("사트 7기 지도", layer);
console.log(proj.stringify());
})
}