Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 3 additions & 2 deletions src/fixed_arrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -101,14 +101,15 @@ macro fixed_vector(name, parent)
end
end

Base.:(*)(a::$name, b::$name) = a .* b

end)
end

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}
Expand Down
5 changes: 5 additions & 0 deletions src/metadata.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions test/fixed_arrays.jl
Original file line number Diff line number Diff line change
@@ -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
27 changes: 20 additions & 7 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Test, Random, StructArrays, Tables, StaticArrays
using GeometryBasics
using LinearAlgebra
using GeometryBasics: attributes

@testset "GeometryBasics" begin

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)))
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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"