Skip to content

Commit

Permalink
bug fix: #329 section on trail producing incorr...
Browse files Browse the repository at this point in the history
section on trail producing incorrect result when upper param is
>= 1 (domainUpper) #329

The first parameter was not being rescaled properly in the case that
the second parameter was >= 1. The old code tried to rescale as though
an extra segment was added, while what the code actually does is replace
the last segment with a longer one. This leads two two cases, either the
first param is on a previous segment and doesn't need to change or it's
on the last segment and has to be rescaled to the new length.
  • Loading branch information
Mike Zuser committed Mar 12, 2019
1 parent b6e4837 commit 542a758
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/Diagrams/Trail.hs
Original file line number Diff line number Diff line change
Expand Up @@ -238,11 +238,14 @@ splitAtParam' tree@(SegTree t) p
case FT.viewr t of
EmptyR -> emptySplit
t' FT.:> seg ->
case seg `splitAtParam` (1 - (1 - p)*tSegs) of
(seg1, seg2) ->
( (SegTree $ t' |> seg1, \u -> u * tSegs / (tSegs + 1))
, (SegTree $ FT.singleton seg2, \u -> (u - p) / (1 - p))
)
let f u | n < (tSegs - 1) = u
| otherwise = (n + u' / (1 + (p - 1)*tSegs)) / tSegs
where (n, u') = propFrac $ u * tSegs
in case seg `splitAtParam` (1 + (p - 1)*tSegs) of
(seg1, seg2) ->
( (SegTree $ t' |> seg1 , f)
, (SegTree $ FT.singleton seg2, \u -> (u - p) / (1 - p))
)
| otherwise =
case FT.viewl after of
EmptyL -> emptySplit
Expand Down

0 comments on commit 542a758

Please sign in to comment.