### return value of a rect in c++

I have got a function in sfml which gets the co-ordinates of a rectangle bounding box for a circle shape. The return value is described as FloatRect and the value is:
circle1 = 1026324980834960100

This is for a circle with the following dimensions:

circle1
x = 395.11
y = 344.97
width = 49.78
height = 50.06

I may be being stupid but I have tried looking in all the ref books I can find and I still can't work out what the return value has got to do with the 4 co-ordinates.

Has anyone got any idea?

What does the function look like? Or are you using something like .getGlobalBounds()?
A FloatRect has 4 members. It does not have a value, per se. The values it holds are contained in its data members.

 I may be being stupid but I have tried looking in all the ref books I can find and I still can't work out what the return value has got to do with the 4 co-ordinates.

What return value and what 4 coordinates? width/height are not coordinates.

If you could supply some minimal code that reproduced the situation you are speaking about instead of using English mumbo jumbo, that would be helpful.
Edit: lol I thought cire was BillH xD

I think you are confused, at least I think I am. (You should supply code that shows us 1026324980834960100)

How did you get that value? Did you just directly std::cout << the floatrect? width/height are not coordinates, but top and left are. You can thus get the other corners by decrementing top by height, incrementing left by width and doing both for the bottom right corner.
Last edited on
To all

Sorry, what I have is this:
This is where the original circle1 = 1026324980834960100 came from:

 ``12`` ``````sprintf(buffer,"\ncircle1 = %.0f\n",circle.getGlobalBounds()); std::cout<

At the moment I am getting the boundary co-ordinates from the following code

 ``12345`` ``````x=circle.getGlobalBounds().left; y=circle.getGlobalBounds().top; w=circle.getGlobalBounds().width; h=circle.getGlobalBounds().height; ``````

I then use this to find out whether the mouse is within that box area, in order to drag and drop. The actual program works fine. What I would like to do is cut these 4 lines down into a single one, if possible. I am fairly new to this so I hope you will bear with me.

Thanks again.
You are printing an object directly, I think behaviour is undefined. It's like saying std::cout << circle.getGlobalBounds().

You say you want to cut it down?

 `` `` ``circle.getGlobalBounds().contains(sf::Mouse::getPosition());``

SFML documentation here http://www.sfml-dev.org/documentation/2.0/classsf_1_1Rect.php
 ``12`` ``````sprintf(buffer,"\ncircle1 = %.0f\n",circle.getGlobalBounds()); std::cout<

The sprintf call is undefined behavior. An sf::FloatRect is not a float.

The following line is equivalent to: `(std::cout << buffer), "\n" ;` which is to say that the "\n" is pointless. Use ` std::cout << buffer << '\n'; ` to chain calls to operator<<.

Using events is more appropriate for dragging/dropping stuff than using sf::Mouse.

Try out the following:
 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667`` ``````#include #include int main() { sf::RenderWindow window(sf::VideoMode(800, 600), "Drag it"); const sf::Color hoverColor(255, 0, 0) ; const sf::Color regularColor(127, 0, 0) ; sf::CircleShape circle(25.0f) ; circle.setOrigin(25.0f, 25.0f) ; circle.setPosition(400.0f, 300.0f) ; circle.setFillColor(regularColor) ; bool hovering = false ; bool dragging = false ; while(window.isOpen()) { sf::Event event; while(window.pollEvent(event)) { switch( event.type ) { case sf::Event::Closed: window.close() ; break; case sf::Event::MouseMoved: if ( dragging ) { circle.setPosition(event.mouseMove.x, event.mouseMove.y) ; } else if ( circle.getGlobalBounds().contains(event.mouseMove.x, event.mouseMove.y) ) { hovering = true ; circle.setFillColor(hoverColor) ; } else if ( hovering == true ) { hovering = false ; circle.setFillColor(regularColor) ; } break ; case sf::Event::MouseButtonPressed: if ( circle.getGlobalBounds().contains(event.mouseButton.x, event.mouseButton.y) && event.mouseButton.button == sf::Mouse::Left ) { dragging = true ; circle.setPosition(event.mouseButton.x, event.mouseButton.y) ; } break ; case sf::Event::MouseButtonReleased: if ( event.mouseButton.button == sf::Mouse::Left ) dragging = false ; break ; } } window.clear(); window.draw(circle) ; window.display(); } }``````

Thanks Bourgond Aries and cire, I was obviously thinking along the wrong lines. Your advice has solved my problem. Thanks again
Topic archived. No new replies allowed.