You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
56 lines
1.1 KiB
56 lines
1.1 KiB
1 year ago
|
//
|
||
|
// Float+Extension.swift
|
||
|
// HPlusFit
|
||
|
//
|
||
|
// Created by lemo. on 2019/10/15.
|
||
|
// Copyright © 2019 lemo. All rights reserved.
|
||
|
//
|
||
|
|
||
|
import Foundation
|
||
|
|
||
|
extension Float {
|
||
|
var strideBegin: Int {
|
||
|
let mid = Int(self)/2
|
||
|
let begin = (mid/self.strideStep)*self.strideStep
|
||
|
return begin
|
||
|
}
|
||
|
|
||
|
var strideEnd: Int {
|
||
|
var end: Int = 10
|
||
|
for i in 1...10 {
|
||
|
let result = powf(10, Float(i))
|
||
|
if result > self {
|
||
|
end = Int(result)
|
||
|
break
|
||
|
}
|
||
|
}
|
||
|
return end
|
||
|
}
|
||
|
|
||
|
var strideStep: Int {
|
||
|
var step: Int = 1
|
||
|
let end = self.strideEnd
|
||
|
if end > 100 {
|
||
|
step = end/100
|
||
|
}else {
|
||
|
step = end/10
|
||
|
}
|
||
|
|
||
|
return step
|
||
|
}
|
||
|
|
||
|
var maxAxis: Int {
|
||
|
var result: Int = 0
|
||
|
let begin = self.strideBegin
|
||
|
let end = self.strideEnd
|
||
|
let step = self.strideStep
|
||
|
for i in stride(from: begin, to: end, by: step) {
|
||
|
if Float(i * 2) >= self {
|
||
|
result = i * 2
|
||
|
break
|
||
|
}
|
||
|
}
|
||
|
return result
|
||
|
}
|
||
|
}
|