From abd43df37b27638e4ee0f0502f49e0863fa27b0f Mon Sep 17 00:00:00 2001 From: Evert Schippers Date: Wed, 11 Sep 2019 09:46:01 +1000 Subject: [PATCH 1/2] Aliases for 2D and 3D Float64 vectors. --- src/SVector.jl | 2 ++ test/SVector.jl | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/SVector.jl b/src/SVector.jl index 40fe8614..166ed573 100644 --- a/src/SVector.jl +++ b/src/SVector.jl @@ -14,6 +14,8 @@ The parameter `S` is mandatory since the length of `vec` is unknown to the compiler (the element type may optionally also be specified). """ const SVector{S, T} = SArray{Tuple{S}, T, 1, S} +const Vector3D = SVector{3, Float64} +const Vector2D = SVector{2, Float64} @inline SVector(x::NTuple{S,Any}) where {S} = SVector{S}(x) @inline SVector{S}(x::NTuple{S,T}) where {S, T} = SVector{S,T}(x) diff --git a/test/SVector.jl b/test/SVector.jl index ee231142..720f111f 100644 --- a/test/SVector.jl +++ b/test/SVector.jl @@ -79,4 +79,23 @@ @test @inferred(convert(SVector, c)) == SVector{2,Int}([1, 2]) @test @inferred(convert(SVector{2}, c)) == SVector{2,Int}([1, 2]) end + + @testset "VectorAliases" begin + @test Vector3D == SArray{Tuple{3},Float64,1,3} + @test Vector2D == SArray{Tuple{2},Float64,1,2} + + v3 = Vector3D(1, 2, 3) + @test typeof(v3) == SArray{Tuple{3},Float64,1,3} + @test v3[1] == 1.0 + @test v3[2] == 2.0 + @test v3[3] == 3.0 + + v2 = Vector2D(10, 20) + @test typeof(v2) == SArray{Tuple{2},Float64,1,2} + @test v2[1] == 10.0 + @test v2[2] == 20.0 + + @test Vector3D(1,2,3) == Vector3D(1.0, 2.0, 3.0) + @test Vector2D(10,20) == Vector2D(10.0, 20.0) + end end From c792afbf7ca809731880ae60f7bc96e268896334 Mon Sep 17 00:00:00 2001 From: Evert Schippers Date: Wed, 11 Sep 2019 14:10:35 +1000 Subject: [PATCH 2/2] As 2D/3D vectors as submodule --- src/SVector.jl | 2 -- src/StaticArrays.jl | 1 + src/vectorModules.jl | 10 ++++++++++ test/SVector.jl | 18 ------------------ test/runtests.jl | 2 ++ test/vectorModules.jl | 20 ++++++++++++++++++++ 6 files changed, 33 insertions(+), 20 deletions(-) create mode 100644 src/vectorModules.jl create mode 100644 test/vectorModules.jl diff --git a/src/SVector.jl b/src/SVector.jl index 166ed573..40fe8614 100644 --- a/src/SVector.jl +++ b/src/SVector.jl @@ -14,8 +14,6 @@ The parameter `S` is mandatory since the length of `vec` is unknown to the compiler (the element type may optionally also be specified). """ const SVector{S, T} = SArray{Tuple{S}, T, 1, S} -const Vector3D = SVector{3, Float64} -const Vector2D = SVector{2, Float64} @inline SVector(x::NTuple{S,Any}) where {S} = SVector{S}(x) @inline SVector{S}(x::NTuple{S,T}) where {S, T} = SVector{S,T}(x) diff --git a/src/StaticArrays.jl b/src/StaticArrays.jl index 07c47438..25a50bc0 100644 --- a/src/StaticArrays.jl +++ b/src/StaticArrays.jl @@ -105,6 +105,7 @@ include("FieldArray.jl") include("SArray.jl") include("SMatrix.jl") include("SVector.jl") +include("vectorModules.jl") include("Scalar.jl") include("MArray.jl") include("MVector.jl") diff --git a/src/vectorModules.jl b/src/vectorModules.jl new file mode 100644 index 00000000..757f79e1 --- /dev/null +++ b/src/vectorModules.jl @@ -0,0 +1,10 @@ +module Float64Vectors + +using StaticArrays + +export Vector2D, Vector3D + +const Vector3D = SVector{3, Float64} +const Vector2D = SVector{2, Float64} + +end \ No newline at end of file diff --git a/test/SVector.jl b/test/SVector.jl index 720f111f..0132c194 100644 --- a/test/SVector.jl +++ b/test/SVector.jl @@ -80,22 +80,4 @@ @test @inferred(convert(SVector{2}, c)) == SVector{2,Int}([1, 2]) end - @testset "VectorAliases" begin - @test Vector3D == SArray{Tuple{3},Float64,1,3} - @test Vector2D == SArray{Tuple{2},Float64,1,2} - - v3 = Vector3D(1, 2, 3) - @test typeof(v3) == SArray{Tuple{3},Float64,1,3} - @test v3[1] == 1.0 - @test v3[2] == 2.0 - @test v3[3] == 3.0 - - v2 = Vector2D(10, 20) - @test typeof(v2) == SArray{Tuple{2},Float64,1,2} - @test v2[1] == 10.0 - @test v2[2] == 20.0 - - @test Vector3D(1,2,3) == Vector3D(1.0, 2.0, 3.0) - @test Vector2D(10,20) == Vector2D(10.0, 20.0) - end end diff --git a/test/runtests.jl b/test/runtests.jl index 279cb7ad..be6af806 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -52,3 +52,5 @@ include("flatten.jl") include("io.jl") include("svd.jl") include("deprecated.jl") + +include("vectorModules.jl") \ No newline at end of file diff --git a/test/vectorModules.jl b/test/vectorModules.jl new file mode 100644 index 00000000..f546730b --- /dev/null +++ b/test/vectorModules.jl @@ -0,0 +1,20 @@ +using StaticArrays.Float64Vectors + +@testset "Float64Vectors" begin + @test Vector3D == SArray{Tuple{3},Float64,1,3} + @test Vector2D == SArray{Tuple{2},Float64,1,2} + + v3 = Vector3D(1, 2, 3) + @test typeof(v3) == SArray{Tuple{3},Float64,1,3} + @test v3[1] == 1.0 + @test v3[2] == 2.0 + @test v3[3] == 3.0 + + v2 = Vector2D(10, 20) + @test typeof(v2) == SArray{Tuple{2},Float64,1,2} + @test v2[1] == 10.0 + @test v2[2] == 20.0 + + @test Vector3D(1,2,3) == Vector3D(1.0, 2.0, 3.0) + @test Vector2D(10,20) == Vector2D(10.0, 20.0) +end \ No newline at end of file