Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin-Mattheus-Moerman committed Feb 29, 2024
2 parents bafad44 + b640129 commit 8d56c60
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 37 deletions.
4 changes: 2 additions & 2 deletions src/functions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ function elements2indices(F)
return unique(reduce(vcat,F))
end

function gridpoints(x::Vector{T}, y=x::Vector{T}, z=x::Vector{T}) where T<:Real
function gridpoints(x::Vector{T}, y=x, z=x) where T<:Real
reshape([GeometryBasics.Point{3, T}(x, y, z) for z in z, y in y, x in x],
length(x)*length(y)*length(z))
end

function gridpoints(x::AbstractRange{T}, y=x::AbstractRange{T}, z=x::AbstractRange{T}) where T<:Real
function gridpoints(x::AbstractRange{T}, y=x, z=x) where T<:Real
reshape([GeometryBasics.Point{3, T}(x, y, z) for z in z, y in y, x in x],
length(x)*length(y)*length(z))
end
Expand Down
34 changes: 0 additions & 34 deletions test/Manifest.toml

This file was deleted.

1 change: 1 addition & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
[deps]
GeometryBasics = "5c1252a2-5f33-56bf-86c9-59e7332b4326"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
48 changes: 47 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Test, Comodo
using Test, Comodo, GeometryBasics

@testset "dist" verbose = true begin

Expand All @@ -8,4 +8,50 @@ using Test, Comodo
result = dist(v1, v2)

@test result == [0.0 0.0 5.0; 0.0 0.0 5.0; 0.0 0.0 5.0]
end

@testset "gridpoints" verbose = true begin

@testset "with 1 vector" begin
a = Float64[1, 2, 3]

expected = Point3{Float64}[[1.0, 1.0, 1.0], [1.0, 1.0, 2.0], [1.0, 1.0, 3.0], [1.0, 2.0, 1.0], [1.0, 2.0, 2.0], [1.0, 2.0, 3.0], [1.0, 3.0, 1.0], [1.0, 3.0, 2.0], [1.0, 3.0, 3.0], [2.0, 1.0, 1.0], [2.0, 1.0, 2.0], [2.0, 1.0, 3.0], [2.0, 2.0, 1.0], [2.0, 2.0, 2.0], [2.0, 2.0, 3.0], [2.0, 3.0, 1.0], [2.0, 3.0, 2.0], [2.0, 3.0, 3.0], [3.0, 1.0, 1.0], [3.0, 1.0, 2.0], [3.0, 1.0, 3.0], [3.0, 2.0, 1.0], [3.0, 2.0, 2.0], [3.0, 2.0, 3.0], [3.0, 3.0, 1.0], [3.0, 3.0, 2.0], [3.0, 3.0, 3.0]]

result = gridpoints(a)

@test result == expected
end

@testset "with 2 vectors" begin
a = Float64[1, 2, 3]
b = Float64[2, 3, 5]

expected = Point3{Float64}[[1.0, 2.0, 1.0], [1.0, 2.0, 2.0], [1.0, 2.0, 3.0], [1.0, 3.0, 1.0], [1.0, 3.0, 2.0], [1.0, 3.0, 3.0], [1.0, 5.0, 1.0], [1.0, 5.0, 2.0], [1.0, 5.0, 3.0], [2.0, 2.0, 1.0], [2.0, 2.0, 2.0], [2.0, 2.0, 3.0], [2.0, 3.0, 1.0], [2.0, 3.0, 2.0], [2.0, 3.0, 3.0], [2.0, 5.0, 1.0], [2.0, 5.0, 2.0], [2.0, 5.0, 3.0], [3.0, 2.0, 1.0], [3.0, 2.0, 2.0], [3.0, 2.0, 3.0], [3.0, 3.0, 1.0], [3.0, 3.0, 2.0], [3.0, 3.0, 3.0], [3.0, 5.0, 1.0], [3.0, 5.0, 2.0], [3.0, 5.0, 3.0]]

result = gridpoints(a, b)

@test result == expected
end

@testset "with 3 vectors" begin
a = Float64[1, 2, 3]
b = Float64[2, 3, 5]
c = Float64[5, 6, 4]

expected = GeometryBasics.Point3{Float64}[[1.0, 2.0, 5.0], [1.0, 2.0, 6.0], [1.0, 2.0, 4.0], [1.0, 3.0, 5.0], [1.0, 3.0, 6.0], [1.0, 3.0, 4.0], [1.0, 5.0, 5.0], [1.0, 5.0, 6.0], [1.0, 5.0, 4.0], [2.0, 2.0, 5.0], [2.0, 2.0, 6.0], [2.0, 2.0, 4.0], [2.0, 3.0, 5.0], [2.0, 3.0, 6.0], [2.0, 3.0, 4.0], [2.0, 5.0, 5.0], [2.0, 5.0, 6.0], [2.0, 5.0, 4.0], [3.0, 2.0, 5.0], [3.0, 2.0, 6.0], [3.0, 2.0, 4.0], [3.0, 3.0, 5.0], [3.0, 3.0, 6.0], [3.0, 3.0, 4.0], [3.0, 5.0, 5.0], [3.0, 5.0, 6.0], [3.0, 5.0, 4.0]]

result = gridpoints(a, b, c)

@test result == expected
end

@testset "Equality of several results" begin
a = Float64[1, 2, 3]

result1 = gridpoints(a)
result2 = gridpoints(a, a)
result3 = gridpoints(a, a, a)

@test allequal([result1, result2, result3])
end
end

0 comments on commit 8d56c60

Please sign in to comment.