-
Notifications
You must be signed in to change notification settings - Fork 0
/
interface.scm
116 lines (94 loc) · 3.7 KB
/
interface.scm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
;;; This file is part of Adaptive Plot, a library for intelligently
;;; plotting functions from the MIT Scheme REPL.
;;; Copyright (C) 2013 Alexey Radul
;;;
;;; Adaptive Plot is free software: you can redistribute it and/or
;;; modify it under the terms of the GNU Affero General Public License
;;; as published by the Free Software Foundation, either version 3 of
;;; the License, or (at your option) any later version.
;;;
;;; Adaptive Plot is distributed in the hope that it will be useful,
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
;;; Affero General Public License for more details.
;;;
;;; You should have received a copy of the GNU Affero General Public
;;; License along with Adaptive Plot. If not, see
;;; <http://www.gnu.org/licenses/>.
(declare (usual-integrations))
;;;; Interface
;;; This file collects the functions that are meant to be called
;;; directly by the user, as opposed to other parts of the system.
;;; Not all documented user-facing functions are to be found here, but
;;; the major and common ones are.
;;;; Facade: common patterns made simple
(define (plot f xlow xhigh . adverbs)
(apply replot (new-plot f xlow xhigh) adverbs))
(define (replot plot . adverbs)
(define scheme-window-wanted?
(not (eq? (last
(filter (lambda (a) (or (eq? a 'invisibly) (eq? a 'visibly)))
(cons 'visibly adverbs)))
'invisibly)))
(if scheme-window-wanted?
(plot-draw! plot))
(apply plot-refine! plot adverbs)
plot)
(define (gnuplot f xlow xhigh . adverbs)
(apply regnuplot (new-plot f xlow xhigh) adverbs))
(define (regnuplot plot . adverbs)
(apply plot-gnu!
(plot-stop-drawing!
(apply replot plot 'invisibly adverbs)) adverbs))
;;;; Interactive manipulation
;; (plot ... 'invisibly)
;; Also plot-draw! and plot-stop-drawing!
(define (plot-gnu! plot . adverbs)
(apply gnuplot-alist (plot-relevant-points-alist plot) adverbs)
plot)
(define (plot-zoom! plot #!optional new-xlow new-xhigh new-ylow new-yhigh)
(plot-resize! plot new-xlow new-xhigh new-ylow new-yhigh)
(plot-refine! plot))
(define (plot-zoom-x! plot #!optional new-xlow new-xhigh)
(plot-resize-x! plot new-xlow new-xhigh)
(plot-refine! plot))
(define (plot-zoom-y! plot #!optional new-ylow new-yhigh)
(plot-resize-y! plot new-ylow new-yhigh)
(plot-refine! plot))
(define (plot-resolve! plot xres yres)
(plot-new-resolution! plot xres yres)
(plot-refine! plot))
;;;; No autorefinement
(define (new-plot f xlow xhigh)
(letrec ((plot
(make-plot
(lambda (x)
(let ((answer (f x)))
(plot-draw-point! plot x answer)
answer)))))
(plot-resize-x! plot xlow xhigh)
plot))
(define (plot-refine! plot . adverbs)
(interpret-refinement-adverb
(last (filter refinement-adverb? (cons 'adaptively adverbs)))
plot))
(define refinement-functions
`((adaptively . ,plot-adaptive-refine!)
(adaptively-with . ,plot-adaptive-refine*!)
(adaptively-to-with . ,plot-adaptive-refine**!)
(uniformly . ,plot-uniform-refine!)
(x-uniformly . ,plot-uniform-refine-x!)
(y-uniformly . ,plot-uniform-refine-y!)))
(define (refinement-adverb? adverb)
(or (memq adverb (map car refinement-functions))
(and (pair? adverb)
(memq (car adverb)
(map car refinement-functions)))))
(define (interpret-refinement-adverb adverb plot)
(define (refinement-function name)
;; Never errors out because I filter the adverbs
(cdr (assq name refinement-functions)))
(if (not (pair? adverb))
(interpret-refinement-adverb (list adverb) plot)
(apply (refinement-function (car adverb))
plot (cdr adverb))))