geomotion icon indicating copy to clipboard operation
geomotion copied to clipboard

Convert to unit coordinates

Open dkrusenstrahle opened this issue 11 years ago • 2 comments

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)

dkrusenstrahle avatar Dec 04 '13 21:12 dkrusenstrahle

By unit coordinates, you mean 'in pixels' I take it? This would be pretty straightforward to add, I think.

colinta avatar Feb 04 '14 16:02 colinta

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)

colinta avatar Feb 07 '14 18:02 colinta