From 26aefb318984debf822c1b5773dc4331607b9f01 Mon Sep 17 00:00:00 2001 From: Florian Henkes Date: Wed, 28 Feb 2024 11:16:20 +0100 Subject: [PATCH 1/3] Fix initial value of high counter --- src/intersect.jl | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/intersect.jl b/src/intersect.jl index 2a7a448..68755bf 100644 --- a/src/intersect.jl +++ b/src/intersect.jl @@ -45,7 +45,7 @@ function _find_intersect_impl(X::AbstractVector{<:RealQuantity}, Y::AbstractVect cand_pos::Int = firstindex(Y) + 1 intersect_pos::Int = firstindex(Y) + 1 - y_high_counter::Int = ifelse(first(Y) > threshold, min_n_over_thresh + 1, 0) + y_high_counter::Int = ifelse(first(Y) >= threshold, min_n_over_thresh + 1, 0) n_intersects::Int = 0 @inbounds for i in eachindex(Y) @@ -61,7 +61,11 @@ function _find_intersect_impl(X::AbstractVector{<:RealQuantity}, Y::AbstractVect intersect_pos = ifelse(first_intersect_found, cand_pos, intersect_pos) end - @assert intersect_pos > firstindex(Y) + #TODO: return NaN if position found is unphysical but make sure it is compatible with the other routines + # @assert intersect_pos > firstindex(Y) + if intersect_pos <= firstindex(Y) + intersect_pos = firstindex(Y) + 1 + end # Linear interpolation: x_l = X[intersect_pos - 1] From ba1fe2f3a8a6dad0cb54244572a0e9dba6e326b5 Mon Sep 17 00:00:00 2001 From: Florian Henkes Date: Wed, 28 Feb 2024 11:23:37 +0100 Subject: [PATCH 2/3] Include assert if intersect still fails --- src/intersect.jl | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/intersect.jl b/src/intersect.jl index 68755bf..a4d4747 100644 --- a/src/intersect.jl +++ b/src/intersect.jl @@ -62,10 +62,7 @@ function _find_intersect_impl(X::AbstractVector{<:RealQuantity}, Y::AbstractVect end #TODO: return NaN if position found is unphysical but make sure it is compatible with the other routines - # @assert intersect_pos > firstindex(Y) - if intersect_pos <= firstindex(Y) - intersect_pos = firstindex(Y) + 1 - end + @assert intersect_pos > firstindex(Y) # Linear interpolation: x_l = X[intersect_pos - 1] From c6f8d23521df968337a5abfd5bd8d313e44df1d5 Mon Sep 17 00:00:00 2001 From: Florian Henkes Date: Wed, 28 Feb 2024 11:24:02 +0100 Subject: [PATCH 3/3] Remove comments --- src/intersect.jl | 1 - 1 file changed, 1 deletion(-) diff --git a/src/intersect.jl b/src/intersect.jl index a4d4747..35bc6b3 100644 --- a/src/intersect.jl +++ b/src/intersect.jl @@ -61,7 +61,6 @@ function _find_intersect_impl(X::AbstractVector{<:RealQuantity}, Y::AbstractVect intersect_pos = ifelse(first_intersect_found, cand_pos, intersect_pos) end - #TODO: return NaN if position found is unphysical but make sure it is compatible with the other routines @assert intersect_pos > firstindex(Y) # Linear interpolation: