//
//  CGPoint.swift
//  USB Meter
//
//  Created by Bogdan Timofte on 10/05/2020.
//  Copyright © 2020 Bogdan Timofte. All rights reserved.
//

import CoreGraphics

extension CGPoint {
    func moveDown(by: CGFloat) -> CGPoint {
        return CGPoint(x: self.x, y: self.y + by)
    }

    func moveUp(by: CGFloat) -> CGPoint {
        return CGPoint(x: self.x, y: self.y - by)
    }

    func putInBounds (minX: CGFloat, maxX: CGFloat, minY: CGFloat, maxY: CGFloat) -> CGPoint {
        let xRange = maxX - minX
        let yRange = maxY - minY
        let xValue = self.x - minX
        let yValue = self.y - minY
        print ("self: \(self) xRange:\(xRange) yRange:\(yRange) xValue:\(xValue) yValue:\(yValue) ")
        return CGPoint(x: xValue / xRange, y: yValue / yRange)
    }
}
