-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix occlusion rounding bug #3400
Conversation
If you're aware, could I trouble you to provide a brief explanation of why this change fixes the problem? And could it be more succinctly expressed with Math.floor()? |
I looked into this a bit more to get you an explanation, but actually found a better fix. The root cause for this issue is that the canvas size is determined inconsistently, 706 & 707 in this example. I found this in the calls to xFromNormalized() -> Math.round(x * width) = result
width:707 x:0.619 result:438
width:707 x:0.6204 result:439
width:707 x:0.6218 result:440
width:707 x:0.6232 result:441
xToNormalized() -> (x / width) = result
width:706 x:438 result:0.6203966005665722
width:706 x:439 result:0.6218130311614731
width:706 x:440 result:0.62322946175637 706 is the true size of the canvas, this is calculated when moving a shape on the canvas to save the data to the database. Below is the stack trace:
This is determined in export const getBoundingBox = () => {
const canvas = globalThis.canvas;
return canvas.getObjects().find((obj) => obj.fill === "transparent")
}; However, when the occlusion editor initially loads it determines the canvas size is 707. See below stack trace:
This is determined in const fabricShape = shape.toFabric(boundingBox.getBoundingRect(true)); My solution to this is to update the export const getBoundingBox = () => {
const canvas = globalThis.canvas;
return canvas.getObjects().find((obj) => obj.fill === "transparent").getBoundingRect(true);
}; My alternate approach is below was to use the actual size of the canvas as the bounds in const fabricShape = shape.toFabric({"width": boundingBox.width ?? 1, "height": boundingBox.height ?? 1}); |
b3f970c
to
751d488
Compare
Thanks Taylor, this looks like an elegant fix. |
* master: Update translations Add an option to show image from editor in folder (ankitects#3412) Call the profile_did_open() hook earlier (ankitects#3421) Fix FSRS progress update issues (ankitects#3420) Update tooltip text (ankitects#3418) Fix pasting from the primary selection (ankitects#3413) Fix occlusion rounding bug (ankitects#3400) Add comment about the usage of the input field in the statistics page (ankitects#3394) (ankitects#3398) Possible to show “last” subdeck name in Browser? (ankitects#3387)
* Fix occlusion rounding bug * Fix contributors
This reverts commit 96ff4f1. This change broke adding of new occlusions on desktop: JS error /_anki/js/editor.js:100016 Uncaught TypeError: Cannot read properties of undefined (reading 'getBoundingRect')
A heads up: unfortunately this broke adding of occlusions |
Fixes #3370