diff --git a/src/lib/converters.ts b/src/lib/converters.ts index ec6ab56..bff0ad7 100644 --- a/src/lib/converters.ts +++ b/src/lib/converters.ts @@ -52,9 +52,9 @@ export function poseToWandelscriptString( pose.orientation?.z ?? 0, ] - const positionValues = position.map((v) => parseFloat(v.toFixed(1))) + const positionValues = position.map((v) => v.toFixed(1)) // Rotation needs more precision since it's in radians - const rotationValues = orientation.map((v) => parseFloat(v.toFixed(4))) + const rotationValues = orientation.map((v) => v.toFixed(4)) return `(${positionValues.concat(rotationValues).join(", ")})` } diff --git a/test/utils.test.ts b/test/utils.test.ts index ebcae27..c96f35e 100644 --- a/test/utils.test.ts +++ b/test/utils.test.ts @@ -3,11 +3,20 @@ import { expect, test } from "vitest" import { poseToWandelscriptString } from "../dist" -test("utility functions", async () => { +test("pose string has right precision", async () => { expect( poseToWandelscriptString({ position: { x: 1, y: 2, z: 3 }, orientation: { x: 4, y: 5, z: 6 }, }), - ).toBe("(1, 2, 3, 4, 5, 6)") + ).toBe("(1.0, 2.0, 3.0, 4.0000, 5.0000, 6.0000)") +}) + +test("pose string rounds correctly", async () => { + expect( + poseToWandelscriptString({ + position: { x: 1, y: 2.22, z: 3.556 }, + orientation: { x: 2, y: 3.3333, z: 1.55559 }, + }), + ).toBe("(1.0, 2.2, 3.6, 2.0000, 3.3333, 1.5556)") })