-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathmarkup.go
332 lines (241 loc) · 7.91 KB
/
markup.go
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
package ewa
import (
"fmt"
"github.com/apex/log"
)
//Markup struct
type Markup struct {
Impulses []*Impulse
Corrections []*Correction
Zigzags []*Zigzag
Flats []*Flat
Triangles []*Triangle
Combos []*Combo
Triples []*Triple
}
func (m *Markup) addImpulse(impulse *Impulse) *Impulse {
context := log.WithFields(log.Fields{
"M": impulse.Move,
"D": impulse.Degree,
})
for _, one := range m.Impulses {
if one.Move.Base.P == impulse.Move.Base.P &&
one.Move.End.P == impulse.Move.End.P {
context.Debug("Impulse found")
return one
}
}
context.Debug("+Impulse")
m.Impulses = append(m.Impulses, impulse)
return impulse
}
func (m *Markup) addCorrection(correction *Correction) *Correction {
context := log.WithFields(log.Fields{
"M": correction.Move,
"D": correction.Degree,
})
for _, one := range m.Corrections {
if one.Move.Base.P == correction.Move.Base.P &&
one.Move.End.P == correction.Move.End.P {
context.Debug("Correction found")
return one
}
}
context.Debug("+Correction")
m.Corrections = append(m.Corrections, correction)
return correction
}
func (m *Markup) processImpulseWave(w mwImpulse) {
degree := Degree(w.Degree)
lessDegree := degree << 1
//Generating points
ori := PointFromMW(w.Origin)
pW1 := PointFromMW(w.Wave1)
pW2 := PointFromMW(w.Wave2)
pW3 := PointFromMW(w.Wave3)
pW4 := PointFromMW(w.Wave4)
pW5 := PointFromMW(w.Wave5)
//Generating sub waves
subW1 := &Wave{Move: &Move{ori, pW1}, Degree: lessDegree}
subW2 := &Wave{Move: &Move{pW1, pW2}, Degree: lessDegree}
subW3 := &Wave{Move: &Move{pW2, pW3}, Degree: lessDegree}
subW4 := &Wave{Move: &Move{pW3, pW4}, Degree: lessDegree}
subW5 := &Wave{Move: &Move{pW4, pW5}, Degree: lessDegree}
setImpulseWaveAdjecency([5]*Wave{subW1, subW2, subW3, subW4, subW5})
// Generating impulse wave
wave := &Wave{Move: &Move{ori, pW5}, Degree: degree}
setParentWave(wave, subW1, subW2, subW3, subW4, subW5)
// Adding primitives
impulse := m.addImpulse(&Impulse{Wave: wave})
impulse.W1 = m.addImpulse(&Impulse{Wave: subW1})
impulse.W3 = m.addImpulse(&Impulse{Wave: subW3})
impulse.W5 = m.addImpulse(&Impulse{Wave: subW5})
impulse.W2 = m.addCorrection(&Correction{Wave: subW2})
impulse.W4 = m.addCorrection(&Correction{Wave: subW4})
}
func (m *Markup) processImpulses(mwQuery *mwQuery) {
for _, w := range mwQuery.Impulses {
m.processImpulseWave(w)
}
for _, w := range mwQuery.ImpulsesLeading {
m.processImpulseWave(w)
}
for _, w := range mwQuery.ImpulsesEnding {
m.processImpulseWave(w)
}
}
func (m *Markup) processCorrections(mwQuery *mwQuery) {
for _, w := range mwQuery.Corrections {
degree := Degree(w.Degree)
lessDegree := degree << 1
//Generating points
ori := PointFromMW(w.Origin)
pWA := PointFromMW(w.WaveA)
pWB := PointFromMW(w.WaveB)
pWC := PointFromMW(w.WaveC)
//Generating sub waves
wave := &Wave{Move: &Move{ori, pWC}, Degree: degree}
subWA := &Wave{Move: &Move{ori, pWA}, Degree: lessDegree}
subWB := &Wave{Move: &Move{pWA, pWB}, Degree: lessDegree}
subWC := &Wave{Move: &Move{pWB, pWC}, Degree: lessDegree}
setParentWave(wave, subWA, subWB, subWC)
corr := m.addCorrection(&Correction{Wave: wave})
wB := m.addCorrection(&Correction{Wave: subWB})
wC := m.addImpulse(&Impulse{Wave: subWC})
if subWA.Len()*.9 <= subWB.Len() {
// Flat
wA := m.addCorrection(&Correction{Wave: subWA})
flat := &Flat{A: wA, B: wB, C: wC}
corr.Flat = flat
m.Flats = append(m.Flats, flat)
} else {
// Zigzag
wA := m.addImpulse(&Impulse{Wave: subWA})
zigzag := &Zigzag{A: wA, B: wB, C: wC}
corr.Zigzag = zigzag
m.Zigzags = append(m.Zigzags, zigzag)
}
}
}
func (m *Markup) processTriangles(mwQuery *mwQuery) {
for _, w := range mwQuery.Triangles {
degree := Degree(w.Degree)
lessDegree := degree << 1
//Generating points
ori := PointFromMW(w.Origin)
pWA := PointFromMW(w.WaveA)
pWB := PointFromMW(w.WaveB)
pWC := PointFromMW(w.WaveC)
pWD := PointFromMW(w.WaveD)
pWE := PointFromMW(w.WaveE)
//Generating sub waves
wave := &Wave{Move: &Move{ori, pWE}, Degree: degree}
subWA := &Wave{Move: &Move{ori, pWA}, Degree: lessDegree}
subWB := &Wave{Move: &Move{pWA, pWB}, Degree: lessDegree}
subWC := &Wave{Move: &Move{pWB, pWC}, Degree: lessDegree}
subWD := &Wave{Move: &Move{pWC, pWD}, Degree: lessDegree}
subWE := &Wave{Move: &Move{pWD, pWE}, Degree: lessDegree}
setParentWave(wave, subWA, subWB, subWC, subWD, subWE)
// Generating triangle wave
triangleWave := &Wave{Move: &Move{ori, pWE}, Degree: degree}
triangleCorrection := m.addCorrection(&Correction{Wave: triangleWave})
triangle := &Triangle{
A: m.addCorrection(&Correction{Wave: subWA}),
B: m.addCorrection(&Correction{Wave: subWB}),
C: m.addCorrection(&Correction{Wave: subWC}),
D: m.addCorrection(&Correction{Wave: subWD}),
E: m.addCorrection(&Correction{Wave: subWE}),
}
log.WithField("Triangle", triangle).Debug("+Triangle")
triangleCorrection.Triangle = triangle
m.Triangles = append(m.Triangles, triangle)
//TODO 9 wave triangle
}
}
func (m *Markup) processTripleWave(w mwComboTriple) {
degree := Degree(w.Degree)
lessDegree := degree << 1
//Generating points
ori := PointFromMW(w.Origin)
pWW := PointFromMW(w.WaveW)
pWX := PointFromMW(w.WaveX)
pWY := PointFromMW(w.WaveY)
pWX2 := PointFromMW(w.WaveX2)
pWZ := PointFromMW(w.WaveZ)
//Generating sub waves
wave := &Wave{Move: &Move{ori, pWZ}, Degree: degree}
subWW := &Wave{Move: &Move{ori, pWW}, Degree: lessDegree}
subWX := &Wave{Move: &Move{pWW, pWX}, Degree: lessDegree}
subWY := &Wave{Move: &Move{pWX, pWY}, Degree: lessDegree}
subWX2 := &Wave{Move: &Move{pWY, pWX2}, Degree: lessDegree}
subWZ := &Wave{Move: &Move{pWX2, pWZ}, Degree: lessDegree}
setParentWave(wave, subWW, subWX, subWY, subWX2, subWZ)
// Generating triangle wave
tripleWave := &Wave{Move: &Move{ori, pWZ}, Degree: degree}
tripleCorrection := m.addCorrection(&Correction{Wave: tripleWave})
triple := &Triple{
W: m.addCorrection(&Correction{Wave: subWW}),
X: m.addCorrection(&Correction{Wave: subWX}),
Y: m.addCorrection(&Correction{Wave: subWY}),
X2: m.addCorrection(&Correction{Wave: subWX2}),
Z: m.addCorrection(&Correction{Wave: subWZ}),
}
tripleCorrection.Triple = triple
log.WithField("Triple", triple).Debug("+Triple")
m.Triples = append(m.Triples, triple)
}
func (m *Markup) processComboWave(w mwComboTriple) {
degree := Degree(w.Degree)
lessDegree := degree << 1
//Generating points
ori := PointFromMW(w.Origin)
pWW := PointFromMW(w.WaveW)
pWX := PointFromMW(w.WaveX)
pWY := PointFromMW(w.WaveY)
//Generating sub waves
wave := &Wave{Move: &Move{ori, pWY}, Degree: degree}
subWW := &Wave{Move: &Move{ori, pWW}, Degree: lessDegree}
subWX := &Wave{Move: &Move{pWW, pWX}, Degree: lessDegree}
subWY := &Wave{Move: &Move{pWX, pWY}, Degree: lessDegree}
setParentWave(wave, subWW, subWX, subWY)
// Generating triangle wave
comboWave := &Wave{Move: &Move{ori, pWY}, Degree: degree}
comboCorrection := m.addCorrection(&Correction{Wave: comboWave})
combo := &Combo{
W: m.addCorrection(&Correction{Wave: subWW}),
X: m.addCorrection(&Correction{Wave: subWX}),
Y: m.addCorrection(&Correction{Wave: subWY}),
}
comboCorrection.Combo = combo
log.WithField("Combo", combo).Debug("+Combo")
m.Combos = append(m.Combos, combo)
}
func (m *Markup) processTripleCombo(mwQuery *mwQuery) {
for _, w := range mwQuery.TripleCombo {
if w.WaveZ.T != 0 {
m.processTripleWave(w)
} else {
m.processComboWave(w)
}
}
}
func (m *Markup) printStack() {
for _, one := range m.Impulses {
log.WithFields(log.Fields{
"D": one.Duration(),
"P": fmt.Sprintf("%.2f->%.2f", one.Base.P, one.End.P),
"W1": one.W1,
"W2": one.W2,
"W3": one.W3,
"W4": one.W4,
"W5": one.W5,
}).Debug("Imp")
}
for _, one := range m.Corrections {
log.WithFields(log.Fields{
"D": one.Duration(),
"P": fmt.Sprintf("%.2f->%.2f", one.Base.P, one.End.P),
"T": one.Type(),
}).Debug("Corr")
}
}