mirror of
https://github.com/SFML/CSFML.git
synced 2026-10-27 21:36:13 +01: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(rect1, false);
|
||||||
CSFML_CHECK_RETURN(rect2, false);
|
CSFML_CHECK_RETURN(rect2, false);
|
||||||
|
|
||||||
sf::FloatRect SFMLRect1 = convertRect(*rect1);
|
const std::optional overlap = convertRect(*rect1).findIntersection(convertRect(*rect2));
|
||||||
sf::FloatRect SFMLRect2 = convertRect(*rect2);
|
|
||||||
|
|
||||||
if (intersection)
|
if (intersection && overlap)
|
||||||
{
|
*intersection = convertRect(*overlap);
|
||||||
std::optional<sf::FloatRect> overlap = SFMLRect1.findIntersection(SFMLRect2);
|
|
||||||
|
|
||||||
if (overlap)
|
return overlap.has_value();
|
||||||
*intersection = convertRect(*overlap);
|
|
||||||
|
|
||||||
return overlap.has_value();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return SFMLRect1.findIntersection(SFMLRect2).has_value();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
bool sfIntRect_intersects(const sfIntRect* rect1, const sfIntRect* rect2, sfIntRect* intersection)
|
bool sfIntRect_intersects(const sfIntRect* rect1, const sfIntRect* rect2, sfIntRect* intersection)
|
||||||
{
|
{
|
||||||
CSFML_CHECK_RETURN(rect1, false);
|
CSFML_CHECK_RETURN(rect1, false);
|
||||||
CSFML_CHECK_RETURN(rect2, false);
|
CSFML_CHECK_RETURN(rect2, false);
|
||||||
|
|
||||||
sf::IntRect SFMLRect1 = convertRect(*rect1);
|
const std::optional overlap = convertRect(*rect1).findIntersection(convertRect(*rect2));
|
||||||
sf::IntRect SFMLRect2 = convertRect(*rect2);
|
|
||||||
|
|
||||||
if (intersection)
|
if (intersection && overlap)
|
||||||
{
|
*intersection = convertRect(*overlap);
|
||||||
std::optional<sf::IntRect> overlap = SFMLRect1.findIntersection(SFMLRect2);
|
|
||||||
|
|
||||||
if (overlap)
|
return overlap.has_value();
|
||||||
*intersection = convertRect(*overlap);
|
|
||||||
|
|
||||||
return overlap.has_value();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return SFMLRect1.findIntersection(SFMLRect2).has_value();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user