diff --git a/.gitignore b/.gitignore index d0bbf43..747f15f 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ *.jl.mem docs/build/ docs/site/ +Manifest.toml diff --git a/src/meshes.jl b/src/meshes.jl index e0b3b52..f2769b6 100644 --- a/src/meshes.jl +++ b/src/meshes.jl @@ -167,7 +167,7 @@ function merge(m1::M, meshes::M...) where M <: AbstractMesh f = copy(m1.faces) attribs = deepcopy(attributes_noVF(m1)) for mesh in meshes - append!(f, mesh.faces .+ length(v)) + append!(f, map(f-> f .+ length(v), mesh.faces)) append!(v, mesh.vertices) for (v1, v2) in zip(values(attribs), values(attributes_noVF(mesh))) append!(v1, v2) @@ -193,7 +193,7 @@ function merge( color_attrib = RGBA{U8}[RGBA{U8}(m1.color)] index = Float32[length(color_attrib)-1 for i=1:length(m1.vertices)] for mesh in meshes - append!(faces, mesh.faces .+ length(vertices)) + append!(faces, map(f-> f .+ length(vertices), mesh.faces)) append!(vertices, mesh.vertices) attribsb = attributes_noVF(mesh) for (k,v) in attribsb diff --git a/src/polygons.jl b/src/polygons.jl index 510035e..42e5e67 100644 --- a/src/polygons.jl +++ b/src/polygons.jl @@ -72,21 +72,21 @@ function snip( return true; end - - """ Triangulates a Polygon given as a `contour`::AbstractArray{Point} without holes. It will return a Vector{`facetype`}, defining indexes into `contour` """ function polygon2faces( - contour::AbstractArray{P}, facetype = GLTriangle + _contour::AbstractArray{P}, facetype = GLTriangle ) where P<:Point #= allocate and initialize list of Vertices in polygon =# result = facetype[] # the algorithm doesn't like closed contours - if isapprox(last(contour), first(contour)) - pop!(contour) + contour = if isapprox(last(_contour), first(_contour)) + @view _contour[1:end-1] + else + @view _contour[1:end] end n = length(contour) @@ -112,7 +112,6 @@ function polygon2faces( end count -= 1 - #= three consecutive vertices in current polygon, =# u = v; (u > nv) && (u = 1) #= previous =# v = u+1; (v > nv) && (v = 1) #= new v =# diff --git a/test/polygons.jl b/test/polygons.jl index 630d49c..965e0a7 100644 --- a/test/polygons.jl +++ b/test/polygons.jl @@ -73,4 +73,11 @@ end @test area(reverse(points)) ≈ 0.5f0 end +@testset "points touching" begin + points = decompose(Point2f0, Circle(Point2f0(0), 1f0)) + triangles = polygon2faces(points) + @test !isempty(triangles) + @test points[1] ≈ points[end] +end + end