-
Notifications
You must be signed in to change notification settings - Fork 0
Rotation #6
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
base: main
Are you sure you want to change the base?
Rotation #6
Conversation
// First, undo scaling | ||
let unscaledX = x / d.scale; | ||
// Then, undo rotation | ||
const rotatedX = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unrotated?
const translatedY = d.y; // y-coordinate remains the same for calculating x | ||
// Apply rotation | ||
const rotatedX = | ||
Math.cos(d.rotation.angle) * (translatedX - d.rotation.x) - |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Math.cos/sin is kinda slow (I'm guessing they don't have a shortcut for PI). But I think it's ok as long as we have much less then 30k objects to render
// Save the current context state | ||
_context.save(); | ||
|
||
// Move to where the image will be drawn and apply rotation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here _context.translate + _context.rotate is more then enough
// Move to the center of the rectangle | ||
_context.translate(s.x(centerX), s.y(centerY)); | ||
|
||
// Rotate the context |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the comment is actually wrong, chatgpt ... :P
isDefined(maxWidth) ? s.distance(maxWidth) : undefined | ||
0, | ||
0, | ||
maxWidth !== undefined ? s.distance(maxWidth) : undefined |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
was this on purpose or just chatgpt?
canvas, | ||
{ x = 0, y = 0, scale = 1, rotation = { x: 0, y: 0, angle: 0 } } = {} | ||
) => { | ||
if (![0, Math.PI].includes(rotation.angle)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How come this is the case?
Frontend is not using canvas anymore. We will not be spending more time on this :) |
Some credit goes to me and @samedii and a lot of credit goes to @chatgpt