Skip to content
This repository was archived by the owner on Nov 22, 2023. It is now read-only.

Commit a844818

Browse files
authored
last fixes for tagging + glvisualize (#100)
* convert HomogenousMesh constructor to an @generated function to work around segfault fixes #92 * fix test * fix bug and correct typo * fix last glvisualize problems * remove debug * add test for creating mesh from sphere * removed unused * don't steal from iterators.jl anymore
1 parent 5485941 commit a844818

File tree

8 files changed

+25
-121
lines changed

8 files changed

+25
-121
lines changed

REQUIRE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ julia 0.6.0-pre
22
StaticArrays
33
ColorTypes
44
FixedPointNumbers 0.3
5+
Iterators

src/GeometryTypes.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ using ColorTypes
77

88
import FixedPointNumbers # U8
99

10+
using Iterators.partition
11+
1012
import Base: ==,
1113
*,
1214
contains,

src/decompose.jl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ primitive.
55
function decompose{SV <: StaticVector, N, T}(::Type{SV},
66
r::AbstractGeometry{N, T}, args...
77
)
8-
vectype = similar_type(SV, eltype_or(SV, T), size_or(SV, Size{(N,)}()))
8+
sz = size_or(SV, (N,))
9+
vectype = similar_type(SV, eltype_or(SV, T), Size{sz}())
910
# since we have not triangular dispatch, we can't define a function with the
1011
# signature for a fully specified Vector type. But we need to check for it
1112
# as it means that decompose is not implemented for that version
@@ -38,8 +39,8 @@ isdecomposable{T<:Face, HR<:SimpleRectangle}(::Type{T}, ::Type{HR}) = true
3839
isdecomposable{T<:TextureCoordinate, HR<:SimpleRectangle}(::Type{T}, ::Type{HR}) = true
3940
isdecomposable{T<:Normal, HR<:SimpleRectangle}(::Type{T}, ::Type{HR}) = true
4041

41-
isdecomposable{T<:Point, HR<:HyperSphere}(::Type{T}, ::Type{HR}) = true
42-
isdecomposable{T<:Face, HR<:HyperSphere}(::Type{T}, ::Type{HR}) = true
42+
isdecomposable{T<:Point, HR <: HyperSphere}(::Type{T}, ::Type{HR}) = true
43+
isdecomposable{T<:Face, HR <: HyperSphere}(::Type{T}, ::Type{HR}) = true
4344

4445
"""
4546
```
@@ -368,7 +369,7 @@ function decompose{N,T}(PT::Type{Point{N,T}}, s::Sphere, facets=12)
368369
end
369370
vertices
370371
end
371-
function decompose{FT<:Face}(::Type{FT}, s::Sphere, facets=12)
372+
function decompose{FT <: Face}(::Type{FT}, s::Sphere, facets=12)
372373
indexes = Vector{FT}(facets*facets*2)
373374
FTE = eltype(FT)
374375
psydo_triangle_i = facets*facets+1

src/lines.jl

Lines changed: 0 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -56,75 +56,6 @@ function simple_concat{P}(vec, range, endpoint::P)
5656
result
5757
end
5858

59-
60-
# Taken from Iterators.jl, since it's not possible to use Iterators.jl on 0.6 with precompilation
61-
62-
struct Partition{I, N}
63-
xs::I
64-
step::Int
65-
end
66-
iteratorsize{T<:Partition}(::Type{T}) = SizeUnknown()
67-
68-
Base.eltype{I, N}(::Type{Partition{I, N}}) = NTuple{N, eltype(I)}
69-
function partition{I}(xs::I, n::Int)
70-
Partition{I, n}(xs, n)
71-
end
72-
73-
function partition{I}(xs::I, n::Int, step::Int)
74-
if step < 1
75-
throw(ArgumentError("Partition step must be at least 1."))
76-
end
77-
78-
Partition{I, n}(xs, step)
79-
end
80-
81-
function Base.start{I, N}(it::Partition{I, N})
82-
p = Vector{eltype(I)}(N)
83-
s = start(it.xs)
84-
for i in 1:(N - 1)
85-
if done(it.xs, s)
86-
break
87-
end
88-
(p[i], s) = next(it.xs, s)
89-
end
90-
(s, p)
91-
end
92-
93-
function Base.next{I, N}(it::Partition{I, N}, state)
94-
(s, p0) = state
95-
(x, s) = next(it.xs, s)
96-
ans = p0; ans[end] = x
97-
98-
p = similar(p0)
99-
overlap = max(0, N - it.step)
100-
for i in 1:overlap
101-
p[i] = ans[it.step + i]
102-
end
103-
104-
# when step > n, skip over some elements
105-
for i in 1:max(0, it.step - N)
106-
if done(it.xs, s)
107-
break
108-
end
109-
(x, s) = next(it.xs, s)
110-
end
111-
112-
for i in (overlap + 1):(N - 1)
113-
if done(it.xs, s)
114-
break
115-
end
116-
117-
(x, s) = next(it.xs, s)
118-
p[i] = x
119-
end
120-
121-
(tuple(ans...), (s, p))
122-
end
123-
124-
Base.done(it::Partition, state) = done(it.xs, state[1])
125-
126-
127-
12859
"""
12960
Finds all self intersections of polygon `points`
13061
"""

src/meshes.jl

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -52,29 +52,6 @@ convert{M <: AbstractMesh}(::Type{M}, mesh::Union{AbstractGeometry, AbstractMesh
5252
convert(::Type{T}, mesh::T) where T <: AbstractMesh = mesh
5353
# (::Type{HM1}){HM1 <: AbstractMesh}(mesh::HM1) = mesh
5454

55-
"""
56-
Uses decompose to get all the converted attributes from the meshtype and
57-
creates a new mesh with the desired attributes from the converted attributs
58-
Getindex can be defined for any arbitrary geometric type or exotic mesh type.
59-
This way, we can make sure, that you can convert most of the meshes from one type to the other
60-
with minimal code.
61-
"""
62-
function (::Type{HM1}){HM1 <: AbstractMesh}(primitive::GeometryPrimitive)
63-
result = Dict{Symbol, Any}()
64-
for (field, target_type) in zip(fieldnames(HM1), HM1.parameters)
65-
if target_type != Void
66-
if field == :attribute_id
67-
if !isa(primitive, HomogenousMesh)
68-
error("Primitive $primitive doesn't hold attribute indexes")
69-
end
70-
result[field] = primitive.attribute_id
71-
else
72-
result[field] = decompose(target_type, primitive)
73-
end
74-
end
75-
end
76-
HM1(result)
77-
end
7855

7956
isvoid{T}(::Type{T}) = false
8057
isvoid(::Type{Void}) = true

src/primitives.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
function (meshtype::Type{T}){T <: AbstractMesh}(c::Pyramid)
3-
T(decompose(vertextype(T), c), decompose(facetype(T), c))
3+
T(vertices = decompose(vertextype(T), c), faces = decompose(facetype(T), c))
44
end
55

66

@@ -18,7 +18,7 @@ function (meshtype::Type{T}){T <: AbstractMesh}(c::GeometryPrimitive, args...)
1818
newattribs[fieldname] = decompose(eltype(typ), c, args...)
1919
end
2020
end
21-
T(homogenousmesh(newattribs))
21+
T(newattribs)
2222
end
2323

2424

src/simplices.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ end
3939
# function StaticArrays.similar_type{SV <: Simplex}(::Union{SV, Type{SV}}, s::Tuple{Int})
4040
# Simplex{s[1], eltype(SV)}
4141
# end
42-
function StaticArrays.similar_type{T}(::Union{Simplex, Type{Simplex}}, ::Type{T}, s::Tuple{Int})
43-
Simplex{s[1], T}
42+
function StaticArrays.similar_type{T, S}(::Union{Simplex, Type{Simplex}}, ::Type{T}, s::Size{S})
43+
Simplex{S[1], T}
4444
end
4545

4646
# (::Type{S}){S <: Simplex}(fs::FlexibleSimplex) = convert(S, fs)

test/meshes.jl

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ end
5252
end
5353

5454
@testset "Primitives" begin
55-
# issue #16
56-
#m = HomogenousMesh{Point{3,Float64},Face{3, Int}}(Sphere(Point(0,0,0), 1))
57-
#@fact length(vertices(m)) --> 145
58-
#@fact length(faces(m)) --> 288
55+
m = GLNormalMesh(Sphere(Point3f0(0), 1f0))
56+
@test length(vertices(m)) == 145
57+
@test length(faces(m)) == 288
58+
5959
end
6060

6161

@@ -173,23 +173,15 @@ end
173173
mesh = PlainMesh{eltype(VT), FT}(vertices=vs, faces=fs)
174174
@test convert(GLNormalMesh, mesh) == GLNormalMesh(vs, fs)
175175
end
176+
@testset "construction" begin
177+
VT = vertextype(GLNormalMesh)
178+
FT = facetype(GLNormalMesh)
179+
vs = [VT(0., 0, 0), VT(1., 0, 0), VT(0., 1, 0)]
180+
fs = [FT(1, 2, 3)]
176181

182+
# test for https://github.com/JuliaGeometry/GeometryTypes.jl/issues/92
183+
m = HomogenousMesh(vs, fs)
184+
@test HomogenousMesh(m) == m
177185
end
178186

179-
180-
using GeometryTypes
181-
attributes = Dict{Symbol, Any}()
182-
attributes[:faces] = GLTriangle[(1,2,3), (3, 2, 1)]
183-
attributes[:vertices] = rand(Point3f0, 3)
184-
attributes[:normals] = rand(Normal{3, Float32}, 3)
185-
@which HomogenousMesh(attributes)
186-
# M = HomogenousMesh
187-
# attribs = attributes
188-
# newfields = map(fieldnames(HomogenousMesh)) do field
189-
# target_type = fieldtype(M, field)
190-
# default = fieldtype(HomogenousMesh, field) <: Vector ? Void[] : nothing
191-
# get(attribs, field, default)
192-
# end
193-
194-
x = GeometryTypes.homogenousmesh(attributes)
195-
GLNormalMesh(x)
187+
end

0 commit comments

Comments
 (0)