     
     
     
-    override func drawRect(rect: CGRect) {
+    override public func drawRect(rect: CGRect) {
         self.committedImage.drawAtPoint(CGPointZero)
         self.currentTool.drawHistory(self.history)
     }
     
     
     
-    override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
+    // MARK: Handling touches
+    override public func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
         guard let touch = touches.first else { return }
         
         let currentPoint = touch.locationInView(self)


// MARK: - DejaDrawView

class DejaDrawView: UIView {

    // MARK: Properties
    var history = TouchHistory()
    var currentTool = VaryingWidthPen()
    var committedImage = UIImage()

    
    
    // MARK: Methods
    required init(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        self.configure()
    }
    
    
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.configure()
    }
    
    
    
    func configure() {
        let long = UILongPressGestureRecognizer(target: self, action: Selector("erase:"))
        self.addGestureRecognizer(long)
    }
    
    
    
    func erase(rec: UIGestureRecognizer) {
        committedImage = UIImage()
        history = TouchHistory()
        self.setNeedsDisplay()

        return CGPointMake(px * f, py * f)
    }
    
    
    
    private func dist(a: CGPoint, _ b: CGPoint) -> CGFloat {
        let r2: CGFloat = pow(b.x - a.x, 2.0)
        let s2: CGFloat = pow(b.y - a.y, 2.0)
        return sqrt(r2 + s2)
    }
    
    
    
    private func midPoint(a: CGPoint, _ b: CGPoint) -> CGPoint {
        return CGPointMake(0.5 * (a.x + b.x), 0.5 * (a.y + b.y))
    }
    
    
    
    private func clamp(d: CGFloat) -> CGFloat {
        return max(min(8.0, d), 2.0)
    }
}
