From ebccf88f7948fc80244fc678144820f09e4da5c3 Mon Sep 17 00:00:00 2001 From: SimonDanisch Date: Fri, 22 May 2020 12:40:53 +0200 Subject: [PATCH 1/2] fix meta & broadcast --- src/fixed_arrays.jl | 5 +++-- src/metadata.jl | 5 +++++ test/fixed_arrays.jl | 14 ++++++++++++++ test/runtests.jl | 27 ++++++++++++++++++++------- 4 files changed, 42 insertions(+), 9 deletions(-) create mode 100644 test/fixed_arrays.jl diff --git a/src/fixed_arrays.jl b/src/fixed_arrays.jl index 6607c440..6f25ebd5 100644 --- a/src/fixed_arrays.jl +++ b/src/fixed_arrays.jl @@ -90,7 +90,7 @@ macro fixed_vector(name, parent) Base.Tuple(v::$(name)) = v.data Base.convert(::Type{$(name){S, T}}, x::NTuple{S, T}) where {S, T} = $(name){S, T}(x) function Base.convert(::Type{$(name){S, T}}, x::Tuple) where {S, T} - $(name){S, T}(convert(NTuple{S, T}, x)) + return $(name){S, T}(convert(NTuple{S, T}, x)) end @generated function StaticArrays.similar_type(::Type{SV}, ::Type{T}, s::Size{S}) where {SV <: $(name), T, S} @@ -101,6 +101,8 @@ macro fixed_vector(name, parent) end end + Base.:(*)(a::$name, b::$name) = a .* b + end) end @@ -108,7 +110,6 @@ abstract type AbstractPoint{Dim, T} <: StaticVector{Dim, T} end @fixed_vector Point AbstractPoint @fixed_vector Vec StaticVector - const Mat = SMatrix const VecTypes{N, T} = Union{StaticVector{N, T}, NTuple{N, T}} const Vecf0{N} = Vec{N, Float32} diff --git a/src/metadata.jl b/src/metadata.jl index 26697ccf..cf261c24 100644 --- a/src/metadata.jl +++ b/src/metadata.jl @@ -127,6 +127,11 @@ macro meta_type(name, mainfield, supertype, params...) return MT(obj, nt) end + function (MT::Type{<: $MetaName})(main::$(name); meta...) + nt = values(meta) + return MT(main, nt) + end + function Base.propertynames(::$MetaName{$(params...), Typ, Names, Types}) where {$(params...), Typ, Names, Types} return ($field, Names...) end diff --git a/test/fixed_arrays.jl b/test/fixed_arrays.jl new file mode 100644 index 00000000..299f5a86 --- /dev/null +++ b/test/fixed_arrays.jl @@ -0,0 +1,14 @@ +using Test + +@testset "conversion" begin + @test convert(Point, (2, 3)) === Point(2, 3) + @test convert(Point, (2.0, 3)) === Point(2.0, 3.0) +end + +@testset "broadcast" begin + x = [Point(2, 3), Point(7, 3)] + + @test [Point(4, 9), Point(14, 9)] == x .* (Point(2, 3),) + @test [Point(4, 6), Point(9, 6)] == x .+ (Point(2, 3),) + @test [Point(0, 0), Point(5, 0)] == x .- (Point(2, 3),) +end diff --git a/test/runtests.jl b/test/runtests.jl index 8747c8fa..09735802 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,6 +1,7 @@ using Test, Random, StructArrays, Tables, StaticArrays using GeometryBasics using LinearAlgebra +using GeometryBasics: attributes @testset "GeometryBasics" begin @@ -79,7 +80,12 @@ using LinearAlgebra @test GeometryBasics.MetaType(Polygon) == PolygonMeta{Polygon,T,Typ,Names,Types} where Types where Names where Typ<:GeometryBasics.AbstractPolygon{Polygon,T} where T @test_throws ErrorException GeometryBasics.meta(plain) @test GeometryBasics.MetaFree(PolygonMeta) == Polygon - + + meta_p = meta(polys[1], boundingbox=Rect(0, 0, 2, 2)) + @test meta_p.boundingbox === Rect(0, 0, 2, 2) + @test metafree(meta_p) === polys[1] + attributes(meta_p) == Dict{Symbol, Any}(:boundingbox => meta_p.boundingbox, + :polygon => polys[1]) end @testset "point with metadata" begin @@ -331,9 +337,7 @@ end @test coordinates(m) === points end -@testset "Tests from GeometryTypes" begin - include("geometrytypes.jl") -end + @testset "convert mesh + meta" begin m = uv_normal_mesh(FRect3D(Vec3f0(-1), Vec3f0(1, 2, 3))) @@ -368,7 +372,7 @@ end @test_throws ErrorException GeometryBasics.MetaType(Simplex) @test_throws ErrorException GeometryBasics.MetaFree(Simplex) - + @test m.xx === xx @test m.color === color @@ -429,6 +433,7 @@ end @test found && point ≈ Point(0.0, 4.0) @test intersects(a, f) === (false, Point(0.0, 0.0)) end + @testset "Offsetintegers" begin x = 1 @test GeometryBasics.raw(x) isa Int64 @@ -453,11 +458,19 @@ end @test -(x, x1) == OffsetInteger{0,Int64}(-1) #test for / @test div(x, x1) == OffsetInteger{0,Int64}(0) - @test !==(x, x1) - @test !>=(x, x1) + @test !==(x, x1) + @test !>=(x, x1) @test <=(x, x1) @test !>(x, x1) @test <(x, x1) end +@testset "Tests from GeometryTypes" begin + include("geometrytypes.jl") +end + +@testset "Point & Vec type" begin + include("fixed_arrays.jl") +end + end # testset "GeometryBasics" From 09bfd3bc245cfc1551188ef817994736beb07368 Mon Sep 17 00:00:00 2001 From: SimonDanisch Date: Fri, 22 May 2020 13:13:22 +0200 Subject: [PATCH 2/2] update travis --- .travis.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6aa12654..a9892539 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,10 +3,8 @@ language: julia os: - linux julia: - - 1.2 - 1 if: branch = master OR tag IS present OR type = pull_request notifications: email: false -after_success: - - julia -e 'using Pkg; Pkg.add("Coverage"); using Coverage; Codecov.submit(process_folder())' +codecov: true