Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Make tick finding more compatible with Float64 #161

Merged
merged 5 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
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
5 changes: 4 additions & 1 deletion src/ticks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,10 @@ function optimize_ticks(
span_buffer = nothing,
scale = nothing,
) where {T}
x_min ≈ x_max && return fallback_ticks(x_min, x_max, k_min, k_max, strict_span)
rtol = T <: AbstractFloat ? 1000.0 * eps(T) : Base.rtoldefault(x_min, x_max, 0)
if isapprox(x_min, x_max, rtol = rtol)
return fallback_ticks(x_min, x_max, k_min, k_max, strict_span)
end

F = float(T)
Qv = F[q[1] for q ∈ Q]
Expand Down
3 changes: 3 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ end
@testset "ticks" begin
@test optimize_ticks(-1, 2) == ([-1.0, 0.0, 1.0, 2.0], -1.0, 2.0)

# check if ticks still generate if max - min << abs(min) (i.e. for Float64 ranges)
@test optimize_ticks(1e11 - 1, 1e11 + 2) == (1e11 .+ (-1:2), 1e11 - 1.0, 1e11 + 2.0)

@testset "dates" begin
dt1, dt2 = Dates.value(DateTime(2000)), Dates.value(DateTime(2100))
@test optimize_datetime_ticks(dt1, dt2) == (
Expand Down
Loading