This is an automated email from the ASF dual-hosted git repository. mseidel pushed a commit to branch trunk in repository https://gitbox.apache.org/repos/asf/openoffice.git
The following commit(s) were added to refs/heads/trunk by this push: new 42fb6e95e2 Cleanup 42fb6e95e2 is described below commit 42fb6e95e2f95f39ff1eee3336bd998cf8ae20a1 Author: mseidel <msei...@apache.org> AuthorDate: Fri Apr 25 13:09:32 2025 +0200 Cleanup --- main/basegfx/source/color/bcolor.cxx | 15 +- main/basegfx/source/color/bcolormodifier.cxx | 529 +++++++++++------------ main/basegfx/source/color/bcolortools.cxx | 463 ++++++++++---------- main/basegfx/source/curve/b2dbeziertools.cxx | 20 +- main/basegfx/source/curve/b2dcubicbezier.cxx | 290 ++++++------- main/basegfx/source/curve/b2dquadraticbezier.cxx | 20 +- 6 files changed, 645 insertions(+), 692 deletions(-) diff --git a/main/basegfx/source/color/bcolor.cxx b/main/basegfx/source/color/bcolor.cxx index 4291fe8260..852522137f 100644 --- a/main/basegfx/source/color/bcolor.cxx +++ b/main/basegfx/source/color/bcolor.cxx @@ -1,5 +1,5 @@ /************************************************************** - * + * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information @@ -7,30 +7,25 @@ * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. - * + * *************************************************************/ - - // MARKER(update_precomp.py): autogen include statement, do not remove #include "precompiled_basegfx.hxx" #include <basegfx/color/bcolor.hxx> -////////////////////////////////////////////////////////////////////////////// - namespace basegfx { } // end of namespace basegfx -////////////////////////////////////////////////////////////////////////////// -// eof +/* vim: set noet sw=4 ts=4: */ diff --git a/main/basegfx/source/color/bcolormodifier.cxx b/main/basegfx/source/color/bcolormodifier.cxx index 4294b68100..50e7695320 100644 --- a/main/basegfx/source/color/bcolormodifier.cxx +++ b/main/basegfx/source/color/bcolormodifier.cxx @@ -1,5 +1,5 @@ /************************************************************** - * + * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information @@ -7,16 +7,16 @@ * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. - * + * *************************************************************/ // MARKER(update_precomp.py): autogen include statement, do not remove @@ -24,320 +24,299 @@ #include <basegfx/color/bcolormodifier.hxx> -////////////////////////////////////////////////////////////////////////////// - namespace basegfx { - BColorModifier::~BColorModifier() - { - } + BColorModifier::~BColorModifier() + { + } } // end of namespace basegfx -////////////////////////////////////////////////////////////////////////////// - namespace basegfx { - BColorModifier_gray::~BColorModifier_gray() - { - } + BColorModifier_gray::~BColorModifier_gray() + { + } - bool BColorModifier_gray::operator==(const BColorModifier& rCompare) const - { - return 0 != dynamic_cast< const BColorModifier_gray* >(&rCompare); - } + bool BColorModifier_gray::operator==(const BColorModifier& rCompare) const + { + return 0 != dynamic_cast< const BColorModifier_gray* >(&rCompare); + } - ::basegfx::BColor BColorModifier_gray::getModifiedColor(const ::basegfx::BColor& aSourceColor) const - { - const double fLuminance(aSourceColor.luminance()); + ::basegfx::BColor BColorModifier_gray::getModifiedColor(const ::basegfx::BColor& aSourceColor) const + { + const double fLuminance(aSourceColor.luminance()); - return ::basegfx::BColor(fLuminance, fLuminance, fLuminance); - } + return ::basegfx::BColor(fLuminance, fLuminance, fLuminance); + } } // end of namespace basegfx -////////////////////////////////////////////////////////////////////////////// - namespace basegfx { - BColorModifier_invert::~BColorModifier_invert() - { - } - - bool BColorModifier_invert::operator==(const BColorModifier& rCompare) const - { - return 0 != dynamic_cast< const BColorModifier_invert* >(&rCompare); - } - - ::basegfx::BColor BColorModifier_invert::getModifiedColor(const ::basegfx::BColor& aSourceColor) const - { - return ::basegfx::BColor(1.0 - aSourceColor.getRed(), 1.0 - aSourceColor.getGreen(), 1.0 - aSourceColor.getBlue()); - } + BColorModifier_invert::~BColorModifier_invert() + { + } + + bool BColorModifier_invert::operator==(const BColorModifier& rCompare) const + { + return 0 != dynamic_cast< const BColorModifier_invert* >(&rCompare); + } + + ::basegfx::BColor BColorModifier_invert::getModifiedColor(const ::basegfx::BColor& aSourceColor) const + { + return ::basegfx::BColor(1.0 - aSourceColor.getRed(), 1.0 - aSourceColor.getGreen(), 1.0 - aSourceColor.getBlue()); + } } // end of namespace basegfx -////////////////////////////////////////////////////////////////////////////// - namespace basegfx { - BColorModifier_luminance_to_alpha::~BColorModifier_luminance_to_alpha() - { - } + BColorModifier_luminance_to_alpha::~BColorModifier_luminance_to_alpha() + { + } - bool BColorModifier_luminance_to_alpha::operator==(const BColorModifier& rCompare) const - { - return 0 != dynamic_cast< const BColorModifier_luminance_to_alpha* >(&rCompare); - } + bool BColorModifier_luminance_to_alpha::operator==(const BColorModifier& rCompare) const + { + return 0 != dynamic_cast< const BColorModifier_luminance_to_alpha* >(&rCompare); + } - ::basegfx::BColor BColorModifier_luminance_to_alpha::getModifiedColor(const ::basegfx::BColor& aSourceColor) const - { - const double fAlpha(1.0 - ((aSourceColor.getRed() * 0.2125) + (aSourceColor.getGreen() * 0.7154) + (aSourceColor.getBlue() * 0.0721))); + ::basegfx::BColor BColorModifier_luminance_to_alpha::getModifiedColor(const ::basegfx::BColor& aSourceColor) const + { + const double fAlpha(1.0 - ((aSourceColor.getRed() * 0.2125) + (aSourceColor.getGreen() * 0.7154) + (aSourceColor.getBlue() * 0.0721))); - return ::basegfx::BColor(fAlpha, fAlpha, fAlpha); - } + return ::basegfx::BColor(fAlpha, fAlpha, fAlpha); + } } // end of namespace basegfx -////////////////////////////////////////////////////////////////////////////// - namespace basegfx { - BColorModifier_replace::~BColorModifier_replace() - { - } - - bool BColorModifier_replace::operator==(const BColorModifier& rCompare) const - { - const BColorModifier_replace* pCompare = dynamic_cast< const BColorModifier_replace* >(&rCompare); - - if(!pCompare) - { - return false; - } - - return getBColor() == pCompare->getBColor(); - } - - ::basegfx::BColor BColorModifier_replace::getModifiedColor(const ::basegfx::BColor& /*aSourceColor*/) const - { - return maBColor; - } + BColorModifier_replace::~BColorModifier_replace() + { + } + + bool BColorModifier_replace::operator==(const BColorModifier& rCompare) const + { + const BColorModifier_replace* pCompare = dynamic_cast< const BColorModifier_replace* >(&rCompare); + + if(!pCompare) + { + return false; + } + + return getBColor() == pCompare->getBColor(); + } + + ::basegfx::BColor BColorModifier_replace::getModifiedColor(const ::basegfx::BColor& /*aSourceColor*/) const + { + return maBColor; + } } // end of namespace basegfx -////////////////////////////////////////////////////////////////////////////// - namespace basegfx { - BColorModifier_interpolate::~BColorModifier_interpolate() - { - } - - bool BColorModifier_interpolate::operator==(const BColorModifier& rCompare) const - { - const BColorModifier_interpolate* pCompare = dynamic_cast< const BColorModifier_interpolate* >(&rCompare); - - if(!pCompare) - { - return false; - } - - return getBColor() == pCompare->getBColor() && getValue() == pCompare->getValue(); - } - - ::basegfx::BColor BColorModifier_interpolate::getModifiedColor(const ::basegfx::BColor& aSourceColor) const - { - return interpolate(maBColor, aSourceColor, mfValue); - } + BColorModifier_interpolate::~BColorModifier_interpolate() + { + } + + bool BColorModifier_interpolate::operator==(const BColorModifier& rCompare) const + { + const BColorModifier_interpolate* pCompare = dynamic_cast< const BColorModifier_interpolate* >(&rCompare); + + if(!pCompare) + { + return false; + } + + return getBColor() == pCompare->getBColor() && getValue() == pCompare->getValue(); + } + + ::basegfx::BColor BColorModifier_interpolate::getModifiedColor(const ::basegfx::BColor& aSourceColor) const + { + return interpolate(maBColor, aSourceColor, mfValue); + } } // end of namespace basegfx -////////////////////////////////////////////////////////////////////////////// - namespace basegfx { - BColorModifier_black_and_white::~BColorModifier_black_and_white() - { - } - - bool BColorModifier_black_and_white::operator==(const BColorModifier& rCompare) const - { - const BColorModifier_black_and_white* pCompare = dynamic_cast< const BColorModifier_black_and_white* >(&rCompare); - - if(!pCompare) - { - return false; - } - - return getValue() == pCompare->getValue(); - } - - ::basegfx::BColor BColorModifier_black_and_white::getModifiedColor(const ::basegfx::BColor& aSourceColor) const - { - const double fLuminance(aSourceColor.luminance()); - - if(fLuminance < mfValue) - { - return ::basegfx::BColor::getEmptyBColor(); - } - else - { - return ::basegfx::BColor(1.0, 1.0, 1.0); - } - } + BColorModifier_black_and_white::~BColorModifier_black_and_white() + { + } + + bool BColorModifier_black_and_white::operator==(const BColorModifier& rCompare) const + { + const BColorModifier_black_and_white* pCompare = dynamic_cast< const BColorModifier_black_and_white* >(&rCompare); + + if(!pCompare) + { + return false; + } + + return getValue() == pCompare->getValue(); + } + + ::basegfx::BColor BColorModifier_black_and_white::getModifiedColor(const ::basegfx::BColor& aSourceColor) const + { + const double fLuminance(aSourceColor.luminance()); + + if(fLuminance < mfValue) + { + return ::basegfx::BColor::getEmptyBColor(); + } + else + { + return ::basegfx::BColor(1.0, 1.0, 1.0); + } + } } // end of namespace basegfx -////////////////////////////////////////////////////////////////////////////// - namespace basegfx { - BColorModifier_gamma::BColorModifier_gamma(double fValue) - : BColorModifier(), - mfValue(fValue), - mfInvValue(fValue), - mbUseIt(!basegfx::fTools::equal(fValue, 1.0) && basegfx::fTools::more(fValue, 0.0) && basegfx::fTools::lessOrEqual(fValue, 10.0)) - { - if(mbUseIt) - { - mfInvValue = 1.0 / mfValue; - } - } - - BColorModifier_gamma::~BColorModifier_gamma() - { - } - - bool BColorModifier_gamma::operator==(const BColorModifier& rCompare) const - { - const BColorModifier_gamma* pCompare = dynamic_cast< const BColorModifier_gamma* >(&rCompare); - - if(!pCompare) - { - return false; - } - - // getValue is sufficient, mfInvValue and mbUseIt are only helper values - return getValue() == pCompare->getValue(); - } - - ::basegfx::BColor BColorModifier_gamma::getModifiedColor(const ::basegfx::BColor& aSourceColor) const - { - if(mbUseIt) - { - ::basegfx::BColor aRetval( - pow(aSourceColor.getRed(), mfInvValue), - pow(aSourceColor.getGreen(), mfInvValue), - pow(aSourceColor.getBlue(), mfInvValue)); - - aRetval.clamp(); - return aRetval; - } - else - { - return aSourceColor; - } - } + BColorModifier_gamma::BColorModifier_gamma(double fValue) + : BColorModifier(), + mfValue(fValue), + mfInvValue(fValue), + mbUseIt(!basegfx::fTools::equal(fValue, 1.0) && basegfx::fTools::more(fValue, 0.0) && basegfx::fTools::lessOrEqual(fValue, 10.0)) + { + if(mbUseIt) + { + mfInvValue = 1.0 / mfValue; + } + } + + BColorModifier_gamma::~BColorModifier_gamma() + { + } + + bool BColorModifier_gamma::operator==(const BColorModifier& rCompare) const + { + const BColorModifier_gamma* pCompare = dynamic_cast< const BColorModifier_gamma* >(&rCompare); + + if(!pCompare) + { + return false; + } + + // getValue is sufficient, mfInvValue and mbUseIt are only helper values + return getValue() == pCompare->getValue(); + } + + ::basegfx::BColor BColorModifier_gamma::getModifiedColor(const ::basegfx::BColor& aSourceColor) const + { + if(mbUseIt) + { + ::basegfx::BColor aRetval( + pow(aSourceColor.getRed(), mfInvValue), + pow(aSourceColor.getGreen(), mfInvValue), + pow(aSourceColor.getBlue(), mfInvValue)); + + aRetval.clamp(); + return aRetval; + } + else + { + return aSourceColor; + } + } } // end of namespace basegfx -////////////////////////////////////////////////////////////////////////////// - namespace basegfx { - BColorModifier_RGBLuminanceContrast::BColorModifier_RGBLuminanceContrast(double fRed, double fGreen, double fBlue, double fLuminance, double fContrast) - : BColorModifier(), - mfRed(basegfx::clamp(fRed, -1.0, 1.0)), - mfGreen(basegfx::clamp(fGreen, -1.0, 1.0)), - mfBlue(basegfx::clamp(fBlue, -1.0, 1.0)), - mfLuminance(basegfx::clamp(fLuminance, -1.0, 1.0)), - mfContrast(basegfx::clamp(fContrast, -1.0, 1.0)), - mfContrastOff(1.0), - mfRedOff(0.0), - mfGreenOff(0.0), - mfBlueOff(0.0), - mbUseIt(false) - { - if(!basegfx::fTools::equalZero(mfRed) - || !basegfx::fTools::equalZero(mfGreen) - || !basegfx::fTools::equalZero(mfBlue) - || !basegfx::fTools::equalZero(mfLuminance) - || !basegfx::fTools::equalZero(mfContrast)) - { - // calculate slope - if(mfContrast >= 0.0) - { - mfContrastOff = 128.0 / (128.0 - (mfContrast * 127.0)); - } - else - { - mfContrastOff = ( 128.0 + (mfContrast * 127.0)) / 128.0; - } - - // calculate unified contrast offset - const double fPreparedContrastOff((128.0 - mfContrastOff * 128.0) / 255.0); - const double fCombinedOffset(mfLuminance + fPreparedContrastOff); - - // set full offsets - mfRedOff = mfRed + fCombinedOffset; - mfGreenOff = mfGreen + fCombinedOffset; - mfBlueOff = mfBlue + fCombinedOffset; - - mbUseIt = true; - } - } - - BColorModifier_RGBLuminanceContrast::~BColorModifier_RGBLuminanceContrast() - { - } - - bool BColorModifier_RGBLuminanceContrast::operator==(const BColorModifier& rCompare) const - { - const BColorModifier_RGBLuminanceContrast* pCompare = dynamic_cast< const BColorModifier_RGBLuminanceContrast* >(&rCompare); - - if(!pCompare) - { - return false; - } - - // no need to compare other values, these are just helpers - return getRed() == pCompare->getRed() - && getGreen() == pCompare->getGreen() - && getBlue() == pCompare->getBlue() - && getLuminance() == pCompare->getLuminance() - && getContrast() == pCompare->getContrast(); - } - - ::basegfx::BColor BColorModifier_RGBLuminanceContrast::getModifiedColor(const ::basegfx::BColor& aSourceColor) const - { - if(mbUseIt) - { - return basegfx::BColor( - basegfx::clamp(aSourceColor.getRed() * mfContrastOff + mfRedOff, 0.0, 1.0), - basegfx::clamp(aSourceColor.getGreen() * mfContrastOff + mfGreenOff, 0.0, 1.0), - basegfx::clamp(aSourceColor.getBlue() * mfContrastOff + mfBlueOff, 0.0, 1.0)); - } - else - { - return aSourceColor; - } - } + BColorModifier_RGBLuminanceContrast::BColorModifier_RGBLuminanceContrast(double fRed, double fGreen, double fBlue, double fLuminance, double fContrast) + : BColorModifier(), + mfRed(basegfx::clamp(fRed, -1.0, 1.0)), + mfGreen(basegfx::clamp(fGreen, -1.0, 1.0)), + mfBlue(basegfx::clamp(fBlue, -1.0, 1.0)), + mfLuminance(basegfx::clamp(fLuminance, -1.0, 1.0)), + mfContrast(basegfx::clamp(fContrast, -1.0, 1.0)), + mfContrastOff(1.0), + mfRedOff(0.0), + mfGreenOff(0.0), + mfBlueOff(0.0), + mbUseIt(false) + { + if(!basegfx::fTools::equalZero(mfRed) + || !basegfx::fTools::equalZero(mfGreen) + || !basegfx::fTools::equalZero(mfBlue) + || !basegfx::fTools::equalZero(mfLuminance) + || !basegfx::fTools::equalZero(mfContrast)) + { + // calculate slope + if(mfContrast >= 0.0) + { + mfContrastOff = 128.0 / (128.0 - (mfContrast * 127.0)); + } + else + { + mfContrastOff = ( 128.0 + (mfContrast * 127.0)) / 128.0; + } + + // calculate unified contrast offset + const double fPreparedContrastOff((128.0 - mfContrastOff * 128.0) / 255.0); + const double fCombinedOffset(mfLuminance + fPreparedContrastOff); + + // set full offsets + mfRedOff = mfRed + fCombinedOffset; + mfGreenOff = mfGreen + fCombinedOffset; + mfBlueOff = mfBlue + fCombinedOffset; + + mbUseIt = true; + } + } + + BColorModifier_RGBLuminanceContrast::~BColorModifier_RGBLuminanceContrast() + { + } + + bool BColorModifier_RGBLuminanceContrast::operator==(const BColorModifier& rCompare) const + { + const BColorModifier_RGBLuminanceContrast* pCompare = dynamic_cast< const BColorModifier_RGBLuminanceContrast* >(&rCompare); + + if(!pCompare) + { + return false; + } + + // no need to compare other values, these are just helpers + return getRed() == pCompare->getRed() + && getGreen() == pCompare->getGreen() + && getBlue() == pCompare->getBlue() + && getLuminance() == pCompare->getLuminance() + && getContrast() == pCompare->getContrast(); + } + + ::basegfx::BColor BColorModifier_RGBLuminanceContrast::getModifiedColor(const ::basegfx::BColor& aSourceColor) const + { + if(mbUseIt) + { + return basegfx::BColor( + basegfx::clamp(aSourceColor.getRed() * mfContrastOff + mfRedOff, 0.0, 1.0), + basegfx::clamp(aSourceColor.getGreen() * mfContrastOff + mfGreenOff, 0.0, 1.0), + basegfx::clamp(aSourceColor.getBlue() * mfContrastOff + mfBlueOff, 0.0, 1.0)); + } + else + { + return aSourceColor; + } + } } // end of namespace basegfx -////////////////////////////////////////////////////////////////////////////// - namespace basegfx { - ::basegfx::BColor BColorModifierStack::getModifiedColor(const ::basegfx::BColor& rSource) const - { - if(maBColorModifiers.empty()) - { - return rSource; - } - - ::basegfx::BColor aRetval(rSource); - - for(sal_uInt32 a(maBColorModifiers.size()); a;) - { - a--; - aRetval = maBColorModifiers[a]->getModifiedColor(aRetval); - } - - return aRetval; - } + ::basegfx::BColor BColorModifierStack::getModifiedColor(const ::basegfx::BColor& rSource) const + { + if(maBColorModifiers.empty()) + { + return rSource; + } + + ::basegfx::BColor aRetval(rSource); + + for(sal_uInt32 a(maBColorModifiers.size()); a;) + { + a--; + aRetval = maBColorModifiers[a]->getModifiedColor(aRetval); + } + + return aRetval; + } } // end of namespace basegfx -////////////////////////////////////////////////////////////////////////////// -// eof +/* vim: set noet sw=4 ts=4: */ diff --git a/main/basegfx/source/color/bcolortools.cxx b/main/basegfx/source/color/bcolortools.cxx index fa7596e6cc..ac32995d04 100644 --- a/main/basegfx/source/color/bcolortools.cxx +++ b/main/basegfx/source/color/bcolortools.cxx @@ -1,5 +1,5 @@ /************************************************************** - * + * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information @@ -7,20 +7,18 @@ * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. - * + * *************************************************************/ - - // MARKER(update_precomp.py): autogen include statement, do not remove #include "precompiled_basegfx.hxx" @@ -28,237 +26,234 @@ #include <basegfx/color/bcolor.hxx> #include <basegfx/color/bcolortools.hxx> -////////////////////////////////////////////////////////////////////////////// - namespace basegfx { namespace tools { - BColor rgb2hsl(const BColor& rRGBColor) - { - const double r=rRGBColor.getRed(), g=rRGBColor.getGreen(), b=rRGBColor.getBlue(); - const double minVal = ::std::min( ::std::min( r, g ), b ); - const double maxVal = ::std::max( ::std::max( r, g ), b ); - const double d = maxVal - minVal; - - double h=0, s=0, l=0; - - l = (maxVal + minVal) / 2.0; - - if( ::basegfx::fTools::equalZero(d) ) - { - s = h = 0; // hue undefined (achromatic case) - } - else - { - s = l > 0.5 ? d/(2.0-maxVal-minVal) : - d/(maxVal + minVal); - - if( r == maxVal ) - h = (g - b)/d; - else if( g == maxVal ) - h = 2.0 + (b - r)/d; - else - h = 4.0 + (r - g)/d; - - h *= 60.0; - - if( h < 0.0 ) - h += 360.0; - } - - return BColor(h,s,l); - } - - static inline double hsl2rgbHelper( double nValue1, double nValue2, double nHue ) - { - // clamp hue to [0,360] - nHue = fmod( nHue, 360.0 ); - - // cope with wrap-arounds - if( nHue < 0.0 ) - nHue += 360.0; - - if( nHue < 60.0 ) - return nValue1 + (nValue2 - nValue1)*nHue/60.0; - else if( nHue < 180.0 ) - return nValue2; - else if( nHue < 240.0 ) - return nValue1 + (nValue2 - nValue1)*(240.0 - nHue)/60.0; - else - return nValue1; - } - - BColor hsl2rgb(const BColor& rHSLColor) - { - const double h=rHSLColor.getRed(), s=rHSLColor.getGreen(), l=rHSLColor.getBlue(); - - if( fTools::equalZero(s) ) - return BColor(l, l, l ); // achromatic case - - const double nVal1( l <= 0.5 ? l*(1.0 + s) : l + s - l*s ); - const double nVal2( 2.0*l - nVal1 ); - - return BColor( - hsl2rgbHelper(nVal2, - nVal1, - h + 120.0), - hsl2rgbHelper(nVal2, - nVal1, - h), - hsl2rgbHelper(nVal2, - nVal1, - h - 120.0) ); - } - - BColor rgb2hsv(const BColor& rRGBColor) - { - const double r=rRGBColor.getRed(), g=rRGBColor.getGreen(), b=rRGBColor.getBlue(); - const double maxVal = std::max(std::max(r,g),b); - const double minVal = std::min(std::min(r,g),b); - const double delta = maxVal-minVal; - - double h=0, s=0, v=0; - - v = maxVal; - if( fTools::equalZero(v) ) - s = 0; - else - s = delta / v; - - if( !fTools::equalZero(s) ) - { - if( maxVal == r ) - { - h = (g - b) / delta; - } - else if( maxVal == g ) - { - h = 2.0 + (b - r) / delta; - } - else - { - h = 4.0 + (r - g) / delta; - } - - h *= 60.0; - - if( h < 0 ) - h += 360; - } - - return BColor(h,s,v); - } - - BColor hsv2rgb(const BColor& rHSVColor) - { - double h=rHSVColor.getRed(); - const double s=rHSVColor.getGreen(), v=rHSVColor.getBlue(); - - if( fTools::equalZero(s) ) - { - // achromatic case: no hue. - return BColor(v,v,v); - } - else - { - if( fTools::equal(h,360) ) - h = 0; // 360 degrees is equivalent to 0 degrees - - h /= 60.0; + BColor rgb2hsl(const BColor& rRGBColor) + { + const double r=rRGBColor.getRed(), g=rRGBColor.getGreen(), b=rRGBColor.getBlue(); + const double minVal = ::std::min( ::std::min( r, g ), b ); + const double maxVal = ::std::max( ::std::max( r, g ), b ); + const double d = maxVal - minVal; + + double h=0, s=0, l=0; + + l = (maxVal + minVal) / 2.0; + + if( ::basegfx::fTools::equalZero(d) ) + { + s = h = 0; // hue undefined (achromatic case) + } + else + { + s = l > 0.5 ? d/(2.0-maxVal-minVal) : + d/(maxVal + minVal); + + if( r == maxVal ) + h = (g - b)/d; + else if( g == maxVal ) + h = 2.0 + (b - r)/d; + else + h = 4.0 + (r - g)/d; + + h *= 60.0; + + if( h < 0.0 ) + h += 360.0; + } + + return BColor(h,s,l); + } + + static inline double hsl2rgbHelper( double nValue1, double nValue2, double nHue ) + { + // clamp hue to [0,360] + nHue = fmod( nHue, 360.0 ); + + // cope with wrap-arounds + if( nHue < 0.0 ) + nHue += 360.0; + + if( nHue < 60.0 ) + return nValue1 + (nValue2 - nValue1)*nHue/60.0; + else if( nHue < 180.0 ) + return nValue2; + else if( nHue < 240.0 ) + return nValue1 + (nValue2 - nValue1)*(240.0 - nHue)/60.0; + else + return nValue1; + } + + BColor hsl2rgb(const BColor& rHSLColor) + { + const double h=rHSLColor.getRed(), s=rHSLColor.getGreen(), l=rHSLColor.getBlue(); + + if( fTools::equalZero(s) ) + return BColor(l, l, l ); // achromatic case + + const double nVal1( l <= 0.5 ? l*(1.0 + s) : l + s - l*s ); + const double nVal2( 2.0*l - nVal1 ); + + return BColor( + hsl2rgbHelper(nVal2, + nVal1, + h + 120.0), + hsl2rgbHelper(nVal2, + nVal1, + h), + hsl2rgbHelper(nVal2, + nVal1, + h - 120.0) ); + } + + BColor rgb2hsv(const BColor& rRGBColor) + { + const double r=rRGBColor.getRed(), g=rRGBColor.getGreen(), b=rRGBColor.getBlue(); + const double maxVal = std::max(std::max(r,g),b); + const double minVal = std::min(std::min(r,g),b); + const double delta = maxVal-minVal; + + double h=0, s=0, v=0; + + v = maxVal; + if( fTools::equalZero(v) ) + s = 0; + else + s = delta / v; + + if( !fTools::equalZero(s) ) + { + if( maxVal == r ) + { + h = (g - b) / delta; + } + else if( maxVal == g ) + { + h = 2.0 + (b - r) / delta; + } + else + { + h = 4.0 + (r - g) / delta; + } + + h *= 60.0; + + if( h < 0 ) + h += 360; + } + + return BColor(h,s,v); + } + + BColor hsv2rgb(const BColor& rHSVColor) + { + double h=rHSVColor.getRed(); + const double s=rHSVColor.getGreen(), v=rHSVColor.getBlue(); + + if( fTools::equalZero(s) ) + { + // achromatic case: no hue. + return BColor(v,v,v); + } + else + { + if( fTools::equal(h,360) ) + h = 0; // 360 degrees is equivalent to 0 degrees + + h /= 60.0; const sal_Int32 intval = static_cast< sal_Int32 >( h ); - const double f = h - intval; - const double p = v*(1.0-s); - const double q = v*(1.0-(s*f)); - const double t = v*(1.0-(s*(1.0-f))); - - /* which hue area? */ - switch( intval ) - { - case 0: - return BColor(v,t,p); - - case 1: - return BColor(q,v,p); - - case 2: - return BColor(p,v,t); - - case 3: - return BColor(p,q,v); - - case 4: - return BColor(t,p,v); - - case 5: - return BColor(v,p,q); - - default: - // hue overflow - return BColor(); - } - } - } - - BColor rgb2yiq(const BColor& rRGBColor) - { - // from Foley, van Dam, Computer Graphics - const double r=rRGBColor.getRed(), g=rRGBColor.getGreen(), b=rRGBColor.getBlue(); - return BColor( - 0.299*r + 0.587*g + 0.114*b, - 0.596*r - 0.274*g - 0.322*b, - 0.211*r - 0.522*g + 0.311*b); - } - - BColor yiq2rgb(const BColor& rYIQColor) - { - // from Foley, van Dam, Computer Graphics - const double y=rYIQColor.getRed(), i=rYIQColor.getGreen(), q=rYIQColor.getBlue(); - return BColor( - y + 0.956*i + 0.623*q, - y - 0.272*i - 0.648*q, - y - 1.105*i + 1.705*q ); - } - - BColor ciexyz2rgb( const BColor& rXYZColor ) - { - // from Poynton color faq, and SMPTE RP 177-1993, Derivation - // of Basic Television Color Equations - const double x=rXYZColor.getRed(), y=rXYZColor.getGreen(), z=rXYZColor.getBlue(); - return BColor( - 3.240479*x - 1.53715*y - 0.498535*z, - -0.969256*x + 1.875991*y + 0.041556*z, - 0.055648*x - 0.204043*y + 1.057311*z ); - } - - BColor rgb2ciexyz( const BColor& rRGBColor ) - { - // from Poynton color faq, and SMPTE RP 177-1993, Derivation - // of Basic Television Color Equations - const double r=rRGBColor.getRed(), g=rRGBColor.getGreen(), b=rRGBColor.getBlue(); - return BColor( - 0.412453*r + 0.35758*g + 0.180423*b, - 0.212671*r + 0.71516*g + 0.072169*b, - 0.019334*r + 0.119193*g + 0.950227*b); - } - - BColor rgb2ypbpr(const BColor& rRGBColor) - { - const double r=rRGBColor.getRed(), g=rRGBColor.getGreen(), b=rRGBColor.getBlue(); - return BColor( - 0.299*r + 0.587*g + 0.114*b, - -0.168736*r - 0.331264*g + 0.5*b, - 0.5*r - 0.418688*g - 0.081312*b); - } - - BColor ypbpr2rgb(const BColor& rYPbPrColor) - { - const double y=rYPbPrColor.getRed(), pb=rYPbPrColor.getGreen(), pr=rYPbPrColor.getBlue(); - return BColor( - 1.*y + 0.*pb + 1.402*pr, - 1.*y - 0.344136*pb - 0.714136*pr, - 1.*y + 1.772*pb + 0.*pr); - } + const double f = h - intval; + const double p = v*(1.0-s); + const double q = v*(1.0-(s*f)); + const double t = v*(1.0-(s*(1.0-f))); + + /* which hue area? */ + switch( intval ) + { + case 0: + return BColor(v,t,p); + + case 1: + return BColor(q,v,p); + + case 2: + return BColor(p,v,t); + + case 3: + return BColor(p,q,v); + + case 4: + return BColor(t,p,v); + + case 5: + return BColor(v,p,q); + + default: + // hue overflow + return BColor(); + } + } + } + + BColor rgb2yiq(const BColor& rRGBColor) + { + // from Foley, van Dam, Computer Graphics + const double r=rRGBColor.getRed(), g=rRGBColor.getGreen(), b=rRGBColor.getBlue(); + return BColor( + 0.299*r + 0.587*g + 0.114*b, + 0.596*r - 0.274*g - 0.322*b, + 0.211*r - 0.522*g + 0.311*b); + } + + BColor yiq2rgb(const BColor& rYIQColor) + { + // from Foley, van Dam, Computer Graphics + const double y=rYIQColor.getRed(), i=rYIQColor.getGreen(), q=rYIQColor.getBlue(); + return BColor( + y + 0.956*i + 0.623*q, + y - 0.272*i - 0.648*q, + y - 1.105*i + 1.705*q ); + } + + BColor ciexyz2rgb( const BColor& rXYZColor ) + { + // from Poynton color faq, and SMPTE RP 177-1993, Derivation + // of Basic Television Color Equations + const double x=rXYZColor.getRed(), y=rXYZColor.getGreen(), z=rXYZColor.getBlue(); + return BColor( + 3.240479*x - 1.53715*y - 0.498535*z, + -0.969256*x + 1.875991*y + 0.041556*z, + 0.055648*x - 0.204043*y + 1.057311*z ); + } + + BColor rgb2ciexyz( const BColor& rRGBColor ) + { + // from Poynton color faq, and SMPTE RP 177-1993, Derivation + // of Basic Television Color Equations + const double r=rRGBColor.getRed(), g=rRGBColor.getGreen(), b=rRGBColor.getBlue(); + return BColor( + 0.412453*r + 0.35758*g + 0.180423*b, + 0.212671*r + 0.71516*g + 0.072169*b, + 0.019334*r + 0.119193*g + 0.950227*b); + } + + BColor rgb2ypbpr(const BColor& rRGBColor) + { + const double r=rRGBColor.getRed(), g=rRGBColor.getGreen(), b=rRGBColor.getBlue(); + return BColor( + 0.299*r + 0.587*g + 0.114*b, + -0.168736*r - 0.331264*g + 0.5*b, + 0.5*r - 0.418688*g - 0.081312*b); + } + + BColor ypbpr2rgb(const BColor& rYPbPrColor) + { + const double y=rYPbPrColor.getRed(), pb=rYPbPrColor.getGreen(), pr=rYPbPrColor.getBlue(); + return BColor( + 1.*y + 0.*pb + 1.402*pr, + 1.*y - 0.344136*pb - 0.714136*pr, + 1.*y + 1.772*pb + 0.*pr); + } } } // end of namespace basegfx -////////////////////////////////////////////////////////////////////////////// -// eof +/* vim: set noet sw=4 ts=4: */ diff --git a/main/basegfx/source/curve/b2dbeziertools.cxx b/main/basegfx/source/curve/b2dbeziertools.cxx index d0d2e3633d..d558a01fb6 100644 --- a/main/basegfx/source/curve/b2dbeziertools.cxx +++ b/main/basegfx/source/curve/b2dbeziertools.cxx @@ -1,5 +1,5 @@ /************************************************************** - * + * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information @@ -7,28 +7,24 @@ * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. - * + * *************************************************************/ - - // MARKER(update_precomp.py): autogen include statement, do not remove #include "precompiled_basegfx.hxx" #include <basegfx/curve/b2dbeziertools.hxx> #include <basegfx/curve/b2dcubicbezier.hxx> #include <algorithm> -////////////////////////////////////////////////////////////////////////////// - namespace basegfx { B2DCubicBezierHelper::B2DCubicBezierHelper(const B2DCubicBezier& rBase, sal_uInt32 nDivisions) @@ -110,12 +106,12 @@ namespace basegfx // not a bezier, linear edge return fDistance / fLength; } - + // it is a bezier ::std::vector< double >::const_iterator aIter = ::std::lower_bound(maLengthArray.begin(), maLengthArray.end(), fDistance); const sal_uInt32 nIndex(aIter - maLengthArray.begin()); const double fHighBound(maLengthArray[nIndex]); - const double fLowBound(nIndex ? maLengthArray[nIndex - 1] : 0.0); + const double fLowBound(nIndex ? maLengthArray[nIndex - 1] : 0.0); const double fLinearInterpolatedLength((fDistance - fLowBound) / (fHighBound - fLowBound)); return (static_cast< double >(nIndex) + fLinearInterpolatedLength) / static_cast< double >(mnEdgeCount); @@ -154,6 +150,4 @@ namespace basegfx } } // end of namespace basegfx -////////////////////////////////////////////////////////////////////////////// - -// eof +/* vim: set noet sw=4 ts=4: */ diff --git a/main/basegfx/source/curve/b2dcubicbezier.cxx b/main/basegfx/source/curve/b2dcubicbezier.cxx index 48637080f0..2020fdc5e7 100644 --- a/main/basegfx/source/curve/b2dcubicbezier.cxx +++ b/main/basegfx/source/curve/b2dcubicbezier.cxx @@ -1,5 +1,5 @@ /************************************************************** - * + * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information @@ -7,20 +7,18 @@ * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. - * + * *************************************************************/ - - // MARKER(update_precomp.py): autogen include statement, do not remove #include "precompiled_basegfx.hxx" #include <basegfx/curve/b2dcubicbezier.hxx> @@ -30,14 +28,12 @@ #include <limits> -// #i37443# +// #i37443# #define FACTOR_FOR_UNSHARPEN (1.6) #ifdef DBG_UTIL static double fMultFactUnsharpen = FACTOR_FOR_UNSHARPEN; #endif -////////////////////////////////////////////////////////////////////////////// - namespace basegfx { namespace @@ -57,7 +53,7 @@ namespace basegfx // do angle test B2DVector aLeft(rfEA - rfPA); B2DVector aRight(rfEB - rfPB); - + // #i72104# if(aLeft.equalZero()) { @@ -149,7 +145,7 @@ namespace basegfx if(!bLeftEqualZero) { double fFactor; - + if(fabs(aBase.getX()) > fabs(aBase.getY())) { fFactor = aLeft.getX() / aBase.getX(); @@ -168,7 +164,7 @@ namespace basegfx if(!bRightEqualZero) { double fFactor; - + if(fabs(aBase.getX()) > fabs(aBase.getY())) { fFactor = aRight.getX() / -aBase.getX(); @@ -329,8 +325,6 @@ namespace basegfx } // end of anonymous namespace } // end of namespace basegfx -////////////////////////////////////////////////////////////////////////////// - namespace basegfx { B2DCubicBezier::B2DCubicBezier(const B2DCubicBezier& rBezier) @@ -340,11 +334,11 @@ namespace basegfx maControlPointB(rBezier.maControlPointB) { } - + B2DCubicBezier::B2DCubicBezier() { } - + B2DCubicBezier::B2DCubicBezier(const B2DPoint& rStart, const B2DPoint& rEnd) : maStartPoint(rStart), maEndPoint(rEnd), @@ -372,7 +366,7 @@ namespace basegfx maEndPoint = rBezier.maEndPoint; maControlPointA = rBezier.maControlPointA; maControlPointB = rBezier.maControlPointB; - + return *this; } @@ -397,15 +391,15 @@ namespace basegfx ); } - bool B2DCubicBezier::equal(const B2DCubicBezier& rBezier) const - { + bool B2DCubicBezier::equal(const B2DCubicBezier& rBezier) const + { return ( maStartPoint.equal(rBezier.maStartPoint) && maEndPoint.equal(rBezier.maEndPoint) && maControlPointA.equal(rBezier.maControlPointA) && maControlPointB.equal(rBezier.maControlPointB) ); - } + } // test if vectors are used bool B2DCubicBezier::isBezier() const @@ -423,28 +417,28 @@ namespace basegfx if(maControlPointA != maStartPoint || maControlPointB != maEndPoint) { const B2DVector aEdge(maEndPoint - maStartPoint); - - // controls parallel to edge can be trivial. No edge -> not parallel -> control can - // still not be trivial (e.g. ballon loop) + + // controls parallel to edge can be trivial. No edge -> not parallel -> control can + // still not be trivial (e.g. balloon loop) if(!aEdge.equalZero()) { - // get control vectors + // get control vectors const B2DVector aVecA(maControlPointA - maStartPoint); const B2DVector aVecB(maControlPointB - maEndPoint); - // check if trivial per se - bool bAIsTrivial(aVecA.equalZero()); - bool bBIsTrivial(aVecB.equalZero()); + // check if trivial per se + bool bAIsTrivial(aVecA.equalZero()); + bool bBIsTrivial(aVecB.equalZero()); - // #i102241# prepare inverse edge length to normalize cross values; - // else the small compare value used in fTools::equalZero - // will be length dependent and this detection will work as less - // precise as longer the edge is. In principle, the length of the control + // #i102241# prepare inverse edge length to normalize cross values; + // else the small compare value used in fTools::equalZero + // will be length dependent and this detection will work as less + // precise as longer the edge is. In principle, the length of the control // vector would need to be used too, but to be trivial it is assumed to // be of roughly equal length to the edge, so edge length can be used // for both. Only needed when one of both is not trivial per se. - const double fInverseEdgeLength(bAIsTrivial && bBIsTrivial - ? 1.0 + const double fInverseEdgeLength(bAIsTrivial && bBIsTrivial + ? 1.0 : 1.0 / aEdge.getLength()); // if A is not zero, check if it could be @@ -457,8 +451,8 @@ namespace basegfx if(fTools::equalZero(fCross)) { // get scale to edge. Use bigger distance for numeric quality - const double fScale(fabs(aEdge.getX()) > fabs(aEdge.getY()) - ? aVecA.getX() / aEdge.getX() + const double fScale(fabs(aEdge.getX()) > fabs(aEdge.getY()) + ? aVecA.getX() / aEdge.getX() : aVecA.getY() / aEdge.getY()); // relative end point of vector in edge range? @@ -469,18 +463,18 @@ namespace basegfx } } - // if B is not zero, check if it could be, but only if A is already trivial; - // else solve to trivial will not be possible for whole edge + // if B is not zero, check if it could be, but only if A is already trivial; + // else solve to trivial will not be possible for whole edge if(bAIsTrivial && !bBIsTrivial) { // parallel to edge? Check aVecB, aEdge const double fCross(aVecB.cross(aEdge) * fInverseEdgeLength); - + if(fTools::equalZero(fCross)) { // get scale to edge. Use bigger distance for numeric quality - const double fScale(fabs(aEdge.getX()) > fabs(aEdge.getY()) - ? aVecB.getX() / aEdge.getX() + const double fScale(fabs(aEdge.getX()) > fabs(aEdge.getY()) + ? aVecB.getX() / aEdge.getX() : aVecB.getY() / aEdge.getY()); // end point of vector in edge range? Caution: controlB is directed AGAINST edge @@ -491,7 +485,7 @@ namespace basegfx } } - // if both are/can be reduced, do it. + // if both are/can be reduced, do it. // Not possible if only one is/can be reduced (!) if(bAIsTrivial && bBIsTrivial) { @@ -502,47 +496,47 @@ namespace basegfx } } - namespace { - double impGetLength(const B2DCubicBezier& rEdge, double fDeviation, sal_uInt32 nRecursionWatch) - { - const double fEdgeLength(rEdge.getEdgeLength()); - const double fControlPolygonLength(rEdge.getControlPolygonLength()); - const double fCurrentDeviation(fTools::equalZero(fControlPolygonLength) ? 0.0 : 1.0 - (fEdgeLength / fControlPolygonLength)); - - if(!nRecursionWatch || fTools:: lessOrEqual(fCurrentDeviation, fDeviation)) - { - return (fEdgeLength + fControlPolygonLength) * 0.5; - } - else - { - B2DCubicBezier aLeft, aRight; - const double fNewDeviation(fDeviation * 0.5); - const sal_uInt32 nNewRecursionWatch(nRecursionWatch - 1); - - rEdge.split(0.5, &aLeft, &aRight); - - return impGetLength(aLeft, fNewDeviation, nNewRecursionWatch) - + impGetLength(aRight, fNewDeviation, nNewRecursionWatch); - } - } - } + namespace { + double impGetLength(const B2DCubicBezier& rEdge, double fDeviation, sal_uInt32 nRecursionWatch) + { + const double fEdgeLength(rEdge.getEdgeLength()); + const double fControlPolygonLength(rEdge.getControlPolygonLength()); + const double fCurrentDeviation(fTools::equalZero(fControlPolygonLength) ? 0.0 : 1.0 - (fEdgeLength / fControlPolygonLength)); + + if(!nRecursionWatch || fTools:: lessOrEqual(fCurrentDeviation, fDeviation)) + { + return (fEdgeLength + fControlPolygonLength) * 0.5; + } + else + { + B2DCubicBezier aLeft, aRight; + const double fNewDeviation(fDeviation * 0.5); + const sal_uInt32 nNewRecursionWatch(nRecursionWatch - 1); + + rEdge.split(0.5, &aLeft, &aRight); + + return impGetLength(aLeft, fNewDeviation, nNewRecursionWatch) + + impGetLength(aRight, fNewDeviation, nNewRecursionWatch); + } + } + } double B2DCubicBezier::getLength(double fDeviation) const - { - if(isBezier()) - { - if(fDeviation < 0.00000001) - { - fDeviation = 0.00000001; - } - - return impGetLength(*this, fDeviation, 6); - } - else - { - return B2DVector(getEndPoint() - getStartPoint()).getLength(); - } - } + { + if(isBezier()) + { + if(fDeviation < 0.00000001) + { + fDeviation = 0.00000001; + } + + return impGetLength(*this, fDeviation, 6); + } + else + { + return B2DVector(getEndPoint() - getStartPoint()).getLength(); + } + } double B2DCubicBezier::getEdgeLength() const { @@ -579,61 +573,61 @@ namespace basegfx } } - B2DVector B2DCubicBezier::getTangent(double t) const - { - if(fTools::lessOrEqual(t, 0.0)) - { - // tangent in start point - B2DVector aTangent(getControlPointA() - getStartPoint()); - - if(!aTangent.equalZero()) - { - return aTangent; - } - - // start point and control vector are the same, fallback - // to implicit start vector to control point B - aTangent = (getControlPointB() - getStartPoint()) * 0.3; - - if(!aTangent.equalZero()) - { - return aTangent; - } - - // not a bezier at all, return edge vector - return (getEndPoint() - getStartPoint()) * 0.3; - } - else if(fTools::moreOrEqual(t, 1.0)) - { - // tangent in end point - B2DVector aTangent(getEndPoint() - getControlPointB()); - - if(!aTangent.equalZero()) - { - return aTangent; - } - - // end point and control vector are the same, fallback - // to implicit start vector from control point A - aTangent = (getEndPoint() - getControlPointA()) * 0.3; - - if(!aTangent.equalZero()) - { - return aTangent; - } - - // not a bezier at all, return edge vector - return (getEndPoint() - getStartPoint()) * 0.3; - } - else - { - // t is in ]0.0 .. 1.0[. Split and extract - B2DCubicBezier aRight; - split(t, 0, &aRight); - - return aRight.getControlPointA() - aRight.getStartPoint(); - } - } + B2DVector B2DCubicBezier::getTangent(double t) const + { + if(fTools::lessOrEqual(t, 0.0)) + { + // tangent in start point + B2DVector aTangent(getControlPointA() - getStartPoint()); + + if(!aTangent.equalZero()) + { + return aTangent; + } + + // start point and control vector are the same, fallback + // to implicit start vector to control point B + aTangent = (getControlPointB() - getStartPoint()) * 0.3; + + if(!aTangent.equalZero()) + { + return aTangent; + } + + // not a bezier at all, return edge vector + return (getEndPoint() - getStartPoint()) * 0.3; + } + else if(fTools::moreOrEqual(t, 1.0)) + { + // tangent in end point + B2DVector aTangent(getEndPoint() - getControlPointB()); + + if(!aTangent.equalZero()) + { + return aTangent; + } + + // end point and control vector are the same, fallback + // to implicit start vector from control point A + aTangent = (getEndPoint() - getControlPointA()) * 0.3; + + if(!aTangent.equalZero()) + { + return aTangent; + } + + // not a bezier at all, return edge vector + return (getEndPoint() - getStartPoint()) * 0.3; + } + else + { + // t is in ]0.0 .. 1.0[. Split and extract + B2DCubicBezier aRight; + split(t, 0, &aRight); + + return aRight.getControlPointA() - aRight.getStartPoint(); + } + } // #i37443# adaptive subdivide by nCount subdivisions void B2DCubicBezier::adaptiveSubdivideByCount(B2DPolygon& rTarget, sal_uInt32 nCount) const @@ -654,7 +648,7 @@ namespace basegfx { if(isBezier()) { - ImpSubDivDistance(maStartPoint, maControlPointA, maControlPointB, maEndPoint, rTarget, + ImpSubDivDistance(maStartPoint, maControlPointA, maControlPointB, maEndPoint, rTarget, fDistanceBound * fDistanceBound, ::std::numeric_limits<double>::max(), 30); } else @@ -674,7 +668,7 @@ namespace basegfx const B2DPoint aS1R(interpolate(maControlPointB, maEndPoint, t)); const B2DPoint aS2L(interpolate(aS1L, aS1C, t)); const B2DPoint aS2R(interpolate(aS1C, aS1R, t)); - + return interpolate(aS2L, aS2R, t); } else @@ -846,7 +840,7 @@ namespace basegfx B2DCubicBezier B2DCubicBezier::snippet(double fStart, double fEnd) const { B2DCubicBezier aRetval; - + if(fTools::more(fStart, 1.0)) { fStart = 1.0; @@ -954,15 +948,15 @@ namespace basegfx { inline void impCheckExtremumResult(double fCandidate, ::std::vector< double >& rResult) { - // check for range ]0.0 .. 1.0[ with excluding 1.0 and 0.0 clearly - // by using the equalZero test, NOT ::more or ::less which will use the - // ApproxEqual() which is too exact here - if(fCandidate > 0.0 && !fTools::equalZero(fCandidate)) - { - if(fCandidate < 1.0 && !fTools::equalZero(fCandidate - 1.0)) - { - rResult.push_back(fCandidate); - } + // check for range ]0.0 .. 1.0[ with excluding 1.0 and 0.0 clearly + // by using the equalZero test, NOT ::more or ::less which will use the + // ApproxEqual() which is too exact here + if(fCandidate > 0.0 && !fTools::equalZero(fCandidate)) + { + if(fCandidate < 1.0 && !fTools::equalZero(fCandidate - 1.0)) + { + rResult.push_back(fCandidate); + } } } } @@ -1098,4 +1092,4 @@ namespace basegfx } // end of namespace basegfx -// eof +/* vim: set noet sw=4 ts=4: */ diff --git a/main/basegfx/source/curve/b2dquadraticbezier.cxx b/main/basegfx/source/curve/b2dquadraticbezier.cxx index bc2b95f26f..30f5f93aef 100644 --- a/main/basegfx/source/curve/b2dquadraticbezier.cxx +++ b/main/basegfx/source/curve/b2dquadraticbezier.cxx @@ -1,5 +1,5 @@ /************************************************************** - * + * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information @@ -7,27 +7,23 @@ * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. - * + * *************************************************************/ - - // MARKER(update_precomp.py): autogen include statement, do not remove #include "precompiled_basegfx.hxx" #include <basegfx/curve/b2dquadraticbezier.hxx> #include <basegfx/numeric/ftools.hxx> -////////////////////////////////////////////////////////////////////////////// - namespace basegfx { B2DQuadraticBezier::B2DQuadraticBezier(const B2DQuadraticBezier& rBezier) @@ -36,11 +32,11 @@ namespace basegfx maControlPoint(rBezier.maControlPoint) { } - + B2DQuadraticBezier::B2DQuadraticBezier() { } - + B2DQuadraticBezier::B2DQuadraticBezier(const ::basegfx::B2DPoint& rStart, const ::basegfx::B2DPoint& rEnd) : maStartPoint(rStart), maEndPoint(rEnd) @@ -64,7 +60,7 @@ namespace basegfx maStartPoint = rBezier.maStartPoint; maEndPoint = rBezier.maEndPoint; maControlPoint = rBezier.maControlPoint; - + return *this; } @@ -98,4 +94,4 @@ namespace basegfx } } // end of namespace basegfx -// eof +/* vim: set noet sw=4 ts=4: */