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

Commit

Permalink
Merge pull request #191 from JuliaGeometry/sd/fix
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonDanisch authored Dec 30, 2019
2 parents 19cb633 + 7d22050 commit a3e3165
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
*.jl.mem
docs/build/
docs/site/
Manifest.toml
4 changes: 2 additions & 2 deletions src/meshes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
11 changes: 5 additions & 6 deletions src/polygons.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -112,7 +112,6 @@ function polygon2faces(
end
count -= 1


#= three consecutive vertices in current polygon, <u,v,w> =#
u = v; (u > nv) && (u = 1) #= previous =#
v = u+1; (v > nv) && (v = 1) #= new v =#
Expand Down
7 changes: 7 additions & 0 deletions test/polygons.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit a3e3165

Please sign in to comment.