aseprite / aseprite

Animated sprite editor & pixel art tool (Windows, macOS, Linux)

Home Page:https://www.aseprite.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Code readability in selection_class.cpp possible typo

alexwittwer opened this issue · comments

Theres several instances in the /src/app/script/selection_class.cpp file where theres an if statement and an assignment operator, instead of an equality operator. I don't know if this is intentional as I'm not at my computer right now and cannot test this out. I figured I would open an issue to see if this was intended by someone who knows better than I about this part of the code base.

Found the issue when I was looking for a way to add a feature where the selection would count the number of pixels selected so that it can be displayed to the user, which is useful when keeping track of volume across animations

Offending lines are:

115: if (auto sprite = obj->sprite(L)) {

220: if (auto sprite = obj->sprite(L)) {

251: if (auto sprite = obj->sprite(L)) {

270: if (auto sprite = obj->sprite(L)) {

290: if (auto sprite = obj->sprite(L)) {

At the very least.

Thanks

...

...

...

Aseprite and System version

V1.3X

  • System: Linux

Hi @alexwittwer, this is intentional. Actually it's not an assignment but an initialization of a new variable inside the if. This is a common idiom in C++ where the declared variable lives in the scope of the if body scope. You can see several examples here: https://en.cppreference.com/w/cpp/language/if even with dynamic_cast<> which we use too and it's a common idiom when RTTI is enabled.

Hi @alexwittwer, this is intentional. Actually it's not an assignment but an initialization of a new variable inside the if. This is a common idiom in C++ where the declared variable lives in the scope of the if body scope. You can see several examples here: https://en.cppreference.com/w/cpp/language/if even with dynamic_cast<> which we use too and it's a common idiom when RTTI is enabled.

You learn something new everyday! Thanks!