SFML community forums

Help => Graphics => Topic started by: oncleJhon on October 12, 2023, 10:09:52 pm

Title: possible bug with sf::circleShape points not updating
Post by: oncleJhon on October 12, 2023, 10:09:52 pm
I think I have discovered a bug with the circleShape.

I was trying to positions elements in a circle formation by creating a circle and using its points positions to determine the positions of the elements I wanted to create. But it seems that using the setPosition() on circleShape doesn't move the circle points locations with it.

Here is a simple code proving it

#include <SFML/Graphics.hpp>

void printPointsLocations(sf::CircleShape& circle) {
    for (int i = 0; i < circle.getPointCount(); i++) {
        printf("Point %d: (%f, %f)\n", i, circle.getPoint(i).x,
               circle.getPoint(i).y);
    }
}

int main() {
    sf::CircleShape circle(100.f, 5);
    printf("Default circle:\n");
    printPointsLocations(circle);
    printf("Default circle position: (%f, %f)\n", circle.getPosition().x,
           circle.getPosition().y);
    circle.setPosition(sf::Vector2f(100.f, 0));
    printf("Moved circle circle:\n");
    printPointsLocations(circle);
    printf("Moved circle position: (%f, %f)\n", circle.getPosition().x,
           circle.getPosition().y);
}

and in attached files my result in my terminal. As you can see the circle has been moved, but the points are at the same place, while I am expecting them to be 100px further after setting the new positions of the circle.
I am aware my issue can be fixed by applying my transformation the the points I am given instead, but it is still a bug for me

I am using SFML 2.6 and VS 2019 compiler on Windows 11.
Title: Re: possible bug with sf::circleShape points not updating
Post by: kimci86 on October 12, 2023, 11:09:17 pm
This is expected. getPoint ignores the shape transform.

Quote from: https://www.sfml-dev.org/documentation/2.6.0/classsf_1_1CircleShape.php#a2d7f9715502b960b92387102fddb8736
The returned point is in local coordinates, that is, the shape's transforms (position, rotation, scale) are not taken into account.

If you want transformed positions, you can get the shape transform (getTransform (https://www.sfml-dev.org/documentation/2.6.0/classsf_1_1Transformable.php#a3e1b4772a451ec66ac7e6af655726154)) and use it to transform the points (transformPoint (https://www.sfml-dev.org/documentation/2.6.0/classsf_1_1Transform.php#ab42a0bb7a252c6d221004f6372ce5fdc)).