CGSRegionRef: How is an arbitrary region represented as union of rects?

23 views Asked by At

The CGSRegionRef type is an undocumented/appkit internal CFType that seems to be able to decompose an arbitrary region into a union of rectangles. However, while the underlying APIs have been reverse-engineered for some time now, I'm having trouble actually understanding the debug output from NSLog'ing a region ref. For instance, the output of

       CGRect rect1 = CGRectMake(0, 0, 50, 10);
       CGRect rect2 = CGRectMake(0, 0, 5, 40);
       CGSRegionRef out1, out2, out3;
       CGSNewRegionWithRect(&rect1, &out1);
       CGSNewRegionWithRect(&rect2, &out2);
       
       CGSUnionRegion(out1, out2, &out3);
   

       NSLog(@"%@", out3);

is

#<CGSRegion 0x600003950630 [0 0 50 40]
         0 [0 50] 
        10 [0 5] 
        40 []
>

which appears to provide some sort of decomposition for a region composed of a 50w10h rectangle and a 5w40h rectangle both with their lower-left corners at the origin. However, it's not clear exactly what the format of the 3 rows is. They don't seem to be convex hull points because (0, 0), (0, 50), (10, 0), (0, 5) doesn't go all the way around the object.

enter image description here

0

There are 0 answers