diff --git a/packages/node-border/src/shader-frag.ts b/packages/node-border/src/shader-frag.ts index 3856a1277..c4594bc25 100644 --- a/packages/node-border/src/shader-frag.ts +++ b/packages/node-border/src/shader-frag.ts @@ -1,4 +1,6 @@ -import { CreateNodeBorderProgramOptions, DEFAULT_BORDER_SIZE_MODE, NodeBorderSize, numberToGLSLFloat } from "./utils"; +import { numberToGLSLFloat } from "sigma/rendering"; + +import { CreateNodeBorderProgramOptions, DEFAULT_BORDER_SIZE_MODE, NodeBorderSize } from "./utils"; export default function getFragmentShader({ borders }: CreateNodeBorderProgramOptions) { const fillCounts = numberToGLSLFloat(borders.filter(({ size }) => "fill" in size).length); diff --git a/packages/node-border/src/utils.ts b/packages/node-border/src/utils.ts index 1be8b370c..58b6a2357 100644 --- a/packages/node-border/src/utils.ts +++ b/packages/node-border/src/utils.ts @@ -22,7 +22,3 @@ export const DEFAULT_CREATE_NODE_BORDER_OPTIONS: CreateNodeBorderProgramOptions }; export const DEFAULT_COLOR = "#000000"; - -export function numberToGLSLFloat(n: number): string { - return n % 1 === 0 ? n.toFixed(1) : n.toString(); -} diff --git a/packages/node-piechart/src/shader-frag.ts b/packages/node-piechart/src/shader-frag.ts index cb45db8be..7b80546ca 100644 --- a/packages/node-piechart/src/shader-frag.ts +++ b/packages/node-piechart/src/shader-frag.ts @@ -1,4 +1,6 @@ -import { CreateNodePiechartProgramOptions, numberToGLSLFloat } from "./utils"; +import { numberToGLSLFloat } from "sigma/rendering"; + +import { CreateNodePiechartProgramOptions } from "./utils"; export default function getFragmentShader({ slices, offset }: CreateNodePiechartProgramOptions) { // language=GLSL diff --git a/packages/node-piechart/src/utils.ts b/packages/node-piechart/src/utils.ts index e162247e0..126cf317c 100644 --- a/packages/node-piechart/src/utils.ts +++ b/packages/node-piechart/src/utils.ts @@ -18,7 +18,3 @@ export const DEFAULT_CREATE_NODE_PIECHART_OPTIONS: Omit { + describe("numberToGLSLFloat", () => { + test('it should properly print all kind of numbers to "GLSL float" strings', () => { + const tests: [number, string][] = [ + [1, "1.0"], + [123, "123.0"], + [1.23, "1.23"], + [0.123, "0.123"], + [1230, "1230.0"], + [12300, "12300.0"], + [1e-6, "0.000001"], + [1e6, "1000000.0"], + ]; + + tests.forEach(([input, expectedOutput]) => expect(numberToGLSLFloat(input)).toBe(expectedOutput)); + }); + }); +});