pth_to_lyt 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core/PTHToLYT.d.ts +1 -0
- package/dist/core/PTHToLYT.d.ts.map +1 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +143 -5
- package/dist/input/PTH.parser.d.ts +3 -1
- package/dist/input/PTH.parser.d.ts.map +1 -0
- package/dist/input/PTH.reader.d.ts +1 -0
- package/dist/input/PTH.reader.d.ts.map +1 -0
- package/dist/input/types.d.ts +1 -0
- package/dist/input/types.d.ts.map +1 -0
- package/dist/output/LYT.transform.d.ts +4 -2
- package/dist/output/LYT.transform.d.ts.map +1 -0
- package/dist/output/LYT.writer.d.ts +3 -1
- package/dist/output/LYT.writer.d.ts.map +1 -0
- package/dist/output/constants.d.ts +1 -0
- package/dist/output/constants.d.ts.map +1 -0
- package/dist/output/types.d.ts +1 -0
- package/dist/output/types.d.ts.map +1 -0
- package/package.json +21 -8
- package/dist/core/PTHToLYT.js +0 -16
- package/dist/input/PTH.parser.js +0 -76
- package/dist/input/PTH.reader.js +0 -14
- package/dist/input/types.js +0 -2
- package/dist/output/LYT.transform.js +0 -85
- package/dist/output/LYT.writer.js +0 -44
- package/dist/output/constants.js +0 -6
- package/dist/output/types.js +0 -2
package/dist/core/PTHToLYT.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PTHToLYT.d.ts","sourceRoot":"","sources":["../../src/core/PTHToLYT.ts"],"names":[],"mappings":"AAOA,2BAA2B;AAC3B,wBAAgB,eAAe,CAC3B,aAAa,EAAE,MAAM,EACrB,aAAa,EAAE,MAAM,EACrB,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,MAAM,QAYlB"}
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h=require("fs");function g(t){const n=L(t),e=w(t),o=N(t),r=H(t,o);return{systemHeader:n,localHeader:e,numberNodes:o,mainNodes:r}}function L(t){let e=0;const o=t.toString("ascii",e,e+6);if(e+=6,o!=="SRPATH")throw new Error("Invalid File (SRPATH not found)");const r=t.readUInt8(e++),c=t.readUInt8(e++);if(r>0||c>252)throw new Error("Wrong version");const i=t.readInt32LE(e);return{version:r,revision:c,flags:i}}function w(t){return{miniRev:t.readUInt8(12)}}function N(t){const e=t.readUInt16LE(16);if(e<=0)throw new Error("The number of nodes is too low");return e}function y(t,n){return{centre:{x:n.readInt32LE(t+4),y:n.readInt32LE(t+8)},dir:{x:n.readFloatLE(t+16),y:n.readFloatLE(t+20)},limits:{driveLeft:n.readFloatLE(t+36),driveRight:n.readFloatLE(t+40)}}}function H(t,n){const r=[];for(let c=0;c<n;c++){const i=56+44*c;r[c]=y(i,t)}return r}function M(t){const n=h.readFileSync(t);if(n===void 0)throw new Error("Invalid File");return n}const s=65536,R=16,x=s/R;function P(t,n){const i=[],a=n<180?n:180,d=n/a;for(let l=0;l<a;l++){const F=Math.round(d*l),E=t[F],_=A(E.dir.x,E.dir.y),u=D(E),I=U(u),f=m(u),O=T(f.x),S=T(f.y);i.push({x:O,y:S,z:240,flags:I<<2|1,index:252,heading:_})}return i}function T(t){return Math.round(t/x)}function A(t,n){const o=Math.atan2(n,t)*(180/Math.PI);return Math.round((o-90+180)*256/360)&255}function D(t){const n=-t.dir.y,e=t.dir.x,o={x:t.centre.x-n*t.limits.driveLeft*s,y:t.centre.y-e*t.limits.driveLeft*s},r={x:t.centre.x-n*t.limits.driveRight*s,y:t.centre.y-e*t.limits.driveRight*s};return{left:o,right:r}}function m(t){const n=(t.right.x+t.left.x)/2,e=(t.right.y+t.left.y)/2;return{x:n,y:e}}function U(t,n=2){const e=Math.pow(t.right.x-t.left.x,2),o=Math.pow(t.right.y-t.left.y,2),r=Math.sqrt(e+o),c=Math.round(r/s/2+n);return c>31?31:c}function Y(t,n){const e=v(n.length),o=p(n),r=[e,o],c=Buffer.concat(r);h.writeFileSync(t,c)}function v(t){const n=Buffer.alloc(12);return n.write("LFSLYT",0,"ascii"),n.writeUInt8(0,6),n.writeUInt8(252,7),n.writeUInt16LE(t,8),n.writeUInt8(0,10),n.writeUInt8(9,11),n}function p(t){const n=Buffer.alloc(8*t.length);let e=0;for(let o=0;o<t.length;o++){const r=t[o];n.writeInt16LE(r.x,e),e+=2,n.writeInt16LE(r.y,e),e+=2,n.writeUInt8(r.z,e),e++,n.writeUInt8(r.flags,e),e++,n.writeUInt8(r.index,e),e++,n.writeUInt8(r.heading,e),e++}return n}function C(t,n,e,o){const r=`${t}/${e}.pth`,c=`${n}/${e}_${o}.lyt`,i=M(r),a=g(i),d=P(a.mainNodes,a.numberNodes);Y(c,d)}exports.convertPTHtoLYT=C;
|
package/dist/index.d.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export { convertPTHtoLYT } from
|
|
1
|
+
export { convertPTHtoLYT } from './core/PTHToLYT';
|
|
2
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,143 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import T from "fs";
|
|
2
|
+
function g(t) {
|
|
3
|
+
const n = L(t), e = w(t), o = N(t), r = H(t, o);
|
|
4
|
+
return {
|
|
5
|
+
systemHeader: n,
|
|
6
|
+
localHeader: e,
|
|
7
|
+
numberNodes: o,
|
|
8
|
+
mainNodes: r
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
function L(t) {
|
|
12
|
+
let e = 0;
|
|
13
|
+
const o = t.toString("ascii", e, e + 6);
|
|
14
|
+
if (e += 6, o !== "SRPATH")
|
|
15
|
+
throw new Error("Invalid File (SRPATH not found)");
|
|
16
|
+
const r = t.readUInt8(e++), c = t.readUInt8(e++);
|
|
17
|
+
if (r > 0 || c > 252)
|
|
18
|
+
throw new Error("Wrong version");
|
|
19
|
+
const i = t.readInt32LE(e);
|
|
20
|
+
return {
|
|
21
|
+
version: r,
|
|
22
|
+
revision: c,
|
|
23
|
+
flags: i
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
function w(t) {
|
|
27
|
+
return {
|
|
28
|
+
miniRev: t.readUInt8(12)
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
function N(t) {
|
|
32
|
+
const e = t.readUInt16LE(16);
|
|
33
|
+
if (e <= 0) throw new Error("The number of nodes is too low");
|
|
34
|
+
return e;
|
|
35
|
+
}
|
|
36
|
+
function y(t, n) {
|
|
37
|
+
return {
|
|
38
|
+
centre: {
|
|
39
|
+
x: n.readInt32LE(t + 4),
|
|
40
|
+
y: n.readInt32LE(t + 8)
|
|
41
|
+
},
|
|
42
|
+
dir: {
|
|
43
|
+
x: n.readFloatLE(t + 16),
|
|
44
|
+
y: n.readFloatLE(t + 20)
|
|
45
|
+
},
|
|
46
|
+
limits: {
|
|
47
|
+
driveLeft: n.readFloatLE(t + 36),
|
|
48
|
+
driveRight: n.readFloatLE(t + 40)
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
function H(t, n) {
|
|
53
|
+
const r = [];
|
|
54
|
+
for (let c = 0; c < n; c++) {
|
|
55
|
+
const i = 56 + 44 * c;
|
|
56
|
+
r[c] = y(i, t);
|
|
57
|
+
}
|
|
58
|
+
return r;
|
|
59
|
+
}
|
|
60
|
+
function M(t) {
|
|
61
|
+
const n = T.readFileSync(t);
|
|
62
|
+
if (n === void 0)
|
|
63
|
+
throw new Error("Invalid File");
|
|
64
|
+
return n;
|
|
65
|
+
}
|
|
66
|
+
const s = 65536, R = 16, x = s / R;
|
|
67
|
+
function A(t, n) {
|
|
68
|
+
const i = [], a = n < 180 ? n : 180, d = n / a;
|
|
69
|
+
for (let l = 0; l < a; l++) {
|
|
70
|
+
const F = Math.round(d * l), E = t[F], _ = D(E.dir.x, E.dir.y), u = m(E), I = U(u), f = P(u), O = h(f.x), S = h(f.y);
|
|
71
|
+
i.push({
|
|
72
|
+
x: O,
|
|
73
|
+
y: S,
|
|
74
|
+
z: 240,
|
|
75
|
+
flags: I << 2 | 1,
|
|
76
|
+
index: 252,
|
|
77
|
+
heading: _
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
return i;
|
|
81
|
+
}
|
|
82
|
+
function h(t) {
|
|
83
|
+
return Math.round(t / x);
|
|
84
|
+
}
|
|
85
|
+
function D(t, n) {
|
|
86
|
+
const o = Math.atan2(n, t) * (180 / Math.PI);
|
|
87
|
+
return Math.round((o - 90 + 180) * 256 / 360) & 255;
|
|
88
|
+
}
|
|
89
|
+
function m(t) {
|
|
90
|
+
const n = -t.dir.y, e = t.dir.x, o = {
|
|
91
|
+
x: t.centre.x - n * t.limits.driveLeft * s,
|
|
92
|
+
y: t.centre.y - e * t.limits.driveLeft * s
|
|
93
|
+
}, r = {
|
|
94
|
+
x: t.centre.x - n * t.limits.driveRight * s,
|
|
95
|
+
y: t.centre.y - e * t.limits.driveRight * s
|
|
96
|
+
};
|
|
97
|
+
return { left: o, right: r };
|
|
98
|
+
}
|
|
99
|
+
function P(t) {
|
|
100
|
+
const n = (t.right.x + t.left.x) / 2, e = (t.right.y + t.left.y) / 2;
|
|
101
|
+
return { x: n, y: e };
|
|
102
|
+
}
|
|
103
|
+
function U(t, n = 2) {
|
|
104
|
+
const e = Math.pow(
|
|
105
|
+
t.right.x - t.left.x,
|
|
106
|
+
2
|
|
107
|
+
), o = Math.pow(
|
|
108
|
+
t.right.y - t.left.y,
|
|
109
|
+
2
|
|
110
|
+
), r = Math.sqrt(e + o), c = Math.round(
|
|
111
|
+
r / s / 2 + n
|
|
112
|
+
);
|
|
113
|
+
return c > 31 ? 31 : c;
|
|
114
|
+
}
|
|
115
|
+
function Y(t, n) {
|
|
116
|
+
const e = p(
|
|
117
|
+
n.length
|
|
118
|
+
), o = C(n), r = [e, o], c = Buffer.concat(r);
|
|
119
|
+
T.writeFileSync(t, c);
|
|
120
|
+
}
|
|
121
|
+
function p(t) {
|
|
122
|
+
const n = Buffer.alloc(12);
|
|
123
|
+
return n.write("LFSLYT", 0, "ascii"), n.writeUInt8(0, 6), n.writeUInt8(252, 7), n.writeUInt16LE(t, 8), n.writeUInt8(0, 10), n.writeUInt8(9, 11), n;
|
|
124
|
+
}
|
|
125
|
+
function C(t) {
|
|
126
|
+
const n = Buffer.alloc(8 * t.length);
|
|
127
|
+
let e = 0;
|
|
128
|
+
for (let o = 0; o < t.length; o++) {
|
|
129
|
+
const r = t[o];
|
|
130
|
+
n.writeInt16LE(r.x, e), e += 2, n.writeInt16LE(r.y, e), e += 2, n.writeUInt8(r.z, e), e++, n.writeUInt8(r.flags, e), e++, n.writeUInt8(r.index, e), e++, n.writeUInt8(r.heading, e), e++;
|
|
131
|
+
}
|
|
132
|
+
return n;
|
|
133
|
+
}
|
|
134
|
+
function B(t, n, e, o) {
|
|
135
|
+
const r = `${t}/${e}.pth`, c = `${n}/${e}_${o}.lyt`, i = M(r), a = g(i), d = A(
|
|
136
|
+
a.mainNodes,
|
|
137
|
+
a.numberNodes
|
|
138
|
+
);
|
|
139
|
+
Y(c, d);
|
|
140
|
+
}
|
|
141
|
+
export {
|
|
142
|
+
B as convertPTHtoLYT
|
|
143
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PTH.parser.d.ts","sourceRoot":"","sources":["../../src/input/PTH.parser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAwB,GAAG,EAAgB,MAAM,SAAS,CAAC;AAElE,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,WAAW,CAAC,GAAG,GAAG,CAY1D"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PTH.reader.d.ts","sourceRoot":"","sources":["../../src/input/PTH.reader.ts"],"names":[],"mappings":"AAEA,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,WAAW,CAAC,CAOzD"}
|
package/dist/input/types.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/input/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,GAAG,GAAG;IACd,YAAY,EAAE,YAAY,CAAC;IAC3B,WAAW,EAAE,WAAW,CAAC;IACzB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,OAAO,EAAE,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IACtB,OAAO,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,OAAO,GAAG;IAClB,MAAM,EAAE;QACJ,CAAC,EAAE,MAAM,CAAC;QACV,CAAC,EAAE,MAAM,CAAC;KACb,CAAC;IACF,GAAG,EAAE;QACD,CAAC,EAAE,MAAM,CAAC;QACV,CAAC,EAAE,MAAM,CAAC;KACb,CAAC;IACF,MAAM,EAAE;QACJ,SAAS,EAAE,MAAM,CAAC;QAClB,UAAU,EAAE,MAAM,CAAC;KACtB,CAAC;CACL,CAAC"}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import { PTHNode } from
|
|
2
|
-
import { DriveLimits, LYTObject, Vector2 } from
|
|
1
|
+
import { PTHNode } from '../input/types';
|
|
2
|
+
import { DriveLimits, LYTObject, Vector2 } from './types';
|
|
3
|
+
|
|
3
4
|
export declare function transformLYT(nodes: PTHNode[], numberNodes: number): LYTObject[];
|
|
4
5
|
export declare function transformLYTObjectPosition(value: number): number;
|
|
5
6
|
export declare function calculateHeading(dirX: number, dirY: number): number;
|
|
6
7
|
export declare function calculateDriveLimits(node: PTHNode): DriveLimits;
|
|
7
8
|
export declare function calculateMidPoint(driveLimits: DriveLimits): Vector2;
|
|
8
9
|
export declare function calculateHalfWidth(driveLimits: DriveLimits, widthOffset?: number): number;
|
|
10
|
+
//# sourceMappingURL=LYT.transform.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LYT.transform.d.ts","sourceRoot":"","sources":["../../src/output/LYT.transform.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAW1D,wBAAgB,YAAY,CACxB,KAAK,EAAE,OAAO,EAAE,EAChB,WAAW,EAAE,MAAM,GACpB,SAAS,EAAE,CAiCb;AAED,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAEhE;AAED,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAQnE;AAED,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,OAAO,GAAG,WAAW,CAoB/D;AAED,wBAAgB,iBAAiB,CAAC,WAAW,EAAE,WAAW,GAAG,OAAO,CAKnE;AAGD,wBAAgB,kBAAkB,CAC9B,WAAW,EAAE,WAAW,EACxB,WAAW,GAAE,MAAU,GACxB,MAAM,CAeR"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LYT.writer.d.ts","sourceRoot":"","sources":["../../src/output/LYT.writer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEpC,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,SAAS,EAAE,QAU9D"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/output/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,SAAS,EAAE,MAAc,CAAC;AACvC,eAAO,MAAM,SAAS,EAAE,MAAW,CAAC;AACpC,eAAO,MAAM,aAAa,EAAE,MAA8B,CAAC"}
|
package/dist/output/types.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/output/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GAAG;IACpB,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,OAAO,GAAG;IAClB,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;CACb,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IACtB,KAAK,EAAE,OAAO,CAAC;IACf,IAAI,EAAE,OAAO,CAAC;CACjB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,15 +1,28 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pth_to_lyt",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "1.0.3",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/index.cjs",
|
|
6
|
+
"module": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"require": "./dist/index.cjs",
|
|
12
|
+
"types": "./dist/index.d.ts"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
6
18
|
"scripts": {
|
|
7
|
-
"build": "
|
|
19
|
+
"build": "vite build",
|
|
20
|
+
"dev": "vite build --watch"
|
|
8
21
|
},
|
|
9
22
|
"devDependencies": {
|
|
10
|
-
"@types/node": "^
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
"
|
|
23
|
+
"@types/node": "^25.0.9",
|
|
24
|
+
"typescript": "^5.0.0",
|
|
25
|
+
"vite": "^5.0.0",
|
|
26
|
+
"vite-plugin-dts": "^3.0.0"
|
|
14
27
|
}
|
|
15
28
|
}
|
package/dist/core/PTHToLYT.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.convertPTHtoLYT = convertPTHtoLYT;
|
|
4
|
-
const PTH_parser_1 = require("../input/PTH.parser");
|
|
5
|
-
const PTH_reader_1 = require("../input/PTH.reader");
|
|
6
|
-
const LYT_transform_1 = require("../output/LYT.transform");
|
|
7
|
-
const LYT_writer_1 = require("../output/LYT.writer");
|
|
8
|
-
/** Generate a .lyt file */
|
|
9
|
-
function convertPTHtoLYT(pthFolderPath, lytFolderPath, trackPrefix, lytName) {
|
|
10
|
-
const pthPath = `${pthFolderPath}/${trackPrefix}.pth`;
|
|
11
|
-
const lytPath = `${lytFolderPath}/${trackPrefix}_${lytName}.lyt`;
|
|
12
|
-
const raw = (0, PTH_reader_1.readPTH)(pthPath);
|
|
13
|
-
const data = (0, PTH_parser_1.parserPTH)(raw);
|
|
14
|
-
const objectArray = (0, LYT_transform_1.transformLYT)(data.mainNodes, data.numberNodes);
|
|
15
|
-
(0, LYT_writer_1.writeLYT)(lytPath, objectArray);
|
|
16
|
-
}
|
package/dist/input/PTH.parser.js
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parserPTH = parserPTH;
|
|
4
|
-
function parserPTH(buffer) {
|
|
5
|
-
const systemHeader = readSystemHeader(buffer);
|
|
6
|
-
const localHeader = readLocalHeader(buffer);
|
|
7
|
-
const numberNodes = readNumberNodes(buffer);
|
|
8
|
-
const mainNodes = readMainNodes(buffer, numberNodes);
|
|
9
|
-
return {
|
|
10
|
-
systemHeader,
|
|
11
|
-
localHeader,
|
|
12
|
-
numberNodes,
|
|
13
|
-
mainNodes,
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
function readSystemHeader(buffer) {
|
|
17
|
-
const SYSTEM_HEADER_OFFSET = 0;
|
|
18
|
-
let offset = SYSTEM_HEADER_OFFSET;
|
|
19
|
-
const magic = buffer.toString("ascii", offset, offset + 6);
|
|
20
|
-
offset += 6;
|
|
21
|
-
if (magic !== "SRPATH") {
|
|
22
|
-
throw new Error("Invalid File (SRPATH not found)");
|
|
23
|
-
}
|
|
24
|
-
const version = buffer.readUInt8(offset++);
|
|
25
|
-
const revision = buffer.readUInt8(offset++);
|
|
26
|
-
if (version > 0 || revision > 252) {
|
|
27
|
-
throw new Error("Wrong version");
|
|
28
|
-
}
|
|
29
|
-
const flags = buffer.readInt32LE(offset);
|
|
30
|
-
return {
|
|
31
|
-
version,
|
|
32
|
-
revision,
|
|
33
|
-
flags,
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
function readLocalHeader(buffer) {
|
|
37
|
-
const LOCAL_HEADER_OFFSET = 12;
|
|
38
|
-
const miniRev = buffer.readUInt8(LOCAL_HEADER_OFFSET);
|
|
39
|
-
return {
|
|
40
|
-
miniRev,
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
function readNumberNodes(buffer) {
|
|
44
|
-
const NUMBER_NODES_OFFSET = 16;
|
|
45
|
-
const numberNodes = buffer.readUInt16LE(NUMBER_NODES_OFFSET);
|
|
46
|
-
if (numberNodes <= 0)
|
|
47
|
-
throw new Error("The number of nodes is too low");
|
|
48
|
-
return numberNodes;
|
|
49
|
-
}
|
|
50
|
-
function readNode(offset, buffer) {
|
|
51
|
-
const node = {
|
|
52
|
-
centre: {
|
|
53
|
-
x: buffer.readInt32LE(offset + 4),
|
|
54
|
-
y: buffer.readInt32LE(offset + 8),
|
|
55
|
-
},
|
|
56
|
-
dir: {
|
|
57
|
-
x: buffer.readFloatLE(offset + 16),
|
|
58
|
-
y: buffer.readFloatLE(offset + 20),
|
|
59
|
-
},
|
|
60
|
-
limits: {
|
|
61
|
-
driveLeft: buffer.readFloatLE(offset + 36),
|
|
62
|
-
driveRight: buffer.readFloatLE(offset + 40),
|
|
63
|
-
},
|
|
64
|
-
};
|
|
65
|
-
return node;
|
|
66
|
-
}
|
|
67
|
-
function readMainNodes(buffer, length) {
|
|
68
|
-
const MAIN_NODES_OFFSET = 56;
|
|
69
|
-
const PTH_NODE_OFFSET = 44;
|
|
70
|
-
const nodes = [];
|
|
71
|
-
for (let i = 0; i < length; i++) {
|
|
72
|
-
const offset = MAIN_NODES_OFFSET + PTH_NODE_OFFSET * i;
|
|
73
|
-
nodes[i] = readNode(offset, buffer);
|
|
74
|
-
}
|
|
75
|
-
return nodes;
|
|
76
|
-
}
|
package/dist/input/PTH.reader.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.readPTH = readPTH;
|
|
7
|
-
const fs_1 = __importDefault(require("fs"));
|
|
8
|
-
function readPTH(path) {
|
|
9
|
-
const buffer = fs_1.default.readFileSync(path);
|
|
10
|
-
if (buffer === undefined) {
|
|
11
|
-
throw new Error("Invalid File");
|
|
12
|
-
}
|
|
13
|
-
return buffer;
|
|
14
|
-
}
|
package/dist/input/types.js
DELETED
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.transformLYT = transformLYT;
|
|
4
|
-
exports.transformLYTObjectPosition = transformLYTObjectPosition;
|
|
5
|
-
exports.calculateHeading = calculateHeading;
|
|
6
|
-
exports.calculateDriveLimits = calculateDriveLimits;
|
|
7
|
-
exports.calculateMidPoint = calculateMidPoint;
|
|
8
|
-
exports.calculateHalfWidth = calculateHalfWidth;
|
|
9
|
-
const constants_1 = require("./constants");
|
|
10
|
-
// LFS NOTATION
|
|
11
|
-
// 0 = world y axis direction
|
|
12
|
-
// LYT NOTATION
|
|
13
|
-
// 128 : heading of zero
|
|
14
|
-
// 192 : heading of 90 degrees
|
|
15
|
-
// 0 : heading of 180 degrees
|
|
16
|
-
// 64 : heading of -90 degrees
|
|
17
|
-
function transformLYT(nodes, numberNodes) {
|
|
18
|
-
const ZBYTE = 240;
|
|
19
|
-
const CHECKPOINT_INDEX = 252;
|
|
20
|
-
const FIRST_CHECKPOINT_FLAG = 0x01;
|
|
21
|
-
const MAX_NODE = 180;
|
|
22
|
-
const objectArray = [];
|
|
23
|
-
const length = numberNodes < MAX_NODE ? numberNodes : MAX_NODE;
|
|
24
|
-
const gap = numberNodes / length;
|
|
25
|
-
for (let i = 0; i < length; i++) {
|
|
26
|
-
const nodeIndex = Math.round(gap * i);
|
|
27
|
-
const node = nodes[nodeIndex];
|
|
28
|
-
const heading = calculateHeading(node.dir.x, node.dir.y);
|
|
29
|
-
const driveLimits = calculateDriveLimits(node);
|
|
30
|
-
const halfWidth = calculateHalfWidth(driveLimits);
|
|
31
|
-
const midPoint = calculateMidPoint(driveLimits);
|
|
32
|
-
const lytObjectX = transformLYTObjectPosition(midPoint.x);
|
|
33
|
-
const lytObjectY = transformLYTObjectPosition(midPoint.y);
|
|
34
|
-
objectArray.push({
|
|
35
|
-
x: lytObjectX,
|
|
36
|
-
y: lytObjectY,
|
|
37
|
-
z: ZBYTE,
|
|
38
|
-
flags: (halfWidth << 2) | FIRST_CHECKPOINT_FLAG,
|
|
39
|
-
index: CHECKPOINT_INDEX,
|
|
40
|
-
heading: heading,
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
return objectArray;
|
|
44
|
-
}
|
|
45
|
-
function transformLYTObjectPosition(value) {
|
|
46
|
-
return Math.round(value / constants_1.SCALAR_FACTOR);
|
|
47
|
-
}
|
|
48
|
-
function calculateHeading(dirX, dirY) {
|
|
49
|
-
const angleRadians = Math.atan2(dirY, dirX);
|
|
50
|
-
const angleDegrees = angleRadians * (180 / Math.PI);
|
|
51
|
-
//"Heading represents 360 degrees in 256 values."
|
|
52
|
-
const heading = Math.round(((angleDegrees - 90 + 180) * 256) / 360) & 0xff;
|
|
53
|
-
return heading;
|
|
54
|
-
}
|
|
55
|
-
function calculateDriveLimits(node) {
|
|
56
|
-
// "A node is represented by a line perpendicular to its direction."
|
|
57
|
-
// perpendicular = 90 degrees
|
|
58
|
-
// rotate 90 degrees to left for find drive limits direct
|
|
59
|
-
const perpendicularX = -node.dir.y;
|
|
60
|
-
const perpendicularY = node.dir.x;
|
|
61
|
-
// driveLeft negative
|
|
62
|
-
// driveRight positive
|
|
63
|
-
const left = {
|
|
64
|
-
x: node.centre.x - perpendicularX * node.limits.driveLeft * constants_1.LFS_METER,
|
|
65
|
-
y: node.centre.y - perpendicularY * node.limits.driveLeft * constants_1.LFS_METER,
|
|
66
|
-
};
|
|
67
|
-
const right = {
|
|
68
|
-
x: node.centre.x - perpendicularX * node.limits.driveRight * constants_1.LFS_METER,
|
|
69
|
-
y: node.centre.y - perpendicularY * node.limits.driveRight * constants_1.LFS_METER,
|
|
70
|
-
};
|
|
71
|
-
return { left, right };
|
|
72
|
-
}
|
|
73
|
-
function calculateMidPoint(driveLimits) {
|
|
74
|
-
const x = (driveLimits.right.x + driveLimits.left.x) / 2;
|
|
75
|
-
const y = (driveLimits.right.y + driveLimits.left.y) / 2;
|
|
76
|
-
return { x, y };
|
|
77
|
-
}
|
|
78
|
-
// "half width in metres (1 to 31 ...)."
|
|
79
|
-
function calculateHalfWidth(driveLimits, widthOffset = 2) {
|
|
80
|
-
const distanceX = Math.pow(driveLimits.right.x - driveLimits.left.x, 2);
|
|
81
|
-
const distanceY = Math.pow(driveLimits.right.y - driveLimits.left.y, 2);
|
|
82
|
-
const distance = Math.sqrt(distanceX + distanceY);
|
|
83
|
-
const halfWidth = Math.round(distance / constants_1.LFS_METER / 2 + widthOffset);
|
|
84
|
-
return halfWidth > 31 ? 31 : halfWidth;
|
|
85
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.writeLYT = writeLYT;
|
|
7
|
-
const fs_1 = __importDefault(require("fs"));
|
|
8
|
-
function writeLYT(path, objectArray) {
|
|
9
|
-
const bufferHeader = buildBufferHeader(objectArray.length);
|
|
10
|
-
const bufferObjects = buildBufferLYTObject(objectArray);
|
|
11
|
-
const bufferList = [bufferHeader, bufferObjects];
|
|
12
|
-
const buffer = Buffer.concat(bufferList);
|
|
13
|
-
fs_1.default.writeFileSync(path, buffer);
|
|
14
|
-
}
|
|
15
|
-
function buildBufferHeader(length) {
|
|
16
|
-
const buffer = Buffer.alloc(12);
|
|
17
|
-
buffer.write("LFSLYT", 0, "ascii");
|
|
18
|
-
buffer.writeUInt8(0, 6);
|
|
19
|
-
buffer.writeUInt8(252, 7);
|
|
20
|
-
buffer.writeUInt16LE(length, 8);
|
|
21
|
-
buffer.writeUInt8(0, 10);
|
|
22
|
-
buffer.writeUInt8(9, 11);
|
|
23
|
-
return buffer;
|
|
24
|
-
}
|
|
25
|
-
function buildBufferLYTObject(objectArray) {
|
|
26
|
-
const buffer = Buffer.alloc(8 * objectArray.length);
|
|
27
|
-
let offset = 0;
|
|
28
|
-
for (let i = 0; i < objectArray.length; i++) {
|
|
29
|
-
const object = objectArray[i];
|
|
30
|
-
buffer.writeInt16LE(object.x, offset);
|
|
31
|
-
offset += 2;
|
|
32
|
-
buffer.writeInt16LE(object.y, offset);
|
|
33
|
-
offset += 2;
|
|
34
|
-
buffer.writeUInt8(object.z, offset);
|
|
35
|
-
offset++;
|
|
36
|
-
buffer.writeUInt8(object.flags, offset);
|
|
37
|
-
offset++;
|
|
38
|
-
buffer.writeUInt8(object.index, offset);
|
|
39
|
-
offset++;
|
|
40
|
-
buffer.writeUInt8(object.heading, offset);
|
|
41
|
-
offset++;
|
|
42
|
-
}
|
|
43
|
-
return buffer;
|
|
44
|
-
}
|
package/dist/output/constants.js
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SCALAR_FACTOR = exports.LYT_METER = exports.LFS_METER = void 0;
|
|
4
|
-
exports.LFS_METER = 65536; // 1m
|
|
5
|
-
exports.LYT_METER = 16; // 1m
|
|
6
|
-
exports.SCALAR_FACTOR = exports.LFS_METER / exports.LYT_METER;
|
package/dist/output/types.js
DELETED