Improve the implementation for markers transforms - gsl-shell.git - gsl-shell

index : gsl-shell.git
gsl-shell
summary refs log tree commit diff
diff options
context:
space:
mode:
authorFrancesco Abbate <francesco.bbt@gmail.com>2011年12月18日 23:57:56 +0100
committerFrancesco Abbate <francesco.bbt@gmail.com>2011年12月18日 23:57:56 +0100
commit1f073c45dc94bbd0a8df7ab8540bb0fe2fecfd6e (patch)
treef209ee59ac3729dd262783096349654ee12ebc62
parent5f093983d4e62111c97436bbb2ce7bf433d1fe7b (diff)
downloadgsl-shell-1f073c45dc94bbd0a8df7ab8540bb0fe2fecfd6e.tar.gz
Improve the implementation for markers transforms
Diffstat
-rw-r--r--agg-plot/agg-parse-trans.cpp 28
-rw-r--r--agg-plot/markers.cpp 72
-rw-r--r--agg-plot/markers.h 1
-rw-r--r--agg-plot/trans.h 22
-rw-r--r--doc/user-manual/graphics.rst 5
5 files changed, 107 insertions, 21 deletions
diff --git a/agg-plot/agg-parse-trans.cpp b/agg-plot/agg-parse-trans.cpp
index 47ccdbe5..bad9e8ce 100644
--- a/agg-plot/agg-parse-trans.cpp
+++ b/agg-plot/agg-parse-trans.cpp
@@ -94,20 +94,38 @@ sg_object* build_marker (lua_State *L, int specindex, sg_object* src)
double size = mlua_named_optnumber(L, specindex, "size", 3.0);
lua_getfield(L, specindex, "mark");
- const char *sym_name = lua_tostring(L, -1);
sg_object *sym;
- if (!sym_name && gs_is_userdata(L, -1, GS_DRAW_SCALABLE))
+ if (lua_isnumber(L, -1))
{
- sg_object* obj = (sg_object*) lua_touserdata(L, -1);
- sym = new trans::scaling_a(obj);
+ int n = lua_tointeger(L, -1);
+ sym = new_marker_symbol(n);
}
else
{
- sym = new_marker_symbol(sym_name ? sym_name : "circle");
+ const char *sym_name = lua_tostring(L, -1);
+ if (!sym_name && gs_is_userdata(L, -1, GS_DRAW_SCALABLE))
+ {
+ sg_object* obj = (sg_object*) lua_touserdata(L, -1);
+ sym = new trans::scaling_a(obj);
+ }
+ else
+ {
+ sym = new_marker_symbol(sym_name ? sym_name : "circle");
+ }
}
lua_pop(L, 1);
+ lua_getfield(L, specindex, "outline");
+ bool outline = !lua_isnil(L, -1);
+ lua_pop(L, 1);
+
+ if (outline)
+ {
+ trans::stroke* stroke = new trans::stroke(sym);
+ sym = stroke;
+ }
+
return new trans::marker(src, size, sym);
}
diff --git a/agg-plot/markers.cpp b/agg-plot/markers.cpp
index f758c67e..1aca7586 100644
--- a/agg-plot/markers.cpp
+++ b/agg-plot/markers.cpp
@@ -16,11 +16,18 @@ struct symbol_reg {
static sg_object *build_circle();
static sg_object *build_square();
static sg_object *build_triangle();
+static sg_object *build_diamond();
+static sg_object *build_plus();
+static sg_object *build_cross();
-static struct symbol_reg builder_table[] = {
+const unsigned NB_SYMBOLS = 6;
+static struct symbol_reg builder_table[NB_SYMBOLS+1] = {
{"circle", build_circle},
{"square", build_square},
{"triangle", build_triangle},
+ {"diamond", build_diamond},
+ {"plus", build_plus},
+ {"cross", build_cross},
{NULL, NULL}
};
@@ -28,7 +35,7 @@ sg_object *
build_circle()
{
draw::ellipse* c = new draw::ellipse();
- trans::scaling* s = new trans::scaling((sg_object*)c);
+ trans::scaling* s = new trans::scaling(c);
c->self().init(0.0, 0.0, 0.5, 0.5);
return s;
}
@@ -37,8 +44,8 @@ sg_object *
build_square()
{
draw::path* p = new draw::path();
- trans::scaling* s = new trans::scaling((sg_object*)p);
-
+ trans::scaling* s = new trans::scaling(p);
+
agg::path_storage& square = p->self();
square.move_to(-0.5, -0.5);
square.line_to( 0.5, -0.5);
@@ -53,8 +60,8 @@ sg_object *
build_triangle()
{
draw::path* p = new draw::path();
- trans::scaling* s = new trans::scaling((sg_object*)p);
-
+ trans::scaling* s = new trans::scaling(p);
+
agg::path_storage& triangle = p->self();
double ht = 0.86602540378444;
@@ -66,6 +73,52 @@ build_triangle()
return s;
}
+sg_object *
+build_diamond()
+{
+ draw::path* p = new draw::path();
+ trans::scaling* s = new trans::scaling(p);
+
+ agg::path_storage& square = p->self();
+ square.move_to(-0.5, 0.0);
+ square.line_to( 0.0, 0.5);
+ square.line_to( 0.5, 0.0);
+ square.line_to( 0.0, -0.5);
+ square.close_polygon();
+
+ return s;
+}
+
+sg_object *
+build_plus()
+{
+ draw::path* p = new draw::path();
+ trans::scaling* s = new trans::scaling(p);
+
+ agg::path_storage& plus = p->self();
+ plus.move_to(-0.5, 0.0);
+ plus.line_to( 0.5, 0.0);
+ plus.move_to( 0.0, -0.5);
+ plus.line_to( 0.0, 0.5);
+
+ return new trans::stroke(s);
+}
+
+sg_object *
+build_cross()
+{
+ draw::path* p = new draw::path();
+ trans::scaling* s = new trans::scaling(p);
+
+ agg::path_storage& plus = p->self();
+ plus.move_to(-0.5, -0.5);
+ plus.line_to( 0.5, 0.5);
+ plus.move_to(-0.5, 0.5);
+ plus.line_to( 0.5, -0.5);
+
+ return new trans::stroke(s);
+}
+
sg_object*
new_marker_symbol (const char *req_name)
{
@@ -78,3 +131,10 @@ new_marker_symbol (const char *req_name)
return builder_table[0].builder();
}
+
+sg_object*
+new_marker_symbol (int n)
+{
+ n = (n-1) % NB_SYMBOLS;
+ return builder_table[n].builder();
+}
diff --git a/agg-plot/markers.h b/agg-plot/markers.h
index 47af2029..d7672bb7 100644
--- a/agg-plot/markers.h
+++ b/agg-plot/markers.h
@@ -4,5 +4,6 @@
#include "sg_object.h"
extern sg_object* new_marker_symbol(const char *name);
+extern sg_object* new_marker_symbol(int n);
#endif
diff --git a/agg-plot/trans.h b/agg-plot/trans.h
index 340659f7..a3f62926 100644
--- a/agg-plot/trans.h
+++ b/agg-plot/trans.h
@@ -162,7 +162,7 @@ struct trans {
str marker_def = gen_svg_marker_def(id, c, marker_id);
str path;
- svg_property_list* ls = this->m_source->svg_path(path);
+ svg_property_list* ls = m_source->svg_path(path);
str marker_url = gen_marker_url(marker_id);
const char* murl = marker_url.cstr();
@@ -183,8 +183,8 @@ struct trans {
virtual void apply_transform(const agg::trans_affine& m, double as)
{
- this->m_symbol->apply_transform(m_scale, as);
- this->m_source->apply_transform(m, as);
+ m_symbol->apply_transform(m_scale, as);
+ m_source->apply_transform(m, as);
}
private:
@@ -194,12 +194,12 @@ struct trans {
str gen_svg_marker_def(int id, agg::rgba8 c, str& marker_id) {
- marker_id.printf("marker%i", id);
+ m_scale.tx = m_size / 2.0;
+ m_scale.ty = m_size / 2.0;
- const double S = 20.0;
- agg::trans_affine m(S, 0.0, 0.0, S, S/2, S/2);
- m_symbol->apply_transform(m, 1.0);
+ marker_id.printf("marker%i", id);
+ const double S = m_size;
str marker_svg = m_symbol->write_svg(-1, c);
str s = str::print("<defs><marker id=\"%s\" "
@@ -208,7 +208,11 @@ struct trans {
"markerWidth=\"1\" markerHeight=\"1\">"
"%s"
"</marker></defs>",
- marker_id.cstr(), S/2, S/2, S, S, marker_svg.cstr());
+ marker_id.cstr(), S/2, S/2, S, S,
+ marker_svg.cstr());
+
+ m_scale.tx = 0.0;
+ m_scale.ty = 0.0;
return s;
}
@@ -220,7 +224,7 @@ struct trans {
struct marker : marker_a {
marker(sg_object* src, double size, sg_object* sym):
- marker_a(src, size, sym)
+ marker_a(src, size, sym)
{}
virtual ~marker() { delete m_source; }
diff --git a/doc/user-manual/graphics.rst b/doc/user-manual/graphics.rst
index 062372c2..efef8f25 100644
--- a/doc/user-manual/graphics.rst
+++ b/doc/user-manual/graphics.rst
@@ -671,9 +671,12 @@ Here a complete list of all the available transforms:
Replace each vertex of the path with a circular mark
* **size**, the size of the marker
- * **mark**, the kind of marker, can be 'circle', 'triangle' or 'square' or any graphical object provided by the user.
+ * **mark**, a string, an integer number or a graphical object indicating the symbol to be used for the markers.
+ Available simbols are 'circle', 'triangle', 'square', 'diamong', 'plus', 'cross'.
+ If a number is given the symbol will be chosed in the list given above.
If a graphical object is supplied its extension should be such that is contained in a box of size 1 and centered in (0, 0).
The object will be automatically scaled according to the parameter ``size``.
+ * **outline**, if it is true draw the marker in outline
**translate**
A translation along the x and y axis. This transformation can be used only in the user coordinate system.
generated by cgit v1.2.3 (git 2.39.1) at 2025年09月15日 20:07:09 +0000

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