Skip to content

Commit

Permalink
use measure
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshuaLampert committed Dec 19, 2024
1 parent 0a5d340 commit 28d07dc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
15 changes: 11 additions & 4 deletions src/geometries/polytopes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,17 @@ function (c::Chain)(t)
if t < 0 || t > 1
throw(DomainError(t, "c(t) is not defined for t outside [0, 1]."))
end
n = nvertices(c) - !isclosed(c)
k = min(n - 1, floor(Int, n * t))
s, _ = iterate(segments(c), k)
s(n * t - k)
segs = segments(c)
measures = cumsum(measure.(segs))
measures /= measures[end]
# measures[k] <= t < measures[k + 1]
k = searchsortedfirst(measures, t) - 1
s, _ = iterate(segs, k)
mk = k == 0 ? 0 : measures[k]
mk1 = measures[k + 1]
# Map t to [0, 1] in the segment
t2 = (t - mk) / (mk1 - mk)
s(t2)
end

# implementations of Chain
Expand Down
12 changes: 6 additions & 6 deletions test/polytopes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -267,16 +267,16 @@ end
# parameterization
ri = Ring(latlon(45, 0), latlon(45, 90), latlon(90, 90))
@test ri(T(0)) == latlon(45, 0)
@test ri(T(0.25)) == latlon(45, 67.5)
@test ri(T(0.5)) == latlon(67.5, 90)
@test ri(T(0.75)) == latlon(78.75, 67.5)
@test ri(T(0.25)) latlon(45, 56.25) atol=1e7 * eps(T) * u"m"
@test ri(T(0.5)) latlon(60, 90) atol=1e7 * eps(T) * u"m"
@test ri(T(0.75)) latlon(82.5, 75) atol=1e7 * eps(T) * u"m"
@test ri(T(1)) == latlon(45, 0)

ro = Rope(latlon(45, 0), latlon(45, 90), latlon(90, 90))
@test ro(T(0)) == latlon(45, 0)
@test ro(T(0.25)) == latlon(45, 45)
@test ro(T(0.5)) == latlon(45, 90)
@test ro(T(0.75)) == latlon(67.5, 90)
@test ro(T(0.25)) latlon(45, 39.375) atol=1e7 * eps(T) * u"m"
@test ro(T(0.5)) latlon(45, 78.75) atol=1e7 * eps(T) * u"m"
@test ro(T(0.75)) latlon(63.75, 90) atol=1e7 * eps(T) * u"m"
@test ro(T(1)) == latlon(90, 90)

ri = Ring(cart.([(1, 1), (2, 2), (3, 3)]))
Expand Down

0 comments on commit 28d07dc

Please sign in to comment.