Skip to content

Commit

Permalink
fixed a part of incorrect triangulations; Stroke example still todo
Browse files Browse the repository at this point in the history
  • Loading branch information
Jerome Plut committed Aug 19, 2022
1 parent 2b40ece commit 5c50e4d
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 9 deletions.
1 change: 1 addition & 0 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* `path_extrude(surface, profile) => path_extrude(∂surface)`
* `path(element1, element2, ...)`
# Bug fixes
- [ ] in GLMakie, (non-convex) polygons are incorrectly triangulated
- [ ] `path_extrude` of shape with holes: hole extrusions are reversed
- [ ] instead of trying funny stuff with symdiff, we could just concatenate everything and do a self-union to regularize
- [x] `matrix*set_parameters` etc.; `raise(.8)*mat*cone(3)*lozenge`...
Expand Down
12 changes: 10 additions & 2 deletions docs/src/transformations.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,23 @@ using CairoMakie
png(name, s) = save(name*".png", Makie.plot(s));
```

All single-object transformations accept two possible syntaxes:
All single-object transformations accept three possible syntaxes:
```julia
transform(parameters, solid1, solid2, ...)
transform(parameters) * solid1
solid1 |> transform(parameters)
```
The second, multiplicative form allows easy chaining of transformations:
(The third form is standard Julia syntax for function application).
The second and third forms allow easy chaining of transformations
in either direction:
```julia
transform1(param1) * transform2(param2) * solid
solid |> transform2(param2) |> transform1(param1)
```
(It is obviously not recommended to mix both syntaxes together.
However, note that in this case, multiplication takes syntactic priority
over function application).

This form may also be applied to several solids by either wrapping them in a
`union`, or equivalently, by applying it to a `Vector` of such objects:
```julia
Expand Down
25 changes: 20 additions & 5 deletions src/LibTriangle.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,35 @@ using Triangulate: Triangulate
# constrained_triangulation
# basic_triangulation
function triangulation(vertices::AbstractVector, names = [],
edges::AbstractVector = [], holes = []; reverse = false)
edges::AbstractVector = [], boundary = [], holes = []; reverse = false)
pointlist = Float64[v[i] for i in 1:2, v in vertices]
segmentlist = Int32[e[i] for i in 1:2, e in edges]
segmentmarkerlist = isempty(boundary) ? Int32[0 for e in edges] :
Int32.(boundary)
pointmarkerlist = Vector{Int32}(names)
holelist = Float64[v[i] for i in 1:2, v in holes]
graph = Triangulate.TriangulateIO(;
pointlist, segmentlist, pointmarkerlist, holelist)
(tri, vor) = Triangulate.triangulate("-Q", graph)
pointlist, segmentlist, pointmarkerlist, segmentmarkerlist, holelist)
(tri, vor) = Triangulate.triangulate("pQ", graph)
reverse && for t in eachcol(tri.trianglelist)
t[1], t[2] = t[2], t[1]
end
return ((t[1], t[2], t[3]) for t in eachcol(tri.trianglelist))
end
end

using .LibTriangle
t = LibTriangle.triangulation([[0,0],[1,0],[0,1],[2,2]])
# # isdefined(Main,:Triangle) ||
# (include("../tri/src/Triangle.jl"); using .Triangle)
# L = LibTriangle
# T = Triangle
# N=T.Triangulate.NativeInterface
# 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]]
# s=NTuple{2,Int}[(1,2),(2,3),(3,4),(4,5),(5,6),(6,1)]
#
# v=Float64[transpose.(p)...;]
# vm=Int[1,2,3,4,5,6]
# e=Int[1 2; 2 3; 3 4; 4 5; 5 6; 6 1]
# em=Bool[true for _ in 1:6]
#
# t2=T.constrained_triangulation(v, vm, e, em)
# t1=L.triangulation(p,[], s, em).trianglelist
6 changes: 4 additions & 2 deletions src/Shapes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,9 @@ function point_in_polygon(poly; orientation=orientation(poly))#««
end#»»
# triangulates a simple loop
function triangulate(v::AbstractVector{<:SVector{2,<:Real}})
triangles = LibTriangle.triangulation(v; reverse = !orientation(v))
triangles = LibTriangle.triangulation(v, [],
[((i,i+1) for i in 1:length(v)-1)...; (length(v), 1)];
reverse = !orientation(v))
# tri = basic_triangulation(
# Matrix{Float64}([transpose.(v)...;]),
# collect(1:length(v)))
Expand Down Expand Up @@ -479,7 +481,7 @@ function triangulate(m::PolygonXor)#««
edges[c+n] = (labels[c+n], labels[c+1])
c+= n
end
push!(tri, LibTriangle.triangulation([plist...;], labels, edges, holes)...)
push!(tri, LibTriangle.triangulation([plist...;], labels, edges, [], holes)...)
end
return tri
end#»»
Expand Down

0 comments on commit 5c50e4d

Please sign in to comment.