             return (CGPoint(), CGPoint(), CGPoint())
         }
         
-        for corner in [.TopLeft, .TopRight, .BottomRight, .BottomLeft] as [UIRectCorner] {
-            let (startPoint, cornerPoint, endPoint) = pointsForCorner(corner)
-            if CGPathIsEmpty(path) {
-                CGPathMoveToPoint(path, nil, startPoint.x, startPoint.y)
+        for corner in [.topLeft, .topRight, .bottomRight, .bottomLeft] as [UIRectCorner] {
+            let (startPoint, cornerPoint, endPoint) = pointsForCorner(corner: corner)
+            if path.isEmpty {
+                path.move(to: startPoint)
             }
             
             if corners.contains(corner) && cornerRadius > 0 {
-                CGPathAddArcToPoint(path, nil, cornerPoint.x, cornerPoint.y, endPoint.x, endPoint.y, cornerRadius)
+                path.addArc(tangent1End: cornerPoint, tangent2End: endPoint, radius: cornerRadius)
             } else {
-                CGPathAddLineToPoint(path, nil, cornerPoint.x, cornerPoint.y)
-                CGPathAddLineToPoint(path, nil, endPoint.x, endPoint.y)
+                path.addLine(to: cornerPoint)
+                path.addLine(to: endPoint)
             }
         }
         
-        CGPathCloseSubpath(path)
+        path.closeSubpath()
         
-        self.init(CGPath: path)
+        self.init(cgPath: path)
     }
 }

    // create our own bezier path since we can control how it positions.
    
    convenience init(roundedRectWithoutAliasing frame: CGRect, byRoundingCorners corners: UIRectCorner, cornerRadius: CGFloat) {
        let path = CGPathCreateMutable()
        
        func pointsForCorner(corner: UIRectCorner) -> (start: CGPoint, corner: CGPoint, end: CGPoint) {
            switch corner {
            case UIRectCorner.TopLeft:
                return (
                    start: CGPoint(x: frame.minX, y: frame.midY),
                    corner: CGPoint(x: frame.minX, y: frame.minY),
                    end: CGPoint(x: frame.midX, y: frame.minY)
                )
            case UIRectCorner.TopRight:
                return (
                    start: CGPoint(x: frame.midX, y: frame.minY),
                    corner: CGPoint(x: frame.maxX, y: frame.minY),
                    end: CGPoint(x: frame.maxX, y: frame.midY)
                )
            case UIRectCorner.BottomRight:
                return (
                    start: CGPoint(x: frame.maxX, y: frame.midY),
                    corner: CGPoint(x: frame.maxX, y: frame.maxY),
                    end: CGPoint(x: frame.midX, y: frame.maxY)
                )
            case UIRectCorner.BottomLeft:
                return (
                    start: CGPoint(x: frame.midX, y: frame.maxY),
                    corner: CGPoint(x: frame.minX, y: frame.maxY),

    // and the language does not allow this
    public static func imageWithRoundedCorners(roundedCorners: UIRectCorner, cornerRadius: CGFloat, resizingDirection: RoundedResizingDirection, foregroundColor: UIColor, backgroundColor: UIColor, borderColor: UIColor? = nil, borderWidth: CGFloat? = nil) -> UIImage {
        // We adjust all our values to be in 1.0-scale space so smaller radii are less aliased
        let screenScale = UIScreen.main.scale
        let scaledCornerRadius = cornerRadius * screenScale
        var scaledSize = CGSize(width: scaledCornerRadius*2.0, height: scaledCornerRadius*2.0)
        
        if resizingDirection.contains(.horizontal) {
            scaledSize.width += screenScale
        }
        
        if resizingDirection.contains(.vertical) {
            scaledSize.height += screenScale
        }
        
