Skip to content

Commit 5c50e4d

Browse files
author
Jerome Plut
committed
fixed a part of incorrect triangulations; Stroke example still todo
1 parent 2b40ece commit 5c50e4d

File tree

4 files changed

+35
-9
lines changed

4 files changed

+35
-9
lines changed

TODO.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
* `path_extrude(surface, profile) => path_extrude(∂surface)`
1010
* `path(element1, element2, ...)`
1111
# Bug fixes
12+
- [ ] in GLMakie, (non-convex) polygons are incorrectly triangulated
1213
- [ ] `path_extrude` of shape with holes: hole extrusions are reversed
1314
- [ ] instead of trying funny stuff with symdiff, we could just concatenate everything and do a self-union to regularize
1415
- [x] `matrix*set_parameters` etc.; `raise(.8)*mat*cone(3)*lozenge`...

docs/src/transformations.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,23 @@ using CairoMakie
1010
png(name, s) = save(name*".png", Makie.plot(s));
1111
```
1212

13-
All single-object transformations accept two possible syntaxes:
13+
All single-object transformations accept three possible syntaxes:
1414
```julia
1515
transform(parameters, solid1, solid2, ...)
1616
transform(parameters) * solid1
17+
solid1 |> transform(parameters)
1718
```
18-
The second, multiplicative form allows easy chaining of transformations:
19+
(The third form is standard Julia syntax for function application).
20+
The second and third forms allow easy chaining of transformations
21+
in either direction:
1922
```julia
2023
transform1(param1) * transform2(param2) * solid
24+
solid |> transform2(param2) |> transform1(param1)
2125
```
26+
(It is obviously not recommended to mix both syntaxes together.
27+
However, note that in this case, multiplication takes syntactic priority
28+
over function application).
29+
2230
This form may also be applied to several solids by either wrapping them in a
2331
`union`, or equivalently, by applying it to a `Vector` of such objects:
2432
```julia

src/LibTriangle.jl

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,35 @@ using Triangulate: Triangulate
44
# constrained_triangulation
55
# basic_triangulation
66
function triangulation(vertices::AbstractVector, names = [],
7-
edges::AbstractVector = [], holes = []; reverse = false)
7+
edges::AbstractVector = [], boundary = [], holes = []; reverse = false)
88
pointlist = Float64[v[i] for i in 1:2, v in vertices]
99
segmentlist = Int32[e[i] for i in 1:2, e in edges]
10+
segmentmarkerlist = isempty(boundary) ? Int32[0 for e in edges] :
11+
Int32.(boundary)
1012
pointmarkerlist = Vector{Int32}(names)
1113
holelist = Float64[v[i] for i in 1:2, v in holes]
1214
graph = Triangulate.TriangulateIO(;
13-
pointlist, segmentlist, pointmarkerlist, holelist)
14-
(tri, vor) = Triangulate.triangulate("-Q", graph)
15+
pointlist, segmentlist, pointmarkerlist, segmentmarkerlist, holelist)
16+
(tri, vor) = Triangulate.triangulate("pQ", graph)
1517
reverse && for t in eachcol(tri.trianglelist)
1618
t[1], t[2] = t[2], t[1]
1719
end
1820
return ((t[1], t[2], t[3]) for t in eachcol(tri.trianglelist))
1921
end
2022
end
2123

22-
using .LibTriangle
23-
t = LibTriangle.triangulation([[0,0],[1,0],[0,1],[2,2]])
24+
# # isdefined(Main,:Triangle) ||
25+
# (include("../tri/src/Triangle.jl"); using .Triangle)
26+
# L = LibTriangle
27+
# T = Triangle
28+
# N=T.Triangulate.NativeInterface
29+
# p=[[10.0, 1.0], [1.0, 1.0], [1.0, 10.0], [0.0, 10.0], [0.0, 0.0], [10.0, 0.0]]
30+
# s=NTuple{2,Int}[(1,2),(2,3),(3,4),(4,5),(5,6),(6,1)]
31+
#
32+
# v=Float64[transpose.(p)...;]
33+
# vm=Int[1,2,3,4,5,6]
34+
# e=Int[1 2; 2 3; 3 4; 4 5; 5 6; 6 1]
35+
# em=Bool[true for _ in 1:6]
36+
#
37+
# t2=T.constrained_triangulation(v, vm, e, em)
38+
# t1=L.triangulation(p,[], s, em).trianglelist

src/Shapes.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,9 @@ function point_in_polygon(poly; orientation=orientation(poly))#««
447447
end#»»
448448
# triangulates a simple loop
449449
function triangulate(v::AbstractVector{<:SVector{2,<:Real}})
450-
triangles = LibTriangle.triangulation(v; reverse = !orientation(v))
450+
triangles = LibTriangle.triangulation(v, [],
451+
[((i,i+1) for i in 1:length(v)-1)...; (length(v), 1)];
452+
reverse = !orientation(v))
451453
# tri = basic_triangulation(
452454
# Matrix{Float64}([transpose.(v)...;]),
453455
# collect(1:length(v)))
@@ -479,7 +481,7 @@ function triangulate(m::PolygonXor)#««
479481
edges[c+n] = (labels[c+n], labels[c+1])
480482
c+= n
481483
end
482-
push!(tri, LibTriangle.triangulation([plist...;], labels, edges, holes)...)
484+
push!(tri, LibTriangle.triangulation([plist...;], labels, edges, [], holes)...)
483485
end
484486
return tri
485487
end#»»

0 commit comments

Comments
 (0)