<commit_before>//
//  UIView+PlaceIt.swift
//  PlaceIt
//
//  Created by <NAME> on 02.08.14.
//  Copyright (c) 2014 <NAME>. All rights reserved.
//

import UIKit

public enum HorizontalPosition {
    case Left(CGFloat)
    case Center
    case Right(CGFloat)
    case EdgeToEdge
}

public enum VerticalPosition {
    case Top(CGFloat)
    case Above(UIView, CGFloat)
    case Center
    case Bottom(CGFloat)
    case Below(UIView, CGFloat)
    case EdgeToEdge(CGFloat)
}

public enum LayoutDirection {
    case TopToBottom
    case LeftToRight
}

public struct Position {
    var horizontal: HorizontalPosition
    var vertical: VerticalPosition
}

public extension UIView {
    func layoutSubview(subview: UIView, atPosition position: Position) -> Self {
        return layoutSubview(subview, atPosition: position, withSize: subview.sizeThatFits(bounds.size))
    }

    func layoutSubview(subview: UIView, atPosition position: Position, withSize size: CGSize) -> Self {
        return layoutSubview(subview, atPosition: position, withSize: size, inRect: bounds)
    }

    func layoutSubview(subview: UIView, atPosition position: Position, withSize size: CGSize, inRect layoutRect:CGRect) -> Self {
        assert(subview.isDescendantOfView(self), "subview is no descendant of self");

        var frame = CGRect(origin: CGPointZero, size: size)

        switch position.horizontal {
        case .Left(let inset):
            frame.origin.x = CGRectGetMinX(layoutRect) + inset
        case .Center:
            frame.origin.x = CGRectGetMidX(layoutRect) - size.width / 2.0
        case .Right(let inset):
            frame.origin.x = CGRectGetMaxX(layoutRect) - size.width - inset
        case .EdgeToEdge:
            frame.origin.x = CGRectGetMinX(layoutRect)
            frame.size.width = CGRectGetWidth(layoutRect)
        }

        switch position.vertical {
        case .Top(let inset):
            frame.origin.y = CGRectGetMinY(layoutRect) + inset
        case .Above(let view, let offset):<commit_msg>Adds layoutSubview:atPosition:inRect.<commit_after>//
//  UIView+PlaceIt.swift
//  PlaceIt
//
//  Created by <NAME> on 02.08.14.
//  Copyright (c) 2014 <NAME>. All rights reserved.
//

import UIKit

public enum HorizontalPosition {
    case Left(CGFloat)
    case Center
    case Right(CGFloat)
    case EdgeToEdge
}

public enum VerticalPosition {
    case Top(CGFloat)
    case Above(UIView, CGFloat)
    case Center
    case Bottom(CGFloat)
    case Below(UIView, CGFloat)
    case EdgeToEdge(CGFloat)
}

public enum LayoutDirection {
    case TopToBottom
    case LeftToRight
}

public struct Position {
    var horizontal: HorizontalPosition
    var vertical: VerticalPosition
}

public extension UIView {
    func layoutSubview(subview: UIView, atPosition position: Position) -> Self {
        return layoutSubview(subview, atPosition: position, withSize: subview.sizeThatFits(bounds.size))
    }

    func layoutSubview(subview: UIView, atPosition position: Position, withSize size: CGSize) -> Self {
        return layoutSubview(subview, atPosition: position, withSize: size, inRect: bounds)
    }

    func layoutSubview(subview: UIView, atPosition position: Position, inRect rect: CGRect) -> Self {
        return layoutSubview(subview, atPosition: position, withSize: subview.sizeThatFits(rect.size), inRect: rect)
    }

    func layoutSubview(subview: UIView, atPosition position: Position, withSize size: CGSize, inRect layoutRect:CGRect) -> Self {
        assert(subview.isDescendantOfView(self), "subview is no descendant of self");

        var frame = CGRect(origin: CGPointZero, size: size)

        switch position.horizontal {
        case .Left(let inset):
            frame.origin.x = CGRectGetMinX(layoutRect) + inset
        case .Center:
            frame.origin.x = CGRectGetMidX(layoutRect) - size.width / 2.0
        case .Right(let inset):
            frame.origin.x = CGRectGetMaxX(layoutRect) - size.width - inset
        case .EdgeToEdge:
            frame.origin.x = CGRectGetMinX(layoutRect)
            frame.size.width = CGRectGetWidth(layoutRect)
        }

        switch position.vertical {
        case .Top(let inset):
            frame.origin.y = CGRectGetMinY(layoutRect) + inset
        case .Above(let view, let offset):
{'fraction_non_alphanumeric': 0.09341429238673517, 'fraction_numerical': 0.005604857543204111, 'mean_word_length': 2.9657407407407406, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 14, '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': '894784', 'n_tokens_mistral': 1340, 'n_tokens_neox': 1271, 'n_words': 338}