Skip to content

Improve rotated rectangles and square brush drawing#5459

Merged
dacap merged 1 commit into
aseprite:mainfrom
martincapello:improve-rects-and-square-brush
Oct 23, 2025
Merged

Improve rotated rectangles and square brush drawing#5459
dacap merged 1 commit into
aseprite:mainfrom
martincapello:improve-rects-and-square-brush

Conversation

@martincapello

Copy link
Copy Markdown
Member

This PR improves how the rectangles (made using any of the rectangle tool) and the square brush are drawn in rotated positions.

@aseprite-bot aseprite-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

int cy = (y1 + y2) / 2;
int a = (x2 - x1) / 2;
int b = (y2 - y1) / 2;
int a = (x2 - x1 + 1) / 2;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: variable 'a' of type 'int' can be declared 'const' [misc-const-correctness]

Suggested change
int a = (x2 - x1 + 1) / 2;
int const a = (x2 - x1 + 1) / 2;

int a = (x2 - x1) / 2;
int b = (y2 - y1) / 2;
int a = (x2 - x1 + 1) / 2;
int b = (y2 - y1 + 1) / 2;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: variable 'b' of type 'int' can be declared 'const' [misc-const-correctness]

Suggested change
int b = (y2 - y1 + 1) / 2;
int const b = (y2 - y1 + 1) / 2;

double s = -std::sin(angle);
double c = std::cos(angle);

int ac = a * c;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: variable 'ac' of type 'int' can be declared 'const' [misc-const-correctness]

Suggested change
int ac = a * c;
int const ac = a * c;

double c = std::cos(angle);

int ac = a * c;
int bs = b * s;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: variable 'bs' of type 'int' can be declared 'const' [misc-const-correctness]

Suggested change
int bs = b * s;
int const bs = b * s;


int ac = a * c;
int bs = b * s;
int as = a * s;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: variable 'as' of type 'int' can be declared 'const' [misc-const-correctness]

Suggested change
int as = a * s;
int const as = a * s;

Comment thread src/doc/brush.cpp
// Based in code of IntertwineAsRectangles::rotateRectangle function.
int c = size / 2;
int a = m_size / 2;
int b = a;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: variable 'b' of type 'int' can be declared 'const' [misc-const-correctness]

Suggested change
int b = a;
int const b = a;

Comment thread src/doc/brush.cpp
int c = size / 2;
int a = m_size / 2;
int b = a;
int ac = a * cos;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: variable 'ac' of type 'int' can be declared 'const' [misc-const-correctness]

Suggested change
int ac = a * cos;
int const ac = a * cos;

Comment thread src/doc/brush.cpp
int a = m_size / 2;
int b = a;
int ac = a * cos;
int bs = b * sin;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: variable 'bs' of type 'int' can be declared 'const' [misc-const-correctness]

Suggested change
int bs = b * sin;
int const bs = b * sin;

Comment thread src/doc/brush.cpp
int b = a;
int ac = a * cos;
int bs = b * sin;
int as = bs;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: variable 'as' of type 'int' can be declared 'const' [misc-const-correctness]

Suggested change
int as = bs;
int const as = bs;

Comment thread src/doc/brush.cpp
int ac = a * cos;
int bs = b * sin;
int as = bs;
int bc = ac;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: variable 'bc' of type 'int' can be declared 'const' [misc-const-correctness]

Suggested change
int bc = ac;
int const bc = ac;

@dacap

dacap commented Oct 23, 2025

Copy link
Copy Markdown
Member

It looks great 👍 I'll merge it, I'm not sure if it would make sense to move the std::swap() inside the rotateRectangle function in the future.

@dacap dacap merged commit 2fe3126 into aseprite:main Oct 23, 2025
12 checks passed
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.

3 participants