Skip to content

Commit

Permalink
Round (x,y) to nearest 3 decimal point
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrySky committed Jul 12, 2022
1 parent 8df4d89 commit 64a837a
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/components/xircuitBodyWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -190,12 +190,17 @@ export const BodyWidget: FC<BodyWidgetProps> = ({
if (contextRef.current.isReady) {
let currentModel = xircuitsApp.getDiagramEngine().getModel().serialize();
contextRef.current.model.fromString(
JSON.stringify(currentModel, null, 4)
JSON.stringify(currentModel, replacer, 4)
);
setSaved(false);
}
}, []);

function replacer(key, value) {
if (key == "x" || key == "y") return Math.round((value + Number.EPSILON) * 1000) / 1000;
return value;
}

useEffect(() => {
const currentContext = contextRef.current;

Expand Down

0 comments on commit 64a837a

Please sign in to comment.