added "scale" affine transformation for graphics pipeline - gsl-shell.git - gsl-shell

index : gsl-shell.git
gsl-shell
summary refs log tree commit diff
diff options
context:
space:
mode:
authorfrancesco-ST <francesco.abbate@st.com>2010年12月28日 13:36:33 +0100
committerfrancesco-ST <francesco.abbate@st.com>2010年12月28日 13:36:33 +0100
commit45ae5dceb38d665e446960618cb8c1cda5f5afc5 (patch)
treee596adfbe330b99d6a0b6b7cd684510b5a10680e
parent6d4c09d61a370c79ed8b41282ed7ad13a0d7f989 (diff)
downloadgsl-shell-45ae5dceb38d665e446960618cb8c1cda5f5afc5.tar.gz
added "scale" affine transformation for graphics pipeline
Added a specific error code. Documentation and fractal example updated.
Diffstat
-rw-r--r--agg-plot/agg-parse-trans.cpp 21
-rw-r--r--agg-plot/agg-parse-trans.h 1
-rw-r--r--doc/source/graphics.rst 5
-rw-r--r--examples/fractals.lua 45
4 files changed, 38 insertions, 34 deletions
diff --git a/agg-plot/agg-parse-trans.cpp b/agg-plot/agg-parse-trans.cpp
index 42f528fa..4547db24 100644
--- a/agg-plot/agg-parse-trans.cpp
+++ b/agg-plot/agg-parse-trans.cpp
@@ -46,6 +46,7 @@ struct property_reg line_join_properties[] = {
const char *agg_spec_error::m_msg[] = {
"invalid specification tag",
"invalid specification table",
+ "missing specification parameter",
"invalid graphical object",
"generic error during graphical operation"
};
@@ -177,6 +178,25 @@ build_translate (lua_State *L, int specindex, typename context::base_type *obj)
}
template <class context> typename context::base_type*
+build_scale (lua_State *L, int specindex, typename context::base_type *obj)
+{
+ typedef typename trans<context>::affine affine_type;
+
+ lua_rawgeti (L, specindex, 2);
+
+ if (! lua_isnumber (L, -1))
+ throw agg_spec_error(agg_spec_error::missing_parameter);
+
+ double s = lua_tonumber (L, -1);
+ lua_pop (L, 1);
+
+ agg::trans_affine mtx(s, 0.0, 0.0, s, 0.0, 0.0);
+ affine_type *t = new affine_type(obj, mtx);
+
+ return (typename context::base_type *) t;
+}
+
+template <class context> typename context::base_type*
build_rotate (lua_State *L, int specindex, typename context::base_type *obj)
{
typedef typename trans<context>::affine affine_type;
@@ -227,6 +247,7 @@ const typename builder<context>::reg builder<context>::builder_table[] = {
{"marker", build_marker <context>},
{"extend", build_extend <context>},
{"translate", build_translate<context>},
+ {"scale", build_scale <context>},
{"rotate", build_rotate <context>},
{NULL, NULL}
};
diff --git a/agg-plot/agg-parse-trans.h b/agg-plot/agg-parse-trans.h
index cd5848f9..66bac15e 100644
--- a/agg-plot/agg-parse-trans.h
+++ b/agg-plot/agg-parse-trans.h
@@ -16,6 +16,7 @@ public:
enum err_e {
invalid_tag = 0,
invalid_spec,
+ missing_parameter,
invalid_object,
generic_error
};
diff --git a/doc/source/graphics.rst b/doc/source/graphics.rst
index 66da1750..f7e539c8 100644
--- a/doc/source/graphics.rst
+++ b/doc/source/graphics.rst
@@ -600,6 +600,11 @@ Here a complete list of all the available transforms:
* **x**, translation along the x axis
* **y**, translation along the y axis
+ **scale**
+ A scaling of the image around the point (0, 0). Only one numeric
+ parameter should be supplied to indicate the scaling factor. For
+ example ``{'scale', 2}`` will scale the image of a factor two.
+
**rotate**
A rotation of a given angle with respect of the origin. This transformation can be used only in the user coordinate system.
diff --git a/examples/fractals.lua b/examples/fractals.lua
index 9f32717f..168ef83e 100644
--- a/examples/fractals.lua
+++ b/examples/fractals.lua
@@ -67,36 +67,16 @@ end
demo2 = function(n) return levyc(n and n or 6) end
-function get_box_gener()
- local pbox = {}
-
- local function get(ll)
- local b = pbox[ll]
- if not b then
- b = rect(0, 0, ll, ll)
- pbox[ll] = b
- end
- return b
- end
-
- local function count()
- local c = 0
- for k, v in pairs(pbox) do c = c+1 end
- return c
- end
- return get, count
-end
-
function demo3()
local rdsd = sqrt(2)/2
+ local ubox = rect(0, 0, 1, 1)
local cf
- local get_box, box_count = get_box_gener()
-
local function pitag_tree(pl, x, y, th, ll, depth)
- local box = get_box(ll)
local col = cf(depth)
- pl:add(box, col, {}, {{'translate', x= x, y= y}, {'rotate', angle= th}})
+ pl:add(ubox, col, {}, {{'translate', x= x, y= y},
+ {'rotate', angle= th},
+ {'scale', ll}})
if depth > 0 then
x, y = x - ll*sin(th), y + ll*cos(th)
pitag_tree(pl, x, y, th + pi/4, ll*rdsd, depth-1)
@@ -113,7 +93,6 @@ function demo3()
pitag_tree(pl, 0, 0, 0, 1, depth)
pl:show()
- print('number of used rectangles:', box_count())
return pl
end
@@ -188,17 +167,16 @@ function demo3ter(n)
end
function demo4(n)
+ local ubox = rect(0, 0, 1, 1)
n = n and n or 10
local col, coln
- local get_box, box_count = get_box_gener()
-
local function pitag_tree(pl, x, y, th, ll, depth)
if depth == 0 then
- local box = get_box(ll)
- local tr = {{'translate', x= x, y= y}, {'rotate', angle= th}}
- pl:add(box, col, {}, tr)
- pl:add(box, coln, {{'stroke', width= 2.5*ll}}, tr)
+ local tr = {{'translate', x= x, y= y}, {'rotate', angle= th},
+ {'scale', ll}}
+ pl:add(ubox, col, {}, tr)
+ pl:add(ubox, coln, {{'stroke', width= 2.5*ll}}, tr)
end
if depth > 0 then
x, y = x - ll*sin(th), y + ll*cos(th)
@@ -212,16 +190,15 @@ function demo4(n)
local cfgen = color_function('darkgreen', 1)
local pl = plot()
- pl.units = false
pl.sync = false
pl:show()
for k=0, n do
col, coln = cfgen(k/n), cfgen((k+1)/n)
pitag_tree(pl, 0, 0, 0, 1, k)
- pl:flush()
+ pl:flush()
end
- print('number of used rectangles:', box_count())
+
return pl
end
generated by cgit v1.2.3 (git 2.39.1) at 2025年09月17日 12:38:58 +0000

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