Skip to content

Instantly share code, notes, and snippets.

@almaleh
Created January 16, 2019 04:27
Show Gist options
  • Save almaleh/7d4ca4fa4ec0fc9acabc59491a6c2003 to your computer and use it in GitHub Desktop.
Save almaleh/7d4ca4fa4ec0fc9acabc59491a6c2003 to your computer and use it in GitHub Desktop.
func calculateRectBetween(lastPoint: CGPoint, newPoint: CGPoint) -> CGRect {
let originX = min(lastPoint.x, newPoint.x) - (lineWidth / 2)
let originY = min(lastPoint.y, newPoint.y) - (lineWidth / 2)
let maxX = max(lastPoint.x, newPoint.x) + (lineWidth / 2)
let maxY = max(lastPoint.y, newPoint.y) + (lineWidth / 2)
let width = maxX - originX
let height = maxY - originY
return CGRect(x: originX, y: originY, width: width, height: height)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment