<commit_before>//
//  SnapPoint.swift
//  SplitScreen
//
//  Created by <NAME> on 3/4/16.
//  Copyright © 2016 SplitScreen. All rights reserved.
//

import Foundation
import AppKit

class SnapPoint{
    
    private var snap_point = [((Int,Int),(Int,Int))]() // All snap locations that can snap to a point
    private var snap_location: (Int, Int)
    private var dimensions: (Int, Int)
    private var logic: Int
    private var orig_height: Int
    private var orig_width: Int
    
    /**
        Initializes this SnapPoint
     
        Parameters:
        
        height - the original height this layout was designed for
     
        width - the original width this layout was designed for
     
        x_dim - the x dimension of the resize
     
        y_dim - the y dimension of the resize
     
        x_snap_loc - the x-coordinate of where the window will be moved to
     
        y_snap_loc - the y-coordinate of where the window will be moved to
     
        log - the logic bit to determine what action will be performed by the snap
     */
    init(height: Int, width: Int, x_dim: Int, y_dim: Int, x_snap_loc: Int, y_snap_loc: Int, log: Int) {
        snap_location = (x_snap_loc, y_snap_loc)
        dimensions = (x_dim,y_dim)
        logic = log
        orig_height = height
        orig_width = width
    }
    
    /**
        Adds a new snap_point definition
     
        Parameters:
     
        x0 - left x-coordinate
        
        y0 - low y-coordinate
     
        x1 - right x-coordinate
     
        y1 - high y-coordinate
     
        [NOTE: at least one number in the pairings of x0,y0 and x1,y1 must be 0]
     
    */
    func add_snap_point(x0: Int, y0: Int, x1: Int, y1: Int) -> Bool {
        
        if x0 > x1 || y0 > y1 {
            return false
        }
        
        snap_point.append(((x0, y0),(x1, y1)))
        return true
    }
    
    
    /**
        Checks if a location falls under this snap point
     
        Parameters: 
        
        x - x value of location to check
     
        y - y value of location to check
     */
    func check_point(x: Int, y: Int) -> Bool {
        
        let (scale_factor_h, scale_factor_w) = get_scale_factors()
        
        // run through each snap_point and check if it fits the guessed location
        for snaps in snap_point{
            
            print("snap_point scaled: x0: \(CGFloat(snaps.0.0) * scale_factor_w) x1: \(CGFloat(snaps.1.0) * scale_factor_w) y0: \(CGFloat(snaps.0.1) * scale_factor_h) y1: \(CGFloat(snaps.1.1) * scale_factor_h)")
            
            if x >= Int(CGFloat(snaps.0.0) * scale_factor_w) && x <= Int(CGFloat(snaps.1.0) * scale_factor_w) && y >= Int(CGFloat(snaps.0.1) * scale_factor_h) && y <= Int(CGFloat(snaps.1.1) * scale_factor_h) {
                print(" - falls in range (\(x),\(y))")
                return true
            }
            
        }
        return false
    }
    
    
    /**
        Returns scaled snap_location value (left hand corner of the snap)
     */
    func get_snap_location() -> (Int, Int) {
        let (scale_factor_h, scale_factor_w) = get_scale_factors()
        
        return (Int(CGFloat(snap_location.0) * scale_factor_w), Int(CGFloat(snap_location.1) * scale_factor_h))

    }
    
    /**
        Returns scaled dimensions of SnapPoint
     */
    func get_dimensions() -> (Int, Int) {
        
        let (scale_factor_h, scale_factor_w) = get_scale_factors()
        
        return (Int(CGFloat(dimensions.0) * scale_factor_w), Int(CGFloat(dimensions.1) * scale_factor_h))
    }
    
    /**
        Returns the logic associated with the snap
     */
    func get_logic() -> Int {
        return Int(logic)
    }

    /**
        Returns the resolution (height, width) that this layout was made with
     
        NOTE: Use for scaling purposes with different resolutions
     */
    func get_orig_resolution() -> (Int, Int){
        return (Int(orig_height), Int(orig_width))
	}
	
	
	func get_string_scalar_representation(scalar: Int, original: Int, original_string: String) -> String {
		if scalar == 0 {
			return "0"
		}
		if (scalar + 1) == original {
			return "\(original_string)-1"
		}
		let scale = original/scalar
		return "\(original_string)/\(scale)"
	}
	
	func get_string_snap_point(point: (Int,Int), height: Int, width: Int) -> String {
		let scalar_x = get_string_scalar_representation(point.0, original: width, original_string: "WIDTH")
		let scalar_y = get_string_scalar_representation(point.1, original: height, original_string: "HEIGHT")
		return "(\(scalar_x); \(scalar_y))"
	}

	/**
		Returns the string representation of the SnapPoint
	*/
	func get_string_representation(screenHeight: Int, screenWidth: Int) -> String {
		var ret_String: String = String()
		ret_String = ret_String.stringByAppendingString("HEIGHT")
		ret_String.append("," as Character)
		ret_String = ret_String.stringByAppendingString("WIDTH")
		ret_String.append("," as Character)
		ret_String = ret_String.stringByAppendingString(
			self.get_string_scalar_representation(dimensions.0,
				original: screenWidth,
				original_string: "WIDTH"))
		
		ret_String.append("," as Character)
		ret_String = ret_String.stringByAppendingString(
			self.get_string_scalar_representation(dimensions.1,
				original: screenHeight,
				original_string: "HEIGHT"))
		
		ret_String.append("," as Character)<commit_msg>Cleaned up file contents<commit_after>//
//  SnapPoint.swift
//  SplitScreen
//
//  Created by <NAME> on 3/4/16.
//  Copyright © 2016 SplitScreen. All rights reserved.
//

import Foundation
import AppKit

class SnapPoint{
    
    private var snap_point = [((Int,Int),(Int,Int))]() // All snap locations that can snap to a point
    private var snap_location: (Int, Int)
    private var dimensions: (Int, Int)
    private var logic: Int
    private var orig_height: Int
    private var orig_width: Int
    
    /**
        Initializes this SnapPoint
     
        Parameters:
        
        height - the original height this layout was designed for
     
        width - the original width this layout was designed for
     
        x_dim - the x dimension of the resize
     
        y_dim - the y dimension of the resize
     
        x_snap_loc - the x-coordinate of where the window will be moved to
     
        y_snap_loc - the y-coordinate of where the window will be moved to
     
        log - the logic bit to determine what action will be performed by the snap
     */
    init(height: Int, width: Int, x_dim: Int, y_dim: Int, x_snap_loc: Int, y_snap_loc: Int, log: Int) {
        snap_location = (x_snap_loc, y_snap_loc)
        dimensions = (x_dim,y_dim)
        logic = log
        orig_height = height
        orig_width = width
    }
    
    /**
        Adds a new snap_point definition
     
        Parameters:
     
        x0 - left x-coordinate
        
        y0 - low y-coordinate
     
        x1 - right x-coordinate
     
        y1 - high y-coordinate
     
        [NOTE: at least one number in the pairings of x0,y0 and x1,y1 must be 0]
     
    */
    func add_snap_point(x0: Int, y0: Int, x1: Int, y1: Int) -> Bool {
        
        if x0 > x1 || y0 > y1 {
            return false
        }
        
        snap_point.append(((x0, y0),(x1, y1)))
        return true
    }
    
    
    /**
        Checks if a location falls under this snap point
     
        Parameters: 
        
        x - x value of location to check
     
        y - y value of location to check
     */
    func check_point(x: Int, y: Int) -> Bool {
        
        let (scale_factor_h, scale_factor_w) = get_scale_factors()
        
        // run through each snap_point and check if it fits the guessed location
        for snaps in snap_point{
            
            print("snap_point scaled: x0: \(CGFloat(snaps.0.0) * scale_factor_w) x1: \(CGFloat(snaps.1.0) * scale_factor_w) y0: \(CGFloat(snaps.0.1) * scale_factor_h) y1: \(CGFloat(snaps.1.1) * scale_factor_h)")
            
            if x >= Int(CGFloat(snaps.0.0) * scale_factor_w) && x <= Int(CGFloat(snaps.1.0) * scale_factor_w) && y >= Int(CGFloat(snaps.0.1) * scale_factor_h) && y <= Int(CGFloat(snaps.1.1) * scale_factor_h) {
                print(" - falls in range (\(x),\(y))")
                return true
            }
            
        }
        return false
    }
    
    
    /**
        Returns scaled snap_location value (left hand corner of the snap)
     */
    func get_snap_location() -> (Int, Int) {
        let (scale_factor_h, scale_factor_w) = get_scale_factors()
        
        return (Int(CGFloat(snap_location.0) * scale_factor_w), Int(CGFloat(snap_location.1) * scale_factor_h))

    }
    
    /**
        Returns scaled dimensions of SnapPoint
     */
    func get_dimensions() -> (Int, Int) {
        
        let (scale_factor_h, scale_factor_w) = get_scale_factors()
        
        return (Int(CGFloat(dimensions.0) * scale_factor_w), Int(CGFloat(dimensions.1) * scale_factor_h))
    }
    
    /**
        Returns the logic associated with the snap
     */
    func get_logic() -> Int {
        return Int(logic)
    }

    /**
        Returns the resolution (height, width) that this layout was made with
     
        NOTE: Use for scaling purposes with different resolutions
     */
    func get_orig_resolution() -> (Int, Int){
        return (Int(orig_height), Int(orig_width))
	}
	
	
	func get_string_scalar_representation(scalar: Int, original: Int, original_string: String) -> String {
		if scalar == 0 {
			return "0"
		}
		if (scalar + 1) == original {
			return "\(original_string)-1"
		}
		if original == scalar {
			return "\(original_string)"
		}
		
		let scale = original/scalar
		return "\(original_string)/\(scale)"
	}
	
	func get_string_snap_point(point: (Int,Int), height: Int, width: Int) -> String {
		let scalar_x = get_string_scalar_representation(point.0, original: width, original_string: "WIDTH")
		let scalar_y = get_string_scalar_representation(point.1, original: height, original_string: "HEIGHT")
		return "(\(scalar_x);\(scalar_y))"
	}

	/**
		Returns the string representation of the SnapPoint
	*/
	func get_string_representation(screenHeight: Int, screenWidth: Int) -> String {
		var ret_String: String = String()
		ret_String = ret_String.stringByAppendingString("HEIGHT")
		ret_String.append("," as Character)
		ret_String = ret_String.stringByAppendingString("WIDTH")
		ret_String.append("," as Character)
		ret_String = ret_String.stringByAppendingString(
			self.get_string_scalar_representation(dimensions.0,
				original: screenWidth,
				original_string: "WIDTH"))
		
		ret_String.append("," as Character)
		ret_String = ret_String.stringByAppendingString(
			self.get_string_scalar_representation(dimensions.1,
				original: screenHeight,
				original_string: "HEIGHT"))
		
		ret_String.append("," as Character)
{'fraction_non_alphanumeric': 0.10194888766317338, 'fraction_numerical': 0.011215296929582643, 'mean_word_length': 2.2827398913699457, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 31, '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': '3689247', 'n_tokens_mistral': 3580, 'n_tokens_neox': 3390, 'n_words': 944}