mirror of
https://github.com/SFML/CSFML.git
synced 2026-10-24 21:53:37 +02:00
Clean up implementation of sf<T>Rect_intersects
This commit is contained in:
1 parent
54d28325b9
commit
b3a0ed815b
1 file changed
+8
-28
@@ -56,42 +56,22 @@ bool sfFloatRect_intersects(const sfFloatRect* rect1, const sfFloatRect* rect2,
|
||||
CSFML_CHECK_RETURN(rect1, false);
|
||||
CSFML_CHECK_RETURN(rect2, false);
|
||||
|
||||
sf::FloatRect SFMLRect1 = convertRect(*rect1);
|
||||
sf::FloatRect SFMLRect2 = convertRect(*rect2);
|
||||
const std::optional overlap = convertRect(*rect1).findIntersection(convertRect(*rect2));
|
||||
|
||||
if (intersection)
|
||||
{
|
||||
std::optional<sf::FloatRect> overlap = SFMLRect1.findIntersection(SFMLRect2);
|
||||
if (intersection && overlap)
|
||||
*intersection = convertRect(*overlap);
|
||||
|
||||
if (overlap)
|
||||
*intersection = convertRect(*overlap);
|
||||
|
||||
return overlap.has_value();
|
||||
}
|
||||
else
|
||||
{
|
||||
return SFMLRect1.findIntersection(SFMLRect2).has_value();
|
||||
}
|
||||
return overlap.has_value();
|
||||
}
|
||||
bool sfIntRect_intersects(const sfIntRect* rect1, const sfIntRect* rect2, sfIntRect* intersection)
|
||||
{
|
||||
CSFML_CHECK_RETURN(rect1, false);
|
||||
CSFML_CHECK_RETURN(rect2, false);
|
||||
|
||||
sf::IntRect SFMLRect1 = convertRect(*rect1);
|
||||
sf::IntRect SFMLRect2 = convertRect(*rect2);
|
||||
const std::optional overlap = convertRect(*rect1).findIntersection(convertRect(*rect2));
|
||||
|
||||
if (intersection)
|
||||
{
|
||||
std::optional<sf::IntRect> overlap = SFMLRect1.findIntersection(SFMLRect2);
|
||||
if (intersection && overlap)
|
||||
*intersection = convertRect(*overlap);
|
||||
|
||||
if (overlap)
|
||||
*intersection = convertRect(*overlap);
|
||||
|
||||
return overlap.has_value();
|
||||
}
|
||||
else
|
||||
{
|
||||
return SFMLRect1.findIntersection(SFMLRect2).has_value();
|
||||
}
|
||||
return overlap.has_value();
|
||||
}
|
||||
Reference in new issue
Block a user