Skip to content

Commit c3044c0

Browse files
authored
Merge pull request #13 from s-ccs/newdocs
new tutorial, renaming of some functions, docstring
2 parents 1b8a858 + f548e9d commit c3044c0

File tree

7 files changed

+117
-18
lines changed

7 files changed

+117
-18
lines changed

.github/workflows/Docs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ jobs:
4040
julia --project=docs -e '
4141
using Pkg
4242
Pkg.develop(PackageSpec(path=pwd()))
43+
Pkg.develop("PDFIO")
4344
Pkg.instantiate()'
4445
- name: Run doctest
4546
run: |

Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "ThesisArt"
22
uuid = "6184abd9-1539-47ca-b742-6ec6f8d46641"
33
authors = ["Benedikt V. Ehinger"]
4-
version = "0.2.0"
4+
version = "0.3.0"
55

66
[deps]
77
BSplineKit = "093aae92-e908-43d7-9660-e50ee39d5a0a"
@@ -14,7 +14,7 @@ RollingFunctions = "b0e4dd01-7b14-53d8-9b45-175a3e362653"
1414
Makie = "0.21"
1515
MakieCore = "0.8"
1616
BSplineKit = "0.17"
17-
PDFIO = "0.1"
17+
PDFIO = "0.1.14"
1818
RollingFunctions = "0.8"
1919
julia = "1"
2020

docs/Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"
33
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
44
HTTP = "cd3eb016-35fb-5094-929b-558a96fad6f3"
55
LiveServer = "16fef848-5104-11e9-1b77-fb7a48bbb589"
6+
PDFIO = "4d0d745f-9d9a-592e-8d18-1ad8a0f42b92"
67
ThesisArt = "6184abd9-1539-47ca-b742-6ec6f8d46641"
78

89
[compat]

docs/src/02-textonpath.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# [TextOnPath](@id init_example)
1+
# [TextOnPath](@id textonpath)
22

33
## TextOnPath
44

docs/src/03-interpolation.md

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# [Interpolation](@id interpolate)
2+
3+
## Interpolation
4+
5+
```@example main
6+
using ThesisArt
7+
using CairoMakie
8+
using Random
9+
nothing #hide
10+
```
11+
12+
Let's define a (random) shape first
13+
14+
```@example main
15+
my_points = 400 .* (rand(MersenneTwister(1),Point2f,20).-Point2f(0.5,0.5))
16+
nothing #hide
17+
```
18+
19+
```@example main
20+
scatterlines(my_points)
21+
```
22+
23+
The lines are not that nice. Let's interpolate them
24+
25+
## order setting
26+
27+
```@example ax_main
28+
my_xy_interpolated_2 =ThesisArt.rolling_interpolation(my_points;order=2)
29+
my_xy_interpolated_4 =ThesisArt.rolling_interpolation(my_points;order=4) # default
30+
```
31+
32+
```@example main
33+
f = Figure()
34+
scatterlines(f[1,1],my_xy_interpolated_2,axis=(;title="Order 2"))
35+
scatter!(my_points,color=:red)
36+
scatterlines(f[1,2],my_xy_interpolated_4,axis=(;title="Order 4"))
37+
scatter!(my_points,color=:red)
38+
f
39+
```
40+
41+
We see left linear interpolation, right cubic interpolation.
42+
43+
## subsample
44+
45+
```@example main
46+
my_xy_interpolated_20 =ThesisArt.rolling_interpolation(my_points;subsample=20)
47+
my_xy_interpolated_5 =ThesisArt.rolling_interpolation(my_points;subsample=5) #
48+
```
49+
50+
```@example main
51+
f = Figure()
52+
scatterlines(f[1,1],my_xy_interpolated_5,axis=(;title="subsample 5"))
53+
scatter!(my_points,color=:red)
54+
scatterlines(f[1,2],my_xy_interpolated_20,axis=(;title="subsample 20"))
55+
scatter!(my_points,color=:red)
56+
f
57+
```
58+
59+
## Equalize distance
60+
61+
```@example main
62+
my_xy_interpolated_100 =ThesisArt.rolling_interpolation(my_points;subsample=100)
63+
64+
my_xy_equ_10 = equalize_distance(my_xy_interpolated_100,min_dist=10)
65+
my_xy_equ_50 = equalize_distance(my_xy_interpolated_100,min_dist=50)
66+
```
67+
68+
```@example main
69+
f = Figure()
70+
scatterlines(f[1,1],my_xy_equ_10,axis=(;title="mindist 10"))
71+
scatter!(my_points,color=:red)
72+
scatterlines(f[1,2],my_xy_equ_50,axis=(;title="mindist 50"))
73+
scatter!(my_points,color=:red)
74+
f
75+
```

src/ThesisArt.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ include("fontOnCurve.jl")
1313

1414
export import_pdf
1515
export get_rotation
16-
export rolling_inter2d
16+
export rolling_interpolation, equalize_distance
1717
export add_spacer!, add_title!, newfigure
1818
export TextOnPath
1919
end

src/interpolateCurve.jl

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,36 @@
22

33
# returns interpolator
44

5-
function interp_spline(z; order = 2)
5+
function interpolate_spline(z; order = 4)
66
t = range(0, 1, length = length(z))
77
return interpolate(t, z, BSplineOrder(order), Natural())
88
end
99
# returns k x more points, interpolated x/y
10-
function interp_curve(k, x; kwargs...)
11-
it = interp_spline(collect(x); kwargs...)
10+
function interpolate_curve(k, x; kwargs...)
11+
it = interpolate_spline(collect(x); kwargs...)
1212
r = range(0, 1, length = k * length(x))
1313

1414
r = range(0.5 - 1 / (length(x) * 2 - 2), 0.5 + 1 / (length(x) * 2 - 2), length = k)
1515
return it.(r)
1616

1717
end
18-
function rolling_interp(x; times = 5, winsize = 4, kwargs...)
18+
19+
"""
20+
21+
Interpolates in 1D or 2D using BSplineOrder(order=4) the x/y path.
22+
23+
# arguments
24+
x: Vector of Numeric, or vector of Point2f
25+
[y: if x/y pairs are provided, will call the function on both axes individually]
26+
27+
# keyword
28+
`winsize=4`: Over how many samples the interpolation function should run. For order =4, needs to be at least 4. For higher orders you need to increase this - you might get better interpolation by raising this, but i'm not sure.
29+
`subsample=5`: How many points to evaluate the spline on, effectively how many intermediate points to return.
30+
`order=4` the order of the BSPline. 4 is default, 2 is linear.
31+
"""
32+
function rolling_interpolation(x; subsample = 5, winsize = 4, kwargs...)
1933
if length(x) == 2
20-
return range(x[1], x[2], length = times)
34+
return range(x[1], x[2], length = subsample)
2135
end
2236
#if length(x)==3
2337
#winsize =3
@@ -26,23 +40,31 @@ function rolling_interp(x; times = 5, winsize = 4, kwargs...)
2640

2741

2842

29-
return vcat(rolling(x -> interp_curve(times, x; kwargs...), x, winsize)..., x[end])
43+
return vcat(
44+
rolling(x -> interpolate_curve(subsample, x; kwargs...), x, winsize)...,
45+
x[end],
46+
)
3047

3148
end
32-
function rolling_inter2d(x, y; minDist = 1, kwargs...)
33-
x = rolling_interp(x; kwargs...)
34-
y = rolling_interp(y; kwargs...)
49+
rolling_interpolation(x::Vector{Point2f}; kwargs...) =
50+
Point2f.(rolling_interpolation(first.(x), last.(x); kwargs...)...)
51+
52+
function rolling_interpolation(x, y; kwargs...)
53+
x = rolling_interpolation(x; kwargs...)
54+
y = rolling_interpolation(y; kwargs...)
55+
3556

3657

37-
#ix = 1:length(x)
38-
return equalize_distance(x, y; minDist = minDist)
58+
return x, y
3959
end
4060

41-
function equalize_distance(x, y; minDist = 1)
61+
equalize_distance(p::Vector{Point2f}; kwargs...) =
62+
Point2f.(equalize_distance(first.(p), last.(p); kwargs...)...)
63+
function equalize_distance(x, y; min_dist = 1)
4264
dist = rolling(dist2, x, y, 2)
4365
sumdist = cumsum(dist)
44-
ix = vcat(0, findall(diff(floor.(sumdist ./ minDist)) .> 0), length(x) - 1) .+ 1
45-
return (; :x => x[ix], :y => y[ix])
66+
ix = vcat(0, findall(diff(floor.(sumdist ./ min_dist)) .> 0), length(x) - 1) .+ 1
67+
return x[ix], y[ix]
4668
end
4769
function dist2(x, y)
4870
return sqrt((x[1] - x[2])^2 + (y[1] - y[2])^2)

0 commit comments

Comments
 (0)