summaryrefslogtreecommitdiffstats
path: root/src/sp-spiral.cpp
diff options
context:
space:
mode:
authorMarkus Engel <markus.engel@tum.de>2013-09-24 22:26:56 +0000
committerMarkus Engel <markus.engel@tum.de>2013-09-24 22:26:56 +0000
commit34f62f6df3f4a18f6ea25c3a1b63e6b47fdc7c5d (patch)
treead8f4e271aa02e76aa3c1e3210d1af1f6a663581 /src/sp-spiral.cpp
parentMerged from trunk (r12588). (diff)
downloadinkscape-34f62f6df3f4a18f6ea25c3a1b63e6b47fdc7c5d.tar.gz
inkscape-34f62f6df3f4a18f6ea25c3a1b63e6b47fdc7c5d.zip
Refactored SPSpiral.
(bzr r11608.1.130)
Diffstat (limited to 'src/sp-spiral.cpp')
-rw-r--r--src/sp-spiral.cpp95
1 files changed, 46 insertions, 49 deletions
diff --git a/src/sp-spiral.cpp b/src/sp-spiral.cpp
index 0c5ef253f..6a22059a8 100644
--- a/src/sp-spiral.cpp
+++ b/src/sp-spiral.cpp
@@ -38,14 +38,16 @@ namespace {
bool spiralRegistered = SPFactory::instance().registerObject("spiral", createSpiral);
}
-SPSpiral::SPSpiral() : SPShape() {
- this->cx = 0.0;
- this->cy = 0.0;
- this->exp = 1.0;
- this->revo = 3.0;
- this->rad = 1.0;
- this->arg = 0.0;
- this->t0 = 0.0;
+SPSpiral::SPSpiral()
+ : SPShape()
+ , cx(0)
+ , cy(0)
+ , exp(1)
+ , revo(3)
+ , rad(1)
+ , arg(0)
+ , t0(0)
+{
}
SPSpiral::~SPSpiral() {
@@ -85,11 +87,12 @@ Inkscape::XML::Node* SPSpiral::write(Inkscape::XML::Document *xml_doc, Inkscape:
// make sure the curve is rebuilt with all up-to-date parameters
this->set_shape();
- //Nulls might be possible if this called iteratively
+ // Nulls might be possible if this called iteratively
if (!this->_curve) {
//g_warning("sp_spiral_write(): No path to copy\n");
return NULL;
}
+
char *d = sp_svg_write_path(this->_curve->get_pathvector());
repr->setAttribute("d", d);
g_free(d);
@@ -198,24 +201,21 @@ void SPSpiral::set(unsigned int key, gchar const* value) {
}
void SPSpiral::update(SPCtx *ctx, guint flags) {
- SPSpiral* object = this;
-
if (flags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG)) {
- reinterpret_cast<SPShape *>(object)->set_shape();
+ this->set_shape();
}
SPShape::update(ctx, flags);
}
void SPSpiral::update_patheffect(bool write) {
- SPSpiral* shape = this;
-
this->set_shape();
if (write) {
- Inkscape::XML::Node *repr = shape->getRepr();
- if ( shape->_curve != NULL ) {
- gchar *str = sp_svg_write_path(shape->_curve->get_pathvector());
+ Inkscape::XML::Node *repr = this->getRepr();
+
+ if ( this->_curve != NULL ) {
+ gchar *str = sp_svg_write_path(this->_curve->get_pathvector());
repr->setAttribute("d", str);
g_free(str);
} else {
@@ -223,7 +223,7 @@ void SPSpiral::update_patheffect(bool write) {
}
}
- shape->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
+ this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
}
const char* SPSpiral::displayName() {
@@ -233,7 +233,7 @@ const char* SPSpiral::displayName() {
gchar* SPSpiral::description() {
// TRANSLATORS: since turn count isn't an integer, please adjust the
// string as needed to deal with an localized plural forms.
- return g_strdup_printf (_("with %3f turns"), SP_SPIRAL(this)->revo);
+ return g_strdup_printf (_("with %3f turns"), this->revo);
}
/**
@@ -323,18 +323,15 @@ void SPSpiral::fitAndDraw(SPCurve* c, double dstep, Geom::Point darray[], Geom::
}
void SPSpiral::set_shape() {
- SPSpiral *spiral = this;
- SPSpiral* shape = spiral;
-
- if (sp_lpe_item_has_broken_path_effect(SP_LPE_ITEM(shape))) {
+ if (sp_lpe_item_has_broken_path_effect(this)) {
g_warning ("The spiral shape has unknown LPE on it! Convert to path to make it editable preserving the appearance; editing it as spiral will remove the bad LPE");
- if (shape->getRepr()->attribute("d")) {
+ if (this->getRepr()->attribute("d")) {
// unconditionally read the curve from d, if any, to preserve appearance
- Geom::PathVector pv = sp_svg_read_pathv(shape->getRepr()->attribute("d"));
+ Geom::PathVector pv = sp_svg_read_pathv(this->getRepr()->attribute("d"));
SPCurve *cold = new SPCurve(pv);
- shape->setCurveInsync( cold, TRUE);
- shape->setCurveBeforeLPE( cold );
+ this->setCurveInsync( cold, TRUE);
+ this->setCurveBeforeLPE( cold );
cold->unref();
}
@@ -344,51 +341,51 @@ void SPSpiral::set_shape() {
Geom::Point darray[SAMPLE_SIZE + 1];
double t;
- spiral->requestModified(SP_OBJECT_MODIFIED_FLAG);
+ this->requestModified(SP_OBJECT_MODIFIED_FLAG);
SPCurve *c = new SPCurve ();
#ifdef SPIRAL_VERBOSE
g_print ("cx=%g, cy=%g, exp=%g, revo=%g, rad=%g, arg=%g, t0=%g\n",
- spiral->cx,
- spiral->cy,
- spiral->exp,
- spiral->revo,
- spiral->rad,
- spiral->arg,
- spiral->t0);
+ this->cx,
+ this->cy,
+ this->exp,
+ this->revo,
+ this->rad,
+ this->arg,
+ this->t0);
#endif
/* Initial moveto. */
- c->moveto(spiral->getXY(spiral->t0));
+ c->moveto(this->getXY(this->t0));
- double const tstep = SAMPLE_STEP / spiral->revo;
+ double const tstep = SAMPLE_STEP / this->revo;
double const dstep = tstep / (SAMPLE_SIZE - 1);
- Geom::Point hat1 = spiral->getTangent(spiral->t0);
+ Geom::Point hat1 = this->getTangent(this->t0);
Geom::Point hat2;
- for (t = spiral->t0; t < (1.0 - tstep);) {
- spiral->fitAndDraw(c, dstep, darray, hat1, hat2, &t);
+ for (t = this->t0; t < (1.0 - tstep);) {
+ this->fitAndDraw(c, dstep, darray, hat1, hat2, &t);
hat1 = -hat2;
}
if ((1.0 - t) > SP_EPSILON) {
- spiral->fitAndDraw(c, (1.0 - t) / (SAMPLE_SIZE - 1.0), darray, hat1, hat2, &t);
+ this->fitAndDraw(c, (1.0 - t) / (SAMPLE_SIZE - 1.0), darray, hat1, hat2, &t);
}
/* Reset the shape'scurve to the "original_curve"
* This is very important for LPEs to work properly! (the bbox might be recalculated depending on the curve in shape)*/
- shape->setCurveInsync( c, TRUE);
- shape->setCurveBeforeLPE( c );
+ this->setCurveInsync( c, TRUE);
+ this->setCurveBeforeLPE( c );
- if (sp_lpe_item_has_path_effect(SP_LPE_ITEM(shape)) && sp_lpe_item_path_effects_enabled(SP_LPE_ITEM(shape))) {
+ if (sp_lpe_item_has_path_effect(this) && sp_lpe_item_path_effects_enabled(this)) {
SPCurve *c_lpe = c->copy();
- bool success = sp_lpe_item_perform_path_effect(SP_LPE_ITEM (shape), c_lpe);
+ bool success = sp_lpe_item_perform_path_effect(this, c_lpe);
if (success) {
- shape->setCurveInsync( c_lpe, TRUE);
+ this->setCurveInsync( c_lpe, TRUE);
}
c_lpe->unref();
@@ -593,17 +590,17 @@ bool SPSpiral::isInvalid() const {
if (rad < 0.0 || rad > SP_HUGE) {
g_print("rad(t=0)=%g\n", rad);
- return TRUE;
+ return true;
}
this->getPolar(1.0, &rad, NULL);
if (rad < 0.0 || rad > SP_HUGE) {
g_print("rad(t=1)=%g\n", rad);
- return TRUE;
+ return true;
}
- return FALSE;
+ return false;
}
/*