geomotion
geomotion copied to clipboard
Convert to unit coordinates
Hello!
Thanks for a really cool and useful gem. I am using the pod GPUImage and the filter GPUImageCropFilter. I need to convert normal CGRectMake coordinates into unit coordinates. Is there a neat and simple way of doing that with Geomotion? If not, it would be cool if there were.
I am trying to convert these into unit coordinates:
CGRectMake(123, 123, 50, 50)
By unit coordinates, you mean 'in pixels' I take it? This would be pretty straightforward to add, I think.
Ohh, I see - unit coordinates are where the total width is 1.0
. So in that case, you have to have the rect, AND the original image size.
size = CGSize.make(width: 400, height: 400)
rect = CGRect.make(x: 100, y: 100, width: 40, height: 40)
unit_rect = size.make_unit_rect(rect)
# => CGRect(0.25, 0.25, 0.1, 0.1)