Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: small sf::rect suggestion  (Read 5926 times)

0 Members and 3 Guests are viewing this topic.

Shadowblitz16

  • Newbie
  • *
  • Posts: 13
    • View Profile
small sf::rect suggestion
« on: May 02, 2017, 10:17:24 pm »
can the sfml devs add support "bottom" "right" and "touching()"

bottom and right would return the x2 and y2.
touching() would return true if two objects are right beside each other. but not if they are intersecting.

Rosme

  • Full Member
  • ***
  • Posts: 169
  • Proud member of the shoe club
    • View Profile
    • Code-Concept
Re: small sf::rect suggestion
« Reply #1 on: May 03, 2017, 12:00:45 am »
bottom and right can already be easily calculated using top+height and left+width.

As for touching, I am not sure what would be the use case. Do you have a use case to present for this because this sound oddly specific to your situtation?
GitHub
Code Concept
Twitter
Rosme on IRC/Discord

ZeroZ30o

  • Newbie
  • *
  • Posts: 47
    • View Profile
Re: small sf::rect suggestion
« Reply #2 on: May 03, 2017, 01:36:24 pm »
bottom and right can already be easily calculated using top+height and left+width.

Yeah but if you store bottom and right you can also easily calculate height and width. It's a matter of what you prefer. I personally also find bottom and right more useful, I use them more often than height and width, thus doing more calculations.

As for touching, I am not sure what would be the use case. Do you have a use case to present for this because this sound oddly specific to your situtation?

Touching doesn't make much sense if it returns false even when they do intersect.
However, it is useful to know if 2 objects are right next to eachother, in some cases like checking if a point is on the edges of the rectangle and other similar operations.

sjaustirni

  • Jr. Member
  • **
  • Posts: 94
    • View Profile
Re: small sf::rect suggestion
« Reply #3 on: May 03, 2017, 02:37:04 pm »
bottom and right can already be easily calculated using top+height and left+width.

Yeah but if you store bottom and right you can also easily calculate height and width. It's a matter of what you prefer. I personally also find bottom and right more useful, I use them more often than height and width, thus doing more calculations.
No, it is not a matter of preference. The way SFML does it is objectively superior.
If you're given x, y, width and height, it is guaranteed you're always given an axis-aligned rectangle. Had you had been given four (random) points instead, the rectangle is not guaranteed  to be axis-aligned. Hell, it is not guaranteed to be a rectangle at all* (it could be any quadrilateral, even a concave one).

* not without cumbersome dedicated checking and error reporting


Touching doesn't make much sense if it returns false even when they do intersect.
However, it is useful to know if 2 objects are right next to eachother, in some cases like checking if a point is on the edges of the rectangle and other similar operations.
SFML is not a collision detection library and you should not treat it so. Besides, thanks to how float-point arithmetic works, you're never going to get a perfect "touch". That's why even in dedicated collision detection/resolution libraries intersections are treated as "touches" (especially if the relative velocity of the colliding objects is small).

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: small sf::rect suggestion
« Reply #4 on: May 03, 2017, 02:53:37 pm »
Quote
Had you had been given four (random) points instead
It's not 4 random points (the corners), it's 4 values (the edges), so it's indeed completely equivalent, and only a matter of taste.
Laurent Gomila - SFML developer

sjaustirni

  • Jr. Member
  • **
  • Posts: 94
    • View Profile
Re: small sf::rect suggestion
« Reply #5 on: May 03, 2017, 08:30:07 pm »
I thought we were talking about sf::Rect. left and top are defined as coordinates there (corners, not edges).
But I suppose I have misunderstood something here?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: small sf::rect suggestion
« Reply #6 on: May 03, 2017, 08:56:59 pm »
Yes, you must have misunderstood it.

The rect would be defined through the the two points (left, top) and (right, bottom).

Both can be calculated from each other and thus it's just a question of preference:
1) (right, bottom) = (left, top) + (width, height)
2) (width, height) = (right, bottom) - (left, top)

This is not the first time this has been brought up, so make sure to use the search engine. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: small sf::rect suggestion
« Reply #7 on: May 03, 2017, 11:22:36 pm »
Quote
I thought we were talking about sf::Rect. left and top are defined as coordinates there (corners, not edges).
No, they are not. All members of sf::Rect<T> (left, top, width and height) are single values of type T, with T being a scalar type (int and float are used internally in SFML).
Laurent Gomila - SFML developer

sjaustirni

  • Jr. Member
  • **
  • Posts: 94
    • View Profile
Re: small sf::rect suggestion
« Reply #8 on: May 04, 2017, 10:24:13 am »
Yes, you must have misunderstood it.

The rect would be defined through the the two points (left, top) and (right, bottom).

Both can be calculated from each other and thus it's just a question of preference:
1) (right, bottom) = (left, top) + (width, height)
2) (width, height) = (right, bottom) - (left, top)
Yes, I see I have misunderstood it now. Indeed, they're equivalent approaches of a representation of a rectangle. I made an implicit assumption that the sf::Rect constructor was somehow involved. I am sorry for the annoyance I caused.  :-[

No, they are not. All members of sf::Rect<T> (left, top, width and height) are single values of type T, with T being a scalar type (int and float are used internally in SFML).

Yeah, what I meant was that left and top made together de facto a left a top coordinate, but that's moot now. Stupid me  :-[

 

anything