Skip to content

Commit e12e85b

Browse files
committed
revert triangulation changes of Circle
1 parent 81d5bfe commit e12e85b

File tree

4 files changed

+14
-13
lines changed

4 files changed

+14
-13
lines changed

src/meshes.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,15 @@ function mesh(primitive::AbstractGeometry; pointtype=Point, facetype=GLTriangleF
2020
_fs = positions.faces
2121
isnothing(faces(primitive)) || @error("A primitive should not define `faces` and use a FaceView for `coordinates()`. Using faces from FaceView.")
2222
else
23-
_fs = faces(primitive)
23+
# This tries `faces(prim)` first, then triangulation with the natural
24+
# position type of the primitive.
25+
_fs = decompose(facetype, primitive)
2426
end
2527

2628
# If faces returns nothing for primitive, we try to triangulate!
2729
if isnothing(_fs)
2830
if eltype(positions) <: Point2
29-
# triangulation.jl
31+
# try triangulation with the converted positions as a last attempt
3032
fs = decompose(facetype, positions)
3133
else
3234
error("No triangulation for $(typeof(primitive))")

src/primitives/spheres.jl

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,20 @@ end
4343

4444
function coordinates(s::Circle, nvertices=64)
4545
r = radius(s); o = origin(s)
46-
ps = [r * Point(cos(phi), sin(phi)) + o for phi in LinRange(0, 2pi, nvertices+1)]
47-
ps[end] = o
46+
ps = [r * Point(cos(phi), sin(phi)) + o for phi in LinRange(0, 2pi, nvertices)]
47+
# ps[end] = o
4848
return ps
4949
end
5050

5151
function texturecoordinates(::Circle, nvertices=64)
5252
return coordinates(Circle(Point2f(0.5), 0.5f0), nvertices)
5353
end
5454

55-
function faces(::Circle, nvertices=64)
56-
return [GLTriangleFace(nvertices+1, i, mod1(i+1, nvertices)) for i in 1:nvertices]
57-
end
55+
# TODO: Consider generating meshes for circles with a point in the center so
56+
# that the triangles are more regular
57+
# function faces(::Circle, nvertices=64)
58+
# return [GLTriangleFace(nvertices+1, i, mod1(i+1, nvertices)) for i in 1:nvertices]
59+
# end
5860

5961

6062
function coordinates(s::Sphere, nvertices=24)

test/geometrytypes.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ end
183183
@test f == face_target
184184
circle = Circle(Point2f(0), 1.0f0)
185185
points = decompose(Point2f, Tesselation(circle, 20))
186-
@test length(points) == 21
186+
@test length(points) == 20
187187
tess_circle = Tesselation(circle, 32)
188188
mesh = triangle_mesh(tess_circle)
189189
@test decompose(Point2f, mesh) decompose(Point2f, tess_circle)

test/polygons.jl

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,11 @@
1313
@test poly1.exterior == decompose(Point2f, rect)
1414
@test poly1.interiors == [decompose(Point2f, hole)]
1515

16-
fs = GLTriangleFace[
17-
(1, 9, 8), (5, 13, 12), (10, 9, 1), (4, 1, 8), (11, 10, 1), (3, 4, 8),
18-
(12, 11, 1), (3, 8, 7), (12, 1, 2), (3, 7, 6), (5, 12, 2), (2, 3, 6), (6, 5, 2)]
19-
@test fs == faces(poly1)
16+
# triangulation is inconsistent...
17+
@test length(faces(poly1)) == 11
2018
ps = vcat(decompose(Point2f, rect), decompose(Point2f, hole))
2119
@test coordinates(poly1) == ps
2220

23-
2421
fs = GeometryBasics.earcut_triangulate([poly1.exterior[[1, 2, 3, 4, 1]]])
2522
@test fs == GLTriangleFace[(4,1,2), (2,3,4)]
2623

0 commit comments

Comments
 (0)