Skip to content

Commit d63e188

Browse files
authored
Merge pull request #47 from JuliaGeometry/sd/improvements
fix meta & broadcast
2 parents f66c5f4 + 09bfd3b commit d63e188

File tree

5 files changed

+43
-12
lines changed

5 files changed

+43
-12
lines changed

.travis.yml

+1-3
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@ language: julia
33
os:
44
- linux
55
julia:
6-
- 1.2
76
- 1
87
if: branch = master OR tag IS present OR type = pull_request
98
notifications:
109
email: false
11-
after_success:
12-
- julia -e 'using Pkg; Pkg.add("Coverage"); using Coverage; Codecov.submit(process_folder())'
10+
codecov: true

src/fixed_arrays.jl

+3-2
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ macro fixed_vector(name, parent)
9090
Base.Tuple(v::$(name)) = v.data
9191
Base.convert(::Type{$(name){S, T}}, x::NTuple{S, T}) where {S, T} = $(name){S, T}(x)
9292
function Base.convert(::Type{$(name){S, T}}, x::Tuple) where {S, T}
93-
$(name){S, T}(convert(NTuple{S, T}, x))
93+
return $(name){S, T}(convert(NTuple{S, T}, x))
9494
end
9595

9696
@generated function StaticArrays.similar_type(::Type{SV}, ::Type{T}, s::Size{S}) where {SV <: $(name), T, S}
@@ -101,14 +101,15 @@ macro fixed_vector(name, parent)
101101
end
102102
end
103103

104+
Base.:(*)(a::$name, b::$name) = a .* b
105+
104106
end)
105107
end
106108

107109
abstract type AbstractPoint{Dim, T} <: StaticVector{Dim, T} end
108110
@fixed_vector Point AbstractPoint
109111
@fixed_vector Vec StaticVector
110112

111-
112113
const Mat = SMatrix
113114
const VecTypes{N, T} = Union{StaticVector{N, T}, NTuple{N, T}}
114115
const Vecf0{N} = Vec{N, Float32}

src/metadata.jl

+5
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,11 @@ macro meta_type(name, mainfield, supertype, params...)
127127
return MT(obj, nt)
128128
end
129129

130+
function (MT::Type{<: $MetaName})(main::$(name); meta...)
131+
nt = values(meta)
132+
return MT(main, nt)
133+
end
134+
130135
function Base.propertynames(::$MetaName{$(params...), Typ, Names, Types}) where {$(params...), Typ, Names, Types}
131136
return ($field, Names...)
132137
end

test/fixed_arrays.jl

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using Test
2+
3+
@testset "conversion" begin
4+
@test convert(Point, (2, 3)) === Point(2, 3)
5+
@test convert(Point, (2.0, 3)) === Point(2.0, 3.0)
6+
end
7+
8+
@testset "broadcast" begin
9+
x = [Point(2, 3), Point(7, 3)]
10+
11+
@test [Point(4, 9), Point(14, 9)] == x .* (Point(2, 3),)
12+
@test [Point(4, 6), Point(9, 6)] == x .+ (Point(2, 3),)
13+
@test [Point(0, 0), Point(5, 0)] == x .- (Point(2, 3),)
14+
end

test/runtests.jl

+20-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Test, Random, StructArrays, Tables, StaticArrays
22
using GeometryBasics
33
using LinearAlgebra
4+
using GeometryBasics: attributes
45

56
@testset "GeometryBasics" begin
67

@@ -79,7 +80,12 @@ using LinearAlgebra
7980
@test GeometryBasics.MetaType(Polygon) == PolygonMeta{Polygon,T,Typ,Names,Types} where Types where Names where Typ<:GeometryBasics.AbstractPolygon{Polygon,T} where T
8081
@test_throws ErrorException GeometryBasics.meta(plain)
8182
@test GeometryBasics.MetaFree(PolygonMeta) == Polygon
82-
83+
84+
meta_p = meta(polys[1], boundingbox=Rect(0, 0, 2, 2))
85+
@test meta_p.boundingbox === Rect(0, 0, 2, 2)
86+
@test metafree(meta_p) === polys[1]
87+
attributes(meta_p) == Dict{Symbol, Any}(:boundingbox => meta_p.boundingbox,
88+
:polygon => polys[1])
8389
end
8490

8591
@testset "point with metadata" begin
@@ -331,9 +337,7 @@ end
331337
@test coordinates(m) === points
332338
end
333339

334-
@testset "Tests from GeometryTypes" begin
335-
include("geometrytypes.jl")
336-
end
340+
337341

338342
@testset "convert mesh + meta" begin
339343
m = uv_normal_mesh(FRect3D(Vec3f0(-1), Vec3f0(1, 2, 3)))
@@ -368,7 +372,7 @@ end
368372
@test_throws ErrorException GeometryBasics.MetaType(Simplex)
369373
@test_throws ErrorException GeometryBasics.MetaFree(Simplex)
370374

371-
375+
372376
@test m.xx === xx
373377
@test m.color === color
374378

@@ -429,6 +433,7 @@ end
429433
@test found && point Point(0.0, 4.0)
430434
@test intersects(a, f) === (false, Point(0.0, 0.0))
431435
end
436+
432437
@testset "Offsetintegers" begin
433438
x = 1
434439
@test GeometryBasics.raw(x) isa Int64
@@ -453,11 +458,19 @@ end
453458
@test -(x, x1) == OffsetInteger{0,Int64}(-1)
454459
#test for /
455460
@test div(x, x1) == OffsetInteger{0,Int64}(0)
456-
@test !==(x, x1)
457-
@test !>=(x, x1)
461+
@test !==(x, x1)
462+
@test !>=(x, x1)
458463
@test <=(x, x1)
459464
@test !>(x, x1)
460465
@test <(x, x1)
461466
end
462467

468+
@testset "Tests from GeometryTypes" begin
469+
include("geometrytypes.jl")
470+
end
471+
472+
@testset "Point & Vec type" begin
473+
include("fixed_arrays.jl")
474+
end
475+
463476
end # testset "GeometryBasics"

0 commit comments

Comments
 (0)