<commit_before>//
//  DrawingView.swift
//  Padiddle
//
//  Created by <NAME> on 10/7/15.
//  Copyright © 2015 <NAME>. All rights reserved.
//

import UIKit

private let debugging = false

typealias ImageCallback = UIImage? -> Void

protocol DrawingViewDelegate:
class {
    var currentColor: UIColor { get }
}

class DrawingView: UIView {

    weak var drawingViewDelegate: DrawingViewDelegate?

    private var needsErase = true
    private var smoothing = true
    private let screenScale = UIScreen.mainScreen().scale

    lazy private var contextScaleFactor: CGFloat = {
        // The context image is scaled as Aspect Fill, so the larger dimension
        // of the bounds is the limiting factor
        let maxDimension = max(CGRectGetWidth(self.frame), CGRectGetHeight(self.frame))
        assert(maxDimension > 0)

        // Given context side length L and bounds max dimension l,
        // We are looking for a factor, ƒ, such that L * ƒ = l
        // So we divide both sides by L to get ƒ = l / L
        let ƒ = maxDimension / self.contextSize.width
        return ƒ
    }()

    private let contextSize = CGSize(width: 1024, height: 1024)

    private let brushDiameter: CGFloat = 12

    private let bytesPerPixel: size_t = 4
    private let bitsPerComponent: size_t = 8

    private var points: [CGPoint]

    // TODO: move offscreen context into view model (duh)
    private var offscreenContext: CGContextRef?

    private var currentDirtyRect = CGRect.null

    private var displayLink: CADisplayLink?

    override init(frame: CGRect) {

        let initialPoint = CGPoint(x: CGRectGetWidth(frame) / 2.0, y: CGRectGetHeight(frame) / 2.0)
        points = [ initialPoint, initialPoint, initialPoint, initialPoint ]

        super.init(frame: frame)

        displayLink = CADisplayLink(target: self, selector: "displayLinkUpdated")
        displayLink?.addToRunLoop(NSRunLoop.mainRunLoop(), forMode: NSDefaultRunLoopMode)

        let success = configureOffscreenContext()
        assert(success, "Problem creating bitmap context")
    }
<commit_msg>Remove “(duh)”.<commit_after>//
//  DrawingView.swift
//  Padiddle
//
//  Created by <NAME> on 10/7/15.
//  Copyright © 2015 <NAME>. All rights reserved.
//

import UIKit

private let debugging = false

typealias ImageCallback = UIImage? -> Void

protocol DrawingViewDelegate:
class {
    var currentColor: UIColor { get }
}

class DrawingView: UIView {

    weak var drawingViewDelegate: DrawingViewDelegate?

    private var needsErase = true
    private var smoothing = true
    private let screenScale = UIScreen.mainScreen().scale

    lazy private var contextScaleFactor: CGFloat = {
        // The context image is scaled as Aspect Fill, so the larger dimension
        // of the bounds is the limiting factor
        let maxDimension = max(CGRectGetWidth(self.frame), CGRectGetHeight(self.frame))
        assert(maxDimension > 0)

        // Given context side length L and bounds max dimension l,
        // We are looking for a factor, ƒ, such that L * ƒ = l
        // So we divide both sides by L to get ƒ = l / L
        let ƒ = maxDimension / self.contextSize.width
        return ƒ
    }()

    private let contextSize = CGSize(width: 1024, height: 1024)

    private let brushDiameter: CGFloat = 12

    private let bytesPerPixel: size_t = 4
    private let bitsPerComponent: size_t = 8

    private var points: [CGPoint]

    // TODO: move offscreen context into view model
    private var offscreenContext: CGContextRef?

    private var currentDirtyRect = CGRect.null

    private var displayLink: CADisplayLink?

    override init(frame: CGRect) {

        let initialPoint = CGPoint(x: CGRectGetWidth(frame) / 2.0, y: CGRectGetHeight(frame) / 2.0)
        points = [ initialPoint, initialPoint, initialPoint, initialPoint ]

        super.init(frame: frame)

        displayLink = CADisplayLink(target: self, selector: "displayLinkUpdated")
        displayLink?.addToRunLoop(NSRunLoop.mainRunLoop(), forMode: NSDefaultRunLoopMode)

        let success = configureOffscreenContext()
        assert(success, "Problem creating bitmap context")
    }

{'fraction_non_alphanumeric': 0.08333333333333333, 'fraction_numerical': 0.012560386473429951, 'mean_word_length': 2.9438095238095237, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1782472', 'n_tokens_mistral': 1271, 'n_tokens_neox': 1180, 'n_words': 402}