@nossen/morphing 2.0.1 → 2.0.2
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/morph.d.ts +21 -2
- package/dist/morph.js +60 -14
- package/package.json +1 -1
package/dist/morph.d.ts
CHANGED
|
@@ -26,6 +26,13 @@ export declare function data24Of(m: morph): number;
|
|
|
26
26
|
/** Int24 helper */
|
|
27
27
|
export declare function fromInt24(value: number, subtype?: number): morph;
|
|
28
28
|
export declare function toInt24(m: morph): number;
|
|
29
|
+
/** Quantized fixed-point float helper.
|
|
30
|
+
*
|
|
31
|
+
* FloatQ stores a signed 24-bit integer equal to value * scale. The scale is
|
|
32
|
+
* caller-selected so transport stays compact and deterministic.
|
|
33
|
+
*/
|
|
34
|
+
export declare function fromFloatQ(value: number, subtype?: number, scale?: number): morph;
|
|
35
|
+
export declare function toFloatQ(m: morph, scale?: number): number;
|
|
29
36
|
/** Signed Int24 helper */
|
|
30
37
|
export declare function fromSignedInt24(value: number, subtype?: number): morph;
|
|
31
38
|
export declare function toSignedInt24(m: morph): number;
|
|
@@ -51,7 +58,18 @@ export declare const enum MorphSpace {
|
|
|
51
58
|
Six = 6,
|
|
52
59
|
Enigma = 7
|
|
53
60
|
}
|
|
54
|
-
export
|
|
61
|
+
export type MorphRefSpaceTable = any[] & {
|
|
62
|
+
readonly space: MorphSpace;
|
|
63
|
+
readonly name: string;
|
|
64
|
+
readonly description: string;
|
|
65
|
+
};
|
|
66
|
+
export type MorphRefSpaceDescription = {
|
|
67
|
+
id: MorphSpace;
|
|
68
|
+
name: string;
|
|
69
|
+
description: string;
|
|
70
|
+
size: number;
|
|
71
|
+
};
|
|
72
|
+
export declare const MorphRefSpaces: MorphRefSpaceTable[];
|
|
55
73
|
export declare function subtypeToSpace(subtype: number): MorphSpace;
|
|
56
74
|
export declare function subtypeToLocalTag(subtype: number): number;
|
|
57
75
|
/** Crée un morph REF dans un espace donné */
|
|
@@ -92,7 +110,8 @@ export declare function resolvePorygon(p: Porygon): any;
|
|
|
92
110
|
/** Cube helpers for higher-level Freeland / RGBA tooling */
|
|
93
111
|
export declare function cubeToRef(cube: MorphCube, space?: MorphSpace, localTag?: number): morph;
|
|
94
112
|
export declare function refToCube(m: morph): MorphCube | undefined;
|
|
95
|
-
export declare const MORPHING_VERSION = "0.1.
|
|
113
|
+
export declare const MORPHING_VERSION = "0.1.6";
|
|
96
114
|
export declare function isMorph(x: any): x is morph;
|
|
115
|
+
export declare function describeRefSpaces(): MorphRefSpaceDescription[];
|
|
97
116
|
export declare function clearSpace(space: MorphSpace): void;
|
|
98
117
|
export declare function clearAllSpaces(): void;
|
package/dist/morph.js
CHANGED
|
@@ -34,17 +34,35 @@ export function fromInt24(value, subtype = 0) {
|
|
|
34
34
|
export function toInt24(m) {
|
|
35
35
|
return data24Of(m);
|
|
36
36
|
}
|
|
37
|
+
/** Quantized fixed-point float helper.
|
|
38
|
+
*
|
|
39
|
+
* FloatQ stores a signed 24-bit integer equal to value * scale. The scale is
|
|
40
|
+
* caller-selected so transport stays compact and deterministic.
|
|
41
|
+
*/
|
|
42
|
+
export function fromFloatQ(value, subtype = 0, scale = 1000) {
|
|
43
|
+
if (!Number.isFinite(value)) {
|
|
44
|
+
throw new RangeError("FloatQ value must be finite");
|
|
45
|
+
}
|
|
46
|
+
if (!Number.isFinite(scale) || scale <= 0) {
|
|
47
|
+
throw new RangeError("FloatQ scale must be a positive finite number");
|
|
48
|
+
}
|
|
49
|
+
return makeMorph(MorphKind.FloatQ, subtype, encodeSigned24(Math.round(value * scale)));
|
|
50
|
+
}
|
|
51
|
+
export function toFloatQ(m, scale = 1000) {
|
|
52
|
+
if (!Number.isFinite(scale) || scale <= 0) {
|
|
53
|
+
throw new RangeError("FloatQ scale must be a positive finite number");
|
|
54
|
+
}
|
|
55
|
+
return decodeSigned24(data24Of(m)) / scale;
|
|
56
|
+
}
|
|
37
57
|
/** Signed Int24 helper */
|
|
38
58
|
export function fromSignedInt24(value, subtype = 0) {
|
|
39
59
|
if (!Number.isInteger(value) || value < -0x800000 || value > 0x7FFFFF) {
|
|
40
60
|
throw new RangeError("signed Int24 value must be between -8388608 and 8388607");
|
|
41
61
|
}
|
|
42
|
-
|
|
43
|
-
return makeMorph(MorphKind.Int24, subtype, encoded);
|
|
62
|
+
return makeMorph(MorphKind.Int24, subtype, encodeSigned24(value));
|
|
44
63
|
}
|
|
45
64
|
export function toSignedInt24(m) {
|
|
46
|
-
|
|
47
|
-
return (raw & 0x800000) !== 0 ? raw - 0x1000000 : raw;
|
|
65
|
+
return decodeSigned24(data24Of(m));
|
|
48
66
|
}
|
|
49
67
|
/** Bool / flag helper */
|
|
50
68
|
export function fromFlag(flag, subtype = 0) {
|
|
@@ -105,16 +123,26 @@ export function uint32ToMorph(v) {
|
|
|
105
123
|
d3: v & 0xFF,
|
|
106
124
|
};
|
|
107
125
|
}
|
|
108
|
-
|
|
126
|
+
function makeRefSpace(space, name, description) {
|
|
127
|
+
const table = [];
|
|
128
|
+
Object.defineProperties(table, {
|
|
129
|
+
space: { value: space, enumerable: false },
|
|
130
|
+
name: { value: name, enumerable: false },
|
|
131
|
+
description: { value: description, enumerable: false },
|
|
132
|
+
});
|
|
133
|
+
return table;
|
|
134
|
+
}
|
|
135
|
+
// 8 espaces max (0-7). Les tableaux restent indexables comme avant, mais
|
|
136
|
+
// portent maintenant une identite stable pour inspection et documentation.
|
|
109
137
|
export const MorphRefSpaces = [
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
138
|
+
makeRefSpace(0 /* MorphSpace.Global */, "global", "Process-local shared references."),
|
|
139
|
+
makeRefSpace(1 /* MorphSpace.QFlush */, "qflush", "QFlush orchestration references."),
|
|
140
|
+
makeRefSpace(2 /* MorphSpace.Spyder */, "spyder", "Spyder packet and memory references."),
|
|
141
|
+
makeRefSpace(3 /* MorphSpace.A11 */, "a11", "A11 agent/runtime references."),
|
|
142
|
+
makeRefSpace(4 /* MorphSpace.Nossen */, "nossen", "NOSSEN package-level references."),
|
|
143
|
+
makeRefSpace(5 /* MorphSpace.Five */, "five", "Reserved reference space 5."),
|
|
144
|
+
makeRefSpace(6 /* MorphSpace.Six */, "six", "Reserved reference space 6."),
|
|
145
|
+
makeRefSpace(7 /* MorphSpace.Enigma */, "enigma", "Private Enigma references."),
|
|
118
146
|
];
|
|
119
147
|
function makeSubtype(space, localTag) {
|
|
120
148
|
if (localTag < 0 || localTag > 0b000111) {
|
|
@@ -242,7 +270,7 @@ export function refToCube(m) {
|
|
|
242
270
|
return undefined;
|
|
243
271
|
}
|
|
244
272
|
// --- Version ---
|
|
245
|
-
export const MORPHING_VERSION = "0.1.
|
|
273
|
+
export const MORPHING_VERSION = "0.1.6";
|
|
246
274
|
// --- Type guard ---
|
|
247
275
|
export function isMorph(x) {
|
|
248
276
|
return (x != null &&
|
|
@@ -257,6 +285,24 @@ function getSpaceTable(space) {
|
|
|
257
285
|
const idx = space & 0b00000111;
|
|
258
286
|
return MorphRefSpaces[idx] ?? MorphRefSpaces[0];
|
|
259
287
|
}
|
|
288
|
+
function encodeSigned24(value) {
|
|
289
|
+
if (!Number.isInteger(value) || value < -0x800000 || value > 0x7FFFFF) {
|
|
290
|
+
throw new RangeError("signed 24-bit value must be between -8388608 and 8388607");
|
|
291
|
+
}
|
|
292
|
+
return value < 0 ? value + 0x1000000 : value;
|
|
293
|
+
}
|
|
294
|
+
function decodeSigned24(value) {
|
|
295
|
+
const unsigned = value & 0xFFFFFF;
|
|
296
|
+
return (unsigned & 0x800000) ? unsigned - 0x1000000 : unsigned;
|
|
297
|
+
}
|
|
298
|
+
export function describeRefSpaces() {
|
|
299
|
+
return MorphRefSpaces.map((table, index) => ({
|
|
300
|
+
id: index,
|
|
301
|
+
name: table.name,
|
|
302
|
+
description: table.description,
|
|
303
|
+
size: table.length,
|
|
304
|
+
}));
|
|
305
|
+
}
|
|
260
306
|
export function clearSpace(space) {
|
|
261
307
|
const table = getSpaceTable(space);
|
|
262
308
|
table.length = 0;
|
package/package.json
CHANGED