0

I have an array of 3 CGPoints, what I'm trying to do is create a CGRect based on those CGPoint coordinates. I need this CGRect to set the bounds of a view so it can "zoom in" to those coordinates as soon as the view is loaded, but I'm not sure how to get the height and width. Any help is greatly appreciated!

1

1 Answer 1

0
let points: [CGPoint] = [
    .init(x: 1, y: 1), 
    .init(x: 5, y: 1), 
    .init(x: 8, y: 5)
]

let bounds = points.reduce(CGRect.null) { rect, point in
    return rect.union(CGRect(origin: point, size: .zero))
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.