Skip to content

steps should be discrete offsets from lowerBound #71

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Sources/Sliders/Base/LinearValueMath.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import SwiftUI
/// Example: For relative value 0.5 in range 2.0..4.0 produces 3.0
@inlinable func valueFrom(distance: CGFloat, availableDistance: CGFloat, bounds: ClosedRange<CGFloat> = 0.0...1.0, step: CGFloat = 0.001, leadingOffset: CGFloat = 0, trailingOffset: CGFloat = 0) -> CGFloat {
let relativeValue = (distance - leadingOffset) / (availableDistance - (leadingOffset + trailingOffset))
let newValue = bounds.lowerBound + (relativeValue * (bounds.upperBound - bounds.lowerBound))
let steppedNewValue = (round(newValue / step) * step)
let newValue = relativeValue * (bounds.upperBound - bounds.lowerBound)
let steppedNewValue = bounds.lowerBound + round(newValue / step) * step
let validatedValue = min(bounds.upperBound, max(bounds.lowerBound, steppedNewValue))
return validatedValue
}
Expand Down