Skip to content

Commit c047941

Browse files
Support for ill-behaved pointsweb-supported uncertain functions.
1 parent 16022c4 commit c047941

1 file changed

Lines changed: 23 additions & 11 deletions

File tree

  • Graphics/Dynamic/Plot

Graphics/Dynamic/Plot/R2.hs

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ import Control.Concurrent.Async
9696
import Control.DeepSeq
9797

9898

99-
import Data.List (foldl', sort, sortBy, intercalate, isPrefixOf, isInfixOf, find, zip4)
99+
import Data.List (foldl', sort, sortBy, partition, zip4)
100100
import qualified Data.List.NonEmpty as NE
101101
import qualified Data.Vector as Arr
102102
import Data.Maybe
@@ -530,28 +530,40 @@ instance Plottable (PointsWeb ℝ (Shade' ℝ)) where
530530
}
531531
where plot grWS@(GraphWindowSpecR2{..}) = mkPlot $
532532
foldMap parallelogram trivs
533+
<> foldMap vbar divis
533534
where parallelogram ((x,δx), ((y,δy), j))
534535
= lLoop [ (x+δx)^&(y+δy+jδx), (x-δx)^&(y+δy-jδx)
535536
, (x-δx)^&(y-δy-jδx), (x+δx)^&(y-δy+jδx) ]
536537
& Dia.strokeLocLoop
537538
& Dia.opacity 0.3
538539
where jδx = j $ δx
540+
vbar (x,δx) = Dia.fromVertices
541+
[ (x-δx)^&tBound, (x-δx)^&bBound
542+
, (x+δx)^&bBound, (x+δx)^&tBound ]
539543

540544
trivs :: [((, Diff ), ((, Diff ), LocalLinear ))]
541-
trivs = map mkTriv locals
545+
divis :: [(, Diff )]
546+
(trivs,divis) = concat***concat $ unzip (map mkTriv locals)
542547
where mkTriv ((xc,Shade' yc yce), [(δxo, Shade' yo _)])
543-
= ( (xc, δxo)
544-
, ( (yc, metricAsLength yce)
545-
, denseLinear $ \δx -> δx * (yo-yc)/δxo ) )
548+
= case tryMetricAsLength yce of
549+
Option (Just ry) ->
550+
( [ ( (xc, δxo)
551+
, ( (yc, ry)
552+
, denseLinear $ \δx -> δx * (yo-yc)/δxo ) ) ], [] )
553+
Option Nothing ->
554+
( [], [(xc, δxo)] )
546555
mkTriv ((xc,Shade' yc yce), [(δxl, Shade' yl _), (δxr, Shade' yr _)])
547-
= ( (xc, δxg)
548-
, ( (yc, metricAsLength yce)
549-
, denseLinear $ \δx -> δx * η ) )
556+
= case tryMetricAsLength yce of
557+
Option (Just ry) ->
558+
( [ ( (xc, δxg)
559+
, ( (yc, ry)
560+
, denseLinear $ \δx -> δx * η ) ) ], [] )
561+
Option Nothing ->
562+
( [], [(xc, δxg)] )
550563
where δxg = (δxr - δxl)/2
551564
η = (yr - yl)/(2*δxg)
552-
mkTriv (_,l) = error $ "Encountered point in web with "
553-
++show(length l)++" neighbours. Any point in 1D "
554-
++"should have either one or two neighbours!"
565+
mkTriv (p,lrs) = concat***concat $ unzip [mkTriv (p,[l,r]) | l<-ls, r<-rs]
566+
where (ls,rs) = partition ((<0) . fst) lrs
555567

556568
lLoop ps@(p:_) = Dia.fromVertices $ ps++[p]
557569

0 commit comments

Comments
 (0)