Skip to content
This repository was archived by the owner on Nov 22, 2023. It is now read-only.

Commit

Permalink
Merge pull request #175 from CarpeNecopinum/fix_minimum_extrema
Browse files Browse the repository at this point in the history
Fixed inconsistency between extrema and minimum/maximum
  • Loading branch information
SimonDanisch authored Jul 23, 2019
2 parents b9408b9 + 214f615 commit 9294dcb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/FixedSizeArrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,10 @@ function Base.extrema(a::AbstractVector{T}) where T <: FixedVector
reduce((x, v)-> (min.(x[1], v), max.(x[2], v)), a; init = (T(typemax(ET)), T(typemin(ET))))
end
function Base.minimum(a::AbstractVector{T}) where T <: FixedVector
reduce((x, v)-> min.(x[1], v), a; init=T(typemax(eltype(T))))
reduce((x, v)-> min.(x, v), a; init=T(typemax(eltype(T))))
end
function Base.maximum(a::AbstractVector{T}) where T <: FixedVector
reduce((x, v)-> max.(x[1], v), a; init=T(typemin(eltype(T))))
reduce((x, v)-> max.(x, v), a; init=T(typemin(eltype(T))))
end


Expand Down
18 changes: 18 additions & 0 deletions test/baseutils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,21 @@

@test_throws ArgumentError GeometryTypes.argmax(identity, [])
end

@testset "extrema" begin
xs = [GeometryTypes.Vec2f0(1f0, 1f0), GeometryTypes.Vec2f0(0.5f0, 1.5f0)]
extr = extrema(xs)

@test extr[1] GeometryTypes.Vec2f0(0.5f0, 1f0)
@test extr[2] GeometryTypes.Vec2f0(1f0, 1.5f0)

@testset "minimum" begin
val = minimum(xs)
@test val extr[1]
end

@testset "maximum" begin
val = maximum(xs)
@test val extr[2]
end
end

0 comments on commit 9294dcb

Please sign in to comment.