gsl-shell.git - gsl-shell

index : gsl-shell.git
gsl-shell
summary refs log tree commit diff
path: root/graph-init.lua
diff options
context:
space:
mode:
authorFrancesco Abbate <francesco.bbt@gmail.com>2011年11月07日 10:34:52 +0100
committerFrancesco Abbate <francesco.bbt@gmail.com>2011年11月07日 10:34:52 +0100
commit495ece07f7c208b1bdbbebe392c8c00060cf812a (patch)
tree7a1d6f264585b0866b1ed39497ef30c16a295238 /graph-init.lua
parent7b1bc314e92d0723ecf85ebcec0a0ab60c1bdc5a (diff)
downloadgsl-shell-495ece07f7c208b1bdbbebe392c8c00060cf812a.tar.gz
Add check for the number of sampling points
Diffstat (limited to 'graph-init.lua')
-rw-r--r--graph-init.lua 22
1 files changed, 20 insertions, 2 deletions
diff --git a/graph-init.lua b/graph-init.lua
index 1d173a6b..5b30fcdb 100644
--- a/graph-init.lua
+++ b/graph-init.lua
@@ -7,6 +7,24 @@ local bor, band, lshift, rshift = bit.bor, bit.band, bit.lshift, bit.rshift
local lua_index_style = gslsh.lua_index_style
+local n_sampling_max = 8192
+local n_sampling_default = 512
+
+local function check_sampling(n)
+ if n then
+ if n <= 1 then
+ error('sampling points should be > 1')
+ elseif n > n_sampling_max then
+ echo('warning: too many sampling points requested, ' ..
+ 'limiting to ' .. n_sampling_max)
+ n = n_sampling_max
+ end
+ else
+ n = n_sampling_default
+ end
+ return n
+end
+
function graph.ipath(f)
local ln = graph.path(f())
for x, y in f do
@@ -34,7 +52,7 @@ function graph.ipathp(f)
end
function graph.fxline(f, xi, xs, n)
- n = n and math.min(n, 8192) or 512
+ n = check_sampling(n)
return graph.ipath(iter.sample(f, xi, xs, n))
end
@@ -51,7 +69,7 @@ function graph.xyline(x, y)
end
function graph.fxplot(f, xi, xs, color, n)
- n = n and n or 512
+ n = check_sampling(n)
local p = graph.plot()
p:addline(graph.ipathp(iter.sample(f, xi, xs, n)), color)
p:show()
generated by cgit v1.2.3 (git 2.25.1) at 2025年09月18日 07:36:02 +0000

AltStyle によって変換されたページ (->オリジナル) /