-
Notifications
You must be signed in to change notification settings - Fork 2
/
parser.js
70 lines (65 loc) · 1.9 KB
/
parser.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
module.exports = function parser(str) { //expects one long string (with or without \n chars)
var reFloat = /\s(-?\d[\d\.]*)/g //allows multiple periods. parseFloat() ignores digits after the 2nd period.
var reFileName = /([\w-]+\.[A-z]{3})/
var result = {}
var strArr = str.split("===== Size =====")
if (strArr.length === 2) {
var temp
var detectedNums = []
while ((temp = reFloat.exec(strArr[1])) !== null) {
detectedNums.push(parseFloat(temp[0]))
}
}
if (detectedNums.length === 28 && strArr.length === 2) {
result.x = {
min: detectedNums[0],
max: detectedNums[1]
}
result.y = {
min: detectedNums[2],
max: detectedNums[3]
}
result.z = {
min: detectedNums[4],
max: detectedNums[5]
}
result.facets = {
overall: {
before: parseInt(detectedNums[6]),
after: parseInt(detectedNums[7])
},
disconnected1: {
before: parseInt(detectedNums[9]), //ignore 8
after: parseInt(detectedNums[10])
},
disconnected2: {
before: parseInt(detectedNums[12]), //ignore 11
after: parseInt(detectedNums[13])
},
disconnected3: {
before: parseInt(detectedNums[15]), //ignore 14
after: parseInt(detectedNums[16])
},
disconnected: {
before: parseInt(detectedNums[17]),
after: parseInt(detectedNums[18])
},
degenerate: parseInt(detectedNums[21]),
removed: parseInt(detectedNums[23]),
added: parseInt(detectedNums[24]),
reversed: parseInt(detectedNums[25])
}
result.volume = detectedNums[20]
result.parts = parseInt(detectedNums[19])
result.edges = {
fixed: parseInt(detectedNums[22]),
backwards: parseInt(detectedNums[26])
}
result.normalsFixed = parseInt(detectedNums[27])
return result
} else {
var err = new Error("Unparseable string: "+strArr.length+", "+detectedNums.length)
err.detectedNums = detectedNums.length
throw err
}
}