Skip to content

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Rotation #6

wants to merge 2 commits into from

Conversation

FelixAbrahamsson
Copy link

@FelixAbrahamsson FelixAbrahamsson commented Jan 26, 2024

Some credit goes to me and @samedii and a lot of credit goes to @chatgpt

// First, undo scaling
let unscaledX = x / d.scale;
// Then, undo rotation
const rotatedX =
Copy link
Contributor

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) -
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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)) {
Copy link
Contributor

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?

@samedii
Copy link

samedii commented Jan 29, 2024

Frontend is not using canvas anymore. We will not be spending more time on this :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants