From bf7c3e8d98b557cb64447804399797d93e1cedc0 Mon Sep 17 00:00:00 2001 From: John Smith Date: Wed, 19 Sep 2012 10:52:19 +0900 Subject: Fix for 643150 : Auto-palette swatches duplicated on copy and paste (bzr r11677) --- src/sp-gradient.cpp | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'src/sp-gradient.cpp') diff --git a/src/sp-gradient.cpp b/src/sp-gradient.cpp index 262c35db1..5efa3c84f 100644 --- a/src/sp-gradient.cpp +++ b/src/sp-gradient.cpp @@ -346,6 +346,41 @@ void SPGradient::setSwatch( bool swatch ) } } + +/** + * return true if this gradient is "equivalent" to that gradient. + * Equivalent meaning they have the same stop count, same stop colors and same stop opacity + * @param that - A gradient to compare this to + */ +gboolean SPGradient::isEquivalent(SPGradient *that) +{ + //TODO Make this work for mesh gradients + + if (this->getStopCount() != that->getStopCount()) + return FALSE; + + if (this->hasStops() != that->hasStops()) + return FALSE; + + if (!this->getVector() || !that->getVector()) + return FALSE; + + SPStop *as = this->getVector()->getFirstStop(); + SPStop *bs = that->getVector()->getFirstStop(); + + while (as && bs) { + if (!as->getEffectiveColor().isClose(bs->getEffectiveColor(), 0.001) || + as->offset != bs->offset) { + return FALSE; + } + as = as->getNextStop(); + bs = bs->getNextStop(); + } + + return TRUE; +} + + /** * Return stop's color as 32bit value. */ @@ -2211,6 +2246,7 @@ sp_meshgradient_repr_write(SPMeshGradient *mg) mg->array.write( mg ); } + /* Local Variables: mode:c++ -- cgit v1.2.3