summaryrefslogtreecommitdiffstats
path: root/src/sp-gradient.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/sp-gradient.cpp')
-rw-r--r--src/sp-gradient.cpp96
1 files changed, 79 insertions, 17 deletions
diff --git a/src/sp-gradient.cpp b/src/sp-gradient.cpp
index 04fb18cf3..115cb754a 100644
--- a/src/sp-gradient.cpp
+++ b/src/sp-gradient.cpp
@@ -111,31 +111,93 @@ gboolean SPGradient::isEquivalent(SPGradient *that)
{
//TODO Make this work for mesh gradients
- if (this->getStopCount() != that->getStopCount())
- return FALSE;
+ bool status = FALSE;
+
+ while(1){ // not really a loop, used to avoid deep nesting or multiple exit points from function
+ if (this->getStopCount() != that->getStopCount()) { break; }
+ if (this->hasStops() != that->hasStops()) { break; }
+ if (!this->getVector() || !that->getVector()) { break; }
+ if ( (SP_IS_LINEARGRADIENT(this) && SP_IS_LINEARGRADIENT(that)) ||
+ (SP_IS_RADIALGRADIENT(this) && SP_IS_RADIALGRADIENT(that)) ||
+ (SP_IS_MESHGRADIENT(this) && SP_IS_MESHGRADIENT(that))) {
+ /* OK! */
+ }
+ else { break; }
- if (this->hasStops() != that->hasStops())
- return FALSE;
+ SPStop *as = this->getVector()->getFirstStop();
+ SPStop *bs = that->getVector()->getFirstStop();
- if (!this->getVector() || !that->getVector())
- return FALSE;
+ bool effective = TRUE;
+ while (effective && (as && bs)) {
+ if (!as->getEffectiveColor().isClose(bs->getEffectiveColor(), 0.001) ||
+ as->offset != bs->offset) {
+ effective = FALSE;
+ break;
+ }
+ else {
+ as = as->getNextStop();
+ bs = bs->getNextStop();
+ }
+ }
+ if(!effective)break;
- SPStop *as = this->getVector()->getFirstStop();
- SPStop *bs = that->getVector()->getFirstStop();
+ status = TRUE;
+ break;
+ }
+ return status;
+}
- while (as && bs) {
- if (!as->getEffectiveColor().isClose(bs->getEffectiveColor(), 0.001) ||
- as->offset != bs->offset) {
- return FALSE;
+/**
+ * return true if this gradient is "aligned" to that gradient.
+ * Aligned means that they have exactly the same coordinates and transform.
+ * @param that - A gradient to compare this to
+ */
+gboolean SPGradient::isAligned(SPGradient *that)
+{
+ bool status = FALSE;
+
+ while(1){ // not really a loop, used to avoid deep nesting or multiple exit points from function
+ if(this->gradientTransform_set != that->gradientTransform_set) { break; }
+ if(this->gradientTransform_set &&
+ (this->gradientTransform != that->gradientTransform)) { break; }
+ if (SP_IS_LINEARGRADIENT(this) && SP_IS_LINEARGRADIENT(that)) {
+ SPLinearGradient *sg=SP_LINEARGRADIENT(this);
+ SPLinearGradient *tg=SP_LINEARGRADIENT(that);
+
+ if( !sg->x1._set || !tg->x1._set || // assume that if these are set so will be all the others
+ (sg->x1.computed != tg->x1.computed) ||
+ (sg->y1.computed != tg->y1.computed) ||
+ (sg->x2.computed != tg->x2.computed) ||
+ (sg->y2.computed != tg->y2.computed)
+ ) { break; }
+ } else if (SP_IS_RADIALGRADIENT(this) && SP_IS_LINEARGRADIENT(that)) {
+ SPRadialGradient *sg=SP_RADIALGRADIENT(this);
+ SPRadialGradient *tg=SP_RADIALGRADIENT(that);
+ if( !sg->cx._set || !tg->cx._set || // assume that if these are set so will be all the others
+ (sg->cx.computed != tg->cx.computed) ||
+ (sg->cy.computed != tg->cy.computed) ||
+ (sg->r.computed != tg->r.computed ) ||
+ (sg->fx.computed != tg->fx.computed) ||
+ (sg->fy.computed != tg->fy.computed)
+ ) { break; }
+ } else if (SP_IS_MESHGRADIENT(this) && SP_IS_MESHGRADIENT(that)) {
+ SPMeshGradient *sg=SP_MESHGRADIENT(this);
+ SPMeshGradient *tg=SP_MESHGRADIENT(that);
+
+ if( !sg->x._set || !tg->x._set ||
+ !sg->y._set || !tg->y._set ||
+ (sg->x.computed != tg->x.computed) ||
+ (sg->y.computed != tg->y.computed)
+ ) { break; }
+ } else {
+ break;
}
- as = as->getNextStop();
- bs = bs->getNextStop();
+ status = TRUE;
+ break;
}
-
- return TRUE;
+ return status;
}
-
/*
* Gradient
*/