<commit_before>//
//  Image.swift
//  ProcessingKit
//
//  Created by AtsuyaSato on 2017/08/16.
//  Copyright © 2017年 <NAME>. All rights reserved.
//

#if !os(iOS)
import Cocoa
#endif

public protocol ImageModelContract {
    func image(_ img: UIImage, _ x: CGFloat, _ y: CGFloat)
    func image(_ img: UIImage, _ x: CGFloat, _ y: CGFloat, _ width: CGFloat, _ height: CGFloat)
}

struct ImageModel: ImageModelContract {

    func image(_ img: UIImage, _ x: CGFloat, _ y: CGFloat) {
        let g = MultiplatformCommon.getCurrentContext()
        g?.saveGState()
        g?.translateBy(x: 0.0, y: img.size.height)
        g?.scaleBy(x: 1.0, y: -1.0)
        if let cgImg = img.cgImage {
            g?.draw(cgImg, in: CGRect(x: x, y: y, width: img.size.width, height: img.size.height))
        }
        g?.restoreGState()
    }

    func image(_ img: UIImage, _ x: CGFloat, _ y: CGFloat, _ width: CGFloat, _ height: CGFloat) {
        let g = MultiplatformCommon.getCurrentContext()
        g?.saveGState()
        g?.translateBy(x: 0.0, y: height)
        g?.scaleBy(x: 1.0, y: -1.0)
        if let cgImg = img.cgImage {
            g?.draw(cgImg, in: CGRect(x: x, y: -y, width: width, height: height))
        }
        g?.restoreGState()
    }
}

// MARK: - ProcessingView Public APIs
extension ProcessingView: ImageModelContract {
    public func image(_ img: UIImage, _ x: CGFloat, _ y: CGFloat) {
        self.imageModel.image(img, x, y)
    }

    public func image(_ img: UIImage, _ x: CGFloat, _ y: CGFloat, _ width: CGFloat, _ height: CGFloat) {
        self.imageModel.image(img, x, y, width, height)
    }
}
<commit_msg>:bug: Fix image function<commit_after>//
//  Image.swift
//  ProcessingKit
//
//  Created by AtsuyaSato on 2017/08/16.
//  Copyright © 2017年 <NAME>. All rights reserved.
//

#if !os(iOS)
import Cocoa
#endif

public protocol ImageModelContract {
    #if os(iOS)
    func image(_ img: UIImage, _ x: CGFloat, _ y: CGFloat)
    func image(_ img: UIImage, _ x: CGFloat, _ y: CGFloat, _ width: CGFloat, _ height: CGFloat)
    #else
    func drawImage(_ img: NSImage, _ x: CGFloat, _ y: CGFloat)
    func drawImage(_ img: NSImage, _ x: CGFloat, _ y: CGFloat, _ width: CGFloat, _ height: CGFloat)
    #endif
}

struct ImageModel: ImageModelContract {
    #if os(iOS)
    func image(_ img: UIImage, _ x: CGFloat, _ y: CGFloat) {
        let g = MultiplatformCommon.getCurrentContext()
        g?.saveGState()
        g?.translateBy(x: 0.0, y: img.size.height)
        g?.scaleBy(x: 1.0, y: -1.0)
        if let cgImg = img.cgImage {
            g?.draw(cgImg, in: CGRect(x: x, y: y, width: img.size.width, height: img.size.height))
        }
        g?.restoreGState()
    }

    func image(_ img: UIImage, _ x: CGFloat, _ y: CGFloat, _ width: CGFloat, _ height: CGFloat) {
        let g = MultiplatformCommon.getCurrentContext()
        g?.saveGState()
        g?.translateBy(x: 0.0, y: height)
        g?.scaleBy(x: 1.0, y: -1.0)
        if let cgImg = img.cgImage {
            g?.draw(cgImg, in: CGRect(x: x, y: -y, width: width, height: height))
        }
        g?.restoreGState()
    }
    #else
    func drawImage(_ img: NSImage, _ x: CGFloat, _ y: CGFloat) {
        let g = MultiplatformCommon.getCurrentContext()
        g?.saveGState()
        g?.translateBy(x: 0.0, y: img.size.height)
        g?.scaleBy(x: 1.0, y: -1.0)
        if let cgImg = img.cgImage {
            g?.draw(cgImg, in: CGRect(x: x, y: y, width: img.size.width, height: img.size.height))
        }
        g?.restoreGState()
    }

    func drawImage(_ img: NSImage, _ x: CGFloat, _ y: CGFloat, _ width: CGFloat, _ height: CGFloat) {
        let g = MultiplatformCommon.getCurrentContext()
        g?.saveGState()
        g?.translateBy(x: 0.0, y: height)
        g?.scaleBy(x: 1.0, y: -1.0)
        if let cgImg = img.cgImage {
            g?.draw(cgImg, in: CGRect(x: x, y: -y, width: width, height: height))
        }
        g?.restoreGState()
    }
    #endif
}

// MARK: - ProcessingView Public APIs
extension ProcessingView: ImageModelContract {
    #if os(iOS)
    public func image(_ img: UIImage, _ x: CGFloat, _ y: CGFloat) {
        self.imageModel.image(img, x, y)
    }

    public func image(_ img: UIImage, _ x: CGFloat, _ y: CGFloat, _ width: CGFloat, _ height: CGFloat) {
        self.imageModel.image(img, x, y, width, height)
    }
    #else
    public func drawImage(_ img: NSImage, _ x: CGFloat, _ y: CGFloat) {
        self.imageModel.drawImage(img, x, y)
    }

    public func drawImage(_ img: NSImage, _ x: CGFloat, _ y: CGFloat, _ width: CGFloat, _ height: CGFloat) {
        self.imageModel.drawImage(img, x, y, width, height)
    }
    #endif
}

{'fraction_non_alphanumeric': 0.1380046998504593, 'fraction_numerical': 0.01281777397991882, 'mean_word_length': 2.432551319648094, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '2338905', 'n_tokens_mistral': 1776, 'n_tokens_neox': 1723, 'n_words': 453}