Skip to content

Commit 889fe65

Browse files
Make continFnPlot less pendantic against NaN-yielding functions.
1 parent 26a0886 commit 889fe65

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

  • Graphics/Dynamic/Plot

Graphics/Dynamic/Plot/R2.hs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,16 +1050,18 @@ continFnPlot f = def{
10501050
, isTintableMonochromic = True
10511051
, axesNecessity = 1
10521052
, dynamicPlot = plot }
1053-
where yRangef = onInterval $ \(l, r) -> ((!10) &&& (!70)) . sort . pruneOutlyers
1053+
where yRangef = onInterval $ \(l, r) -> ((!%0.1) &&& (!%0.9)) . sort . pruneOutlyers
10541054
$ map f [l, l + (r-l)/80 .. r]
10551055
plot (GraphWindowSpecR2{..}) = curve `deepseq` mkPlot (trace curve)
10561056
where δx = (rBound - lBound) * 2 / fromIntegral xResolution
10571057
curve = [ (x ^& f x) | x<-[lBound, lBound+δx .. rBound] ]
10581058
trace (p:q:ps) = simpleLine p q <> trace (q:ps)
10591059
trace _ = mempty
10601060
pruneOutlyers = filter (not . isNaN)
1061-
l!n | (x:_)<-drop n l = x
1062-
| otherwise = error "Function appears to yield NaN most of the time. Cannot be plotted."
1061+
l!%η = case length l of
1062+
ll | ll<2 -> error
1063+
"Function appears to yield NaN most of the time. Cannot be plotted."
1064+
| otherwise -> l !! floor (fromIntegral ll * η)
10631065

10641066

10651067
type (-->) = RWDiffable

0 commit comments

Comments
 (0)