<commit_before>//
//  DoubleLayout.swift
//  PhotoCollectionView
//
//  Created by luan on 9/2/17.
//
//

import UIKit

class DoubleLayout: PhotoLayoutProtocol {
    var contentSize: CGSize = CGSize.zero
    var itemSize: CGSize = CGSize.zero
    
    var maxPhoto: Int {
        return 2
    }
    
    func frame(at index: Int, in photoCollectionView: PhotoCollectionView) -> CGRect {
        guard index >= 0 && index < maxPhoto else {
            return CGRect.zero
        }
        if index == 1 {
            return CGRect(origin: CGPoint(x: spacing, y: spacing * 2 + itemSize.width), size: itemSize)
        }
        
        contentSize = photoCollectionView.bounds.size
        guard let image = photoCollectionView.image(at: index) else {
            return CGRect(origin: .zero, size: contentSize)
        }
        let width = (photoCollectionView.bounds.width - spacing * CGFloat(maxPhoto + 1)) / CGFloat(maxPhoto)
        var height = width * image.size.height / image.size.width
        height = min(height, width * 1.25)
        itemSize = CGSize(width: width, height: height)
        contentSize = CGSize(width: photoCollectionView.bounds.width, height: height)
        return CGRect(origin: .zero, size: contentSize)
    }
    
    func contentSize(of photoCollectionView: PhotoCollectionView) -> CGSize {
        return contentSize
    }

}<commit_msg>Update calculate frame in DoubleLayout<commit_after>//
//  DoubleLayout.swift
//  PhotoCollectionView
//
//  Created by luan on 9/2/17.
//
//

import UIKit

class DoubleLayout: PhotoLayoutProtocol {
    var contentSize: CGSize = CGSize.zero
    var itemSize: CGSize = CGSize.zero
    var isVertical = false
    
    var maxPhoto: Int {
        return 2
    }
    
    func frame(at index: Int, in photoCollectionView: PhotoCollectionView) -> CGRect {
        guard index >= 0 && index < maxPhoto else {
            return CGRect.zero
        }
        if index == 0 {
            if let image = photoCollectionView.image(at: index) {
                let ratio = image.size.height / image.size.width
                isVertical = ratio > 1.0
                if isVertical {
                    let width = (photoCollectionView.bounds.width - spacing * 3) / 2
                    itemSize = CGSize(width: width, height: width * min(ratio, 1.25))
                } else {
                    let width = photoCollectionView.bounds.width - spacing * 2
                    itemSize = CGSize(width: width, height: width * min(ratio, 0.8))
                }
            } else {
                isVertical = false
                itemSize = CGSize(width: photoCollectionView.bounds.width - spacing * 2,
                                  height: photoCollectionView.bounds.height - spacing * 3)
            }
        }
        
        let x = spacing + (spacing + itemSize.width) * CGFloat(isVertical ? index : 0)
        let y = spacing + (spacing + itemSize.height) * CGFloat(isVertical ? 0 : index)
        return CGRect(origin: CGPoint(x: x, y: y), size: itemSize)
    }
    
    func contentSize(of photoCollectionView: PhotoCollectionView) -> CGSize {
        return contentSize
    }

}
{'fraction_non_alphanumeric': 0.09563014566181127, 'fraction_numerical': 0.01044965167827739, 'mean_word_length': 1.949579831932773, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5154231', 'n_tokens_mistral': 949, 'n_tokens_neox': 872, 'n_words': 241}