Reputation: 17705
When working with (contentless) SpriteKit nodes I bumped into an infinite rectangle
NSLog(@"%@", NSStringFromCGRect([node calculateAccumulatedFrame]));
which outputted
{{inf, inf}, {inf, inf}}
I thought to check for this with CGRectIsInfinite
, but that test failed, which lead me to trying the following check
CGRect rect = [node calculateAccumulatedFrame];
if (rect.origin.x == INFINITY && rect.origin.y == INFINITY &&
rect.size.width == INFINITY && rect.size.height == INFINITY) {
if (!CGRectIsInfinite(rect)) {
NSLog(@"I don't get it");
}
}
Which outputs: I don't get it
, which neatly summarises my position right now.
As pointed out by allestuetsmerweh
in an answer the function does return true for CGRectInfinite
, when I output this rectangle I get
{{-8.9884656743115785e+307, -8.9884656743115785e+307}, {1.7976931348623157e+308, 1.7976931348623157e+308}}
(the sizes are both DBL_MAX
)
What's the reasoning behind CGRectInfinite
being a rectangle with some values set to DBL_MAX i.s.o. a rectangle with all elements set to INFINITY
? (while the API does return CGRect with all members set to INFINITY)
Or rather, why doesn't a rectangle with the elements set to INFINITY
register as a CGRectIsInfinite
?
Upvotes: 0
Views: 1576
Reputation: 1592
CG has defined the infinite rectangle, see CGRectInfinite. As a probable surprise to many, this rect is defined to have bounds ±CGFLOAT_MAX/2, with a finite size equal to CGFLOAT_MAX.
The CGRectIsInfinite() function does not tell you that the rectangle is infinite, despite documentation to the contrary. It tells you whether the rectangle is the infinite rect (which isn't er... actually infinite).
Upvotes: 0
Reputation: 81868
What's the reasoning behind CGRectInfinite being a rectangle with some values set to DBL_MAX i.s.o. a rectangle with all elements set to INFINITY?
Here are some guesses:
CGRectInfinite
).And why doesn't a rectangle with the elements set to INFINITY register as a CGRectIsInfinite?
Because, as expected, CGRectIsInfinite
compares its argument to CGRectInfinite
(which has a special meaning in some APIs and so should be unambiguously identifiable).
Upvotes: 2
Reputation: 41
CGRect r = CGRectInfinite;
NSLog(@"%i", CGRectIsInfinite(r)); //prints "1"
From the docs:
An infinite rectangle is one that has no defined bounds. Infinite rectangles can be created as output from a tiling filter. For example, the Core Image framework perspective tile filter creates an image whose extent is described by an infinite rectangle.
Upvotes: 3