Skip to content

Commit 6ba05e4

Browse files
authored
Merge pull request #64 from JuliaGeometry/sd/uv_fix
fix texturecoordinates fallback
2 parents 348fcd6 + 3457762 commit 6ba05e4

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

src/interfaces.jl

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ function faces(primitive, nvertices=nothing)
3333
return nothing
3434
end
3535

36+
texturecoordinates(primitive, nvertices=nothing) = nothing
37+
3638
"""
3739
Tesselation(primitive, nvertices)
3840
For abstract geometries, when we generate
@@ -123,16 +125,25 @@ function decompose(NT::Normal{T}, primitive) where T
123125
end
124126

125127
function decompose(UVT::Union{UV{T}, UVW{T}}, primitive) where T
128+
# This is the fallback for texture coordinates if a primitive doesn't overload them
129+
# We just take the positions and normalize them
126130
uv = texturecoordinates(primitive)
127131
if uv === nothing
128-
return decompose(UVT, texturecoordinates(coordinates(primitive)))
132+
# If the primitive doesn't even have coordinates, we're out of options and return
133+
# nothing, indicating that texturecoordinates aren't implemented
134+
positions = decompose(Point, primitive)
135+
positions === nothing && return nothing
136+
# Let this overlord do the work
137+
return decompose(UVT, positions)
129138
end
130139
return collect_with_eltype(T, uv)
131140
end
132141

133-
function texturecoordinates(positions::AbstractVector{<:VecTypes})
134-
bb = Rect(positions)
135-
return map(positions) do p
142+
function decompose(UVT::Union{UV{T}, UVW{T}}, positions::AbstractVector{<:VecTypes}) where T
143+
N = length(T)
144+
positions_nd = decompose(Point{N, eltype(T)}, positions)
145+
bb = Rect(positions_nd) # Make sure we get this as points
146+
return map(positions_nd) do p
136147
return (p .- minimum(bb)) ./ widths(bb)
137148
end
138149
end

test/geometrytypes.jl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ end
102102
@test GeometryBasics.coordinates(m) positions
103103
m = normal_mesh(s)# just test that it works without explicit resolution parameter
104104
@test m isa GLNormalMesh
105+
106+
muv = uv_mesh(s)
107+
@test Rect(Point.(texturecoordinates(muv))) == FRect2D(Vec2f0(0), Vec2f0(1.0))
105108
end
106109
end
107110

@@ -240,7 +243,7 @@ end
240243
@test !in(rect1, split1)
241244

242245
prim = Rect(0.0, 0.0, 1.0, 1.0)
243-
@test length(prim) == 2
246+
@test length(prim) == 2
244247

245248
@test width(prim) == 1.0
246249
@test height(prim) == 1.0
@@ -267,7 +270,7 @@ end
267270
@test update(b, v) isa GeometryBasics.HyperRectangle{2,Float64}
268271
v = Vec(1.0, 2.0)
269272
@test update(b, v) isa GeometryBasics.HyperRectangle{2,Float64}
270-
273+
271274
p = Vec(5.0, 4.0)
272275
rect = Rect(0.0, 0.0, 1.0, 1.0)
273276
@test min_dist_dim(rect, p, 1) == 4.0

0 commit comments

Comments
 (0)