//
//  AppleGuidelinesProtocol.swift
//  MVMCoreUI
//
//  Created by Kevin Christiano on 12/20/19.
//  Copyright © 2019 Verizon Wireless. All rights reserved.
//

import UIKit


public protocol AppleGuidelinesProtocol {
    static var minimumTappableArea: CGFloat { get }
    static func acceptablyOutsideBounds(point: CGPoint, bounds: CGRect) -> Bool
}

extension AppleGuidelinesProtocol {
    
    static public var minimumTappableArea: CGFloat {
        return 44.0
    }
    
     // If the control is smaller than 44pt by width or height, this will compensate.
    static public func acceptablyOutsideBounds(point: CGPoint, bounds: CGRect) -> Bool {
        
        let faultToleranceX: CGFloat = max((minimumTappableArea - bounds.size.width) / 2.0, 0)
        let faultToleranceY: CGFloat = max((minimumTappableArea - bounds.size.height) / 2.0, 0)
        let area = bounds.insetBy(dx: -faultToleranceX, dy: -faultToleranceY)
        
        return area.contains(point)
    }
}
