1*09dbbe93SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*09dbbe93SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*09dbbe93SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*09dbbe93SAndrew Rist * distributed with this work for additional information 6*09dbbe93SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*09dbbe93SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*09dbbe93SAndrew Rist * "License"); you may not use this file except in compliance 9*09dbbe93SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*09dbbe93SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*09dbbe93SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*09dbbe93SAndrew Rist * software distributed under the License is distributed on an 15*09dbbe93SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*09dbbe93SAndrew Rist * KIND, either express or implied. See the License for the 17*09dbbe93SAndrew Rist * specific language governing permissions and limitations 18*09dbbe93SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*09dbbe93SAndrew Rist *************************************************************/ 21*09dbbe93SAndrew Rist 22*09dbbe93SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_basegfx.hxx" 26cdf0e10cSrcweir #include <basegfx/polygon/b2dpolypolygontools.hxx> 27cdf0e10cSrcweir #include <osl/diagnose.h> 28cdf0e10cSrcweir #include <basegfx/polygon/b2dpolypolygon.hxx> 29cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygon.hxx> 30cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygontools.hxx> 31cdf0e10cSrcweir #include <basegfx/numeric/ftools.hxx> 32cdf0e10cSrcweir #include <basegfx/polygon/b2dpolypolygoncutter.hxx> 33cdf0e10cSrcweir 34cdf0e10cSrcweir #include <numeric> 35cdf0e10cSrcweir 36cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////// 37cdf0e10cSrcweir 38cdf0e10cSrcweir namespace basegfx 39cdf0e10cSrcweir { 40cdf0e10cSrcweir namespace tools 41cdf0e10cSrcweir { 42cdf0e10cSrcweir B2DPolyPolygon correctOrientations(const B2DPolyPolygon& rCandidate) 43cdf0e10cSrcweir { 44cdf0e10cSrcweir B2DPolyPolygon aRetval(rCandidate); 45cdf0e10cSrcweir const sal_uInt32 nCount(aRetval.count()); 46cdf0e10cSrcweir 47cdf0e10cSrcweir for(sal_uInt32 a(0L); a < nCount; a++) 48cdf0e10cSrcweir { 49cdf0e10cSrcweir const B2DPolygon aCandidate(rCandidate.getB2DPolygon(a)); 50cdf0e10cSrcweir const B2VectorOrientation aOrientation(tools::getOrientation(aCandidate)); 51cdf0e10cSrcweir sal_uInt32 nDepth(0L); 52cdf0e10cSrcweir 53cdf0e10cSrcweir for(sal_uInt32 b(0L); b < nCount; b++) 54cdf0e10cSrcweir { 55cdf0e10cSrcweir if(b != a) 56cdf0e10cSrcweir { 57cdf0e10cSrcweir const B2DPolygon aCompare(rCandidate.getB2DPolygon(b)); 58cdf0e10cSrcweir 59cdf0e10cSrcweir if(tools::isInside(aCompare, aCandidate, true)) 60cdf0e10cSrcweir { 61cdf0e10cSrcweir nDepth++; 62cdf0e10cSrcweir } 63cdf0e10cSrcweir } 64cdf0e10cSrcweir } 65cdf0e10cSrcweir 66cdf0e10cSrcweir const bool bShallBeHole(1L == (nDepth & 0x00000001)); 67cdf0e10cSrcweir const bool bIsHole(ORIENTATION_NEGATIVE == aOrientation); 68cdf0e10cSrcweir 69cdf0e10cSrcweir if(bShallBeHole != bIsHole && ORIENTATION_NEUTRAL != aOrientation) 70cdf0e10cSrcweir { 71cdf0e10cSrcweir B2DPolygon aFlipped(aCandidate); 72cdf0e10cSrcweir aFlipped.flip(); 73cdf0e10cSrcweir aRetval.setB2DPolygon(a, aFlipped); 74cdf0e10cSrcweir } 75cdf0e10cSrcweir } 76cdf0e10cSrcweir 77cdf0e10cSrcweir return aRetval; 78cdf0e10cSrcweir } 79cdf0e10cSrcweir 80cdf0e10cSrcweir B2DPolyPolygon correctOutmostPolygon(const B2DPolyPolygon& rCandidate) 81cdf0e10cSrcweir { 82cdf0e10cSrcweir const sal_uInt32 nCount(rCandidate.count()); 83cdf0e10cSrcweir 84cdf0e10cSrcweir if(nCount > 1L) 85cdf0e10cSrcweir { 86cdf0e10cSrcweir for(sal_uInt32 a(0L); a < nCount; a++) 87cdf0e10cSrcweir { 88cdf0e10cSrcweir const B2DPolygon aCandidate(rCandidate.getB2DPolygon(a)); 89cdf0e10cSrcweir sal_uInt32 nDepth(0L); 90cdf0e10cSrcweir 91cdf0e10cSrcweir for(sal_uInt32 b(0L); b < nCount; b++) 92cdf0e10cSrcweir { 93cdf0e10cSrcweir if(b != a) 94cdf0e10cSrcweir { 95cdf0e10cSrcweir const B2DPolygon aCompare(rCandidate.getB2DPolygon(b)); 96cdf0e10cSrcweir 97cdf0e10cSrcweir if(tools::isInside(aCompare, aCandidate, true)) 98cdf0e10cSrcweir { 99cdf0e10cSrcweir nDepth++; 100cdf0e10cSrcweir } 101cdf0e10cSrcweir } 102cdf0e10cSrcweir } 103cdf0e10cSrcweir 104cdf0e10cSrcweir if(!nDepth) 105cdf0e10cSrcweir { 106cdf0e10cSrcweir B2DPolyPolygon aRetval(rCandidate); 107cdf0e10cSrcweir 108cdf0e10cSrcweir if(a != 0L) 109cdf0e10cSrcweir { 110cdf0e10cSrcweir // exchange polygon a and polygon 0L 111cdf0e10cSrcweir aRetval.setB2DPolygon(0L, aCandidate); 112cdf0e10cSrcweir aRetval.setB2DPolygon(a, rCandidate.getB2DPolygon(0L)); 113cdf0e10cSrcweir } 114cdf0e10cSrcweir 115cdf0e10cSrcweir // exit 116cdf0e10cSrcweir return aRetval; 117cdf0e10cSrcweir } 118cdf0e10cSrcweir } 119cdf0e10cSrcweir } 120cdf0e10cSrcweir 121cdf0e10cSrcweir return rCandidate; 122cdf0e10cSrcweir } 123cdf0e10cSrcweir 124cdf0e10cSrcweir B2DPolyPolygon adaptiveSubdivideByDistance(const B2DPolyPolygon& rCandidate, double fDistanceBound) 125cdf0e10cSrcweir { 126cdf0e10cSrcweir if(rCandidate.areControlPointsUsed()) 127cdf0e10cSrcweir { 128cdf0e10cSrcweir const sal_uInt32 nPolygonCount(rCandidate.count()); 129cdf0e10cSrcweir B2DPolyPolygon aRetval; 130cdf0e10cSrcweir 131cdf0e10cSrcweir for(sal_uInt32 a(0L); a < nPolygonCount; a++) 132cdf0e10cSrcweir { 133cdf0e10cSrcweir const B2DPolygon aCandidate(rCandidate.getB2DPolygon(a)); 134cdf0e10cSrcweir 135cdf0e10cSrcweir if(aCandidate.areControlPointsUsed()) 136cdf0e10cSrcweir { 137cdf0e10cSrcweir aRetval.append(tools::adaptiveSubdivideByDistance(aCandidate, fDistanceBound)); 138cdf0e10cSrcweir } 139cdf0e10cSrcweir else 140cdf0e10cSrcweir { 141cdf0e10cSrcweir aRetval.append(aCandidate); 142cdf0e10cSrcweir } 143cdf0e10cSrcweir } 144cdf0e10cSrcweir 145cdf0e10cSrcweir return aRetval; 146cdf0e10cSrcweir } 147cdf0e10cSrcweir else 148cdf0e10cSrcweir { 149cdf0e10cSrcweir return rCandidate; 150cdf0e10cSrcweir } 151cdf0e10cSrcweir } 152cdf0e10cSrcweir 153cdf0e10cSrcweir B2DPolyPolygon adaptiveSubdivideByAngle(const B2DPolyPolygon& rCandidate, double fAngleBound) 154cdf0e10cSrcweir { 155cdf0e10cSrcweir if(rCandidate.areControlPointsUsed()) 156cdf0e10cSrcweir { 157cdf0e10cSrcweir const sal_uInt32 nPolygonCount(rCandidate.count()); 158cdf0e10cSrcweir B2DPolyPolygon aRetval; 159cdf0e10cSrcweir 160cdf0e10cSrcweir for(sal_uInt32 a(0L); a < nPolygonCount; a++) 161cdf0e10cSrcweir { 162cdf0e10cSrcweir const B2DPolygon aCandidate(rCandidate.getB2DPolygon(a)); 163cdf0e10cSrcweir 164cdf0e10cSrcweir if(aCandidate.areControlPointsUsed()) 165cdf0e10cSrcweir { 166cdf0e10cSrcweir aRetval.append(tools::adaptiveSubdivideByAngle(aCandidate, fAngleBound)); 167cdf0e10cSrcweir } 168cdf0e10cSrcweir else 169cdf0e10cSrcweir { 170cdf0e10cSrcweir aRetval.append(aCandidate); 171cdf0e10cSrcweir } 172cdf0e10cSrcweir } 173cdf0e10cSrcweir 174cdf0e10cSrcweir return aRetval; 175cdf0e10cSrcweir } 176cdf0e10cSrcweir else 177cdf0e10cSrcweir { 178cdf0e10cSrcweir return rCandidate; 179cdf0e10cSrcweir } 180cdf0e10cSrcweir } 181cdf0e10cSrcweir 182cdf0e10cSrcweir B2DPolyPolygon adaptiveSubdivideByCount(const B2DPolyPolygon& rCandidate, sal_uInt32 nCount) 183cdf0e10cSrcweir { 184cdf0e10cSrcweir if(rCandidate.areControlPointsUsed()) 185cdf0e10cSrcweir { 186cdf0e10cSrcweir const sal_uInt32 nPolygonCount(rCandidate.count()); 187cdf0e10cSrcweir B2DPolyPolygon aRetval; 188cdf0e10cSrcweir 189cdf0e10cSrcweir for(sal_uInt32 a(0L); a < nPolygonCount; a++) 190cdf0e10cSrcweir { 191cdf0e10cSrcweir const B2DPolygon aCandidate(rCandidate.getB2DPolygon(a)); 192cdf0e10cSrcweir 193cdf0e10cSrcweir if(aCandidate.areControlPointsUsed()) 194cdf0e10cSrcweir { 195cdf0e10cSrcweir aRetval.append(tools::adaptiveSubdivideByCount(aCandidate, nCount)); 196cdf0e10cSrcweir } 197cdf0e10cSrcweir else 198cdf0e10cSrcweir { 199cdf0e10cSrcweir aRetval.append(aCandidate); 200cdf0e10cSrcweir } 201cdf0e10cSrcweir } 202cdf0e10cSrcweir 203cdf0e10cSrcweir return aRetval; 204cdf0e10cSrcweir } 205cdf0e10cSrcweir else 206cdf0e10cSrcweir { 207cdf0e10cSrcweir return rCandidate; 208cdf0e10cSrcweir } 209cdf0e10cSrcweir } 210cdf0e10cSrcweir 211cdf0e10cSrcweir bool isInside(const B2DPolyPolygon& rCandidate, const B2DPoint& rPoint, bool bWithBorder) 212cdf0e10cSrcweir { 213cdf0e10cSrcweir const sal_uInt32 nPolygonCount(rCandidate.count()); 214cdf0e10cSrcweir 215cdf0e10cSrcweir if(1L == nPolygonCount) 216cdf0e10cSrcweir { 217cdf0e10cSrcweir return isInside(rCandidate.getB2DPolygon(0L), rPoint, bWithBorder); 218cdf0e10cSrcweir } 219cdf0e10cSrcweir else 220cdf0e10cSrcweir { 221cdf0e10cSrcweir sal_Int32 nInsideCount(0L); 222cdf0e10cSrcweir 223cdf0e10cSrcweir for(sal_uInt32 a(0L); a < nPolygonCount; a++) 224cdf0e10cSrcweir { 225cdf0e10cSrcweir const B2DPolygon aPolygon(rCandidate.getB2DPolygon(a)); 226cdf0e10cSrcweir const bool bInside(isInside(aPolygon, rPoint, bWithBorder)); 227cdf0e10cSrcweir 228cdf0e10cSrcweir if(bInside) 229cdf0e10cSrcweir { 230cdf0e10cSrcweir nInsideCount++; 231cdf0e10cSrcweir } 232cdf0e10cSrcweir } 233cdf0e10cSrcweir 234cdf0e10cSrcweir return (nInsideCount % 2L); 235cdf0e10cSrcweir } 236cdf0e10cSrcweir } 237cdf0e10cSrcweir 238cdf0e10cSrcweir B2DRange getRangeWithControlPoints(const B2DPolyPolygon& rCandidate) 239cdf0e10cSrcweir { 240cdf0e10cSrcweir B2DRange aRetval; 241cdf0e10cSrcweir const sal_uInt32 nPolygonCount(rCandidate.count()); 242cdf0e10cSrcweir 243cdf0e10cSrcweir for(sal_uInt32 a(0L); a < nPolygonCount; a++) 244cdf0e10cSrcweir { 245cdf0e10cSrcweir B2DPolygon aCandidate = rCandidate.getB2DPolygon(a); 246cdf0e10cSrcweir aRetval.expand(tools::getRangeWithControlPoints(aCandidate)); 247cdf0e10cSrcweir } 248cdf0e10cSrcweir 249cdf0e10cSrcweir return aRetval; 250cdf0e10cSrcweir } 251cdf0e10cSrcweir 252cdf0e10cSrcweir B2DRange getRange(const B2DPolyPolygon& rCandidate) 253cdf0e10cSrcweir { 254cdf0e10cSrcweir B2DRange aRetval; 255cdf0e10cSrcweir const sal_uInt32 nPolygonCount(rCandidate.count()); 256cdf0e10cSrcweir 257cdf0e10cSrcweir for(sal_uInt32 a(0L); a < nPolygonCount; a++) 258cdf0e10cSrcweir { 259cdf0e10cSrcweir B2DPolygon aCandidate = rCandidate.getB2DPolygon(a); 260cdf0e10cSrcweir aRetval.expand(tools::getRange(aCandidate)); 261cdf0e10cSrcweir } 262cdf0e10cSrcweir 263cdf0e10cSrcweir return aRetval; 264cdf0e10cSrcweir } 265cdf0e10cSrcweir 266cdf0e10cSrcweir void applyLineDashing(const B2DPolyPolygon& rCandidate, const ::std::vector<double>& rDotDashArray, B2DPolyPolygon* pLineTarget, B2DPolyPolygon* pGapTarget, double fFullDashDotLen) 267cdf0e10cSrcweir { 268cdf0e10cSrcweir if(0.0 == fFullDashDotLen && rDotDashArray.size()) 269cdf0e10cSrcweir { 270cdf0e10cSrcweir // calculate fFullDashDotLen from rDotDashArray 271cdf0e10cSrcweir fFullDashDotLen = ::std::accumulate(rDotDashArray.begin(), rDotDashArray.end(), 0.0); 272cdf0e10cSrcweir } 273cdf0e10cSrcweir 274cdf0e10cSrcweir if(rCandidate.count() && fFullDashDotLen > 0.0) 275cdf0e10cSrcweir { 276cdf0e10cSrcweir B2DPolyPolygon aLineTarget, aGapTarget; 277cdf0e10cSrcweir 278cdf0e10cSrcweir for(sal_uInt32 a(0L); a < rCandidate.count(); a++) 279cdf0e10cSrcweir { 280cdf0e10cSrcweir const B2DPolygon aCandidate(rCandidate.getB2DPolygon(a)); 281cdf0e10cSrcweir 282cdf0e10cSrcweir applyLineDashing( 283cdf0e10cSrcweir aCandidate, 284cdf0e10cSrcweir rDotDashArray, 285cdf0e10cSrcweir pLineTarget ? &aLineTarget : 0, 286cdf0e10cSrcweir pGapTarget ? &aGapTarget : 0, 287cdf0e10cSrcweir fFullDashDotLen); 288cdf0e10cSrcweir 289cdf0e10cSrcweir if(pLineTarget) 290cdf0e10cSrcweir { 291cdf0e10cSrcweir pLineTarget->append(aLineTarget); 292cdf0e10cSrcweir } 293cdf0e10cSrcweir 294cdf0e10cSrcweir if(pGapTarget) 295cdf0e10cSrcweir { 296cdf0e10cSrcweir pGapTarget->append(aGapTarget); 297cdf0e10cSrcweir } 298cdf0e10cSrcweir } 299cdf0e10cSrcweir } 300cdf0e10cSrcweir } 301cdf0e10cSrcweir 302cdf0e10cSrcweir bool isInEpsilonRange(const B2DPolyPolygon& rCandidate, const B2DPoint& rTestPosition, double fDistance) 303cdf0e10cSrcweir { 304cdf0e10cSrcweir const sal_uInt32 nPolygonCount(rCandidate.count()); 305cdf0e10cSrcweir 306cdf0e10cSrcweir for(sal_uInt32 a(0L); a < nPolygonCount; a++) 307cdf0e10cSrcweir { 308cdf0e10cSrcweir B2DPolygon aCandidate(rCandidate.getB2DPolygon(a)); 309cdf0e10cSrcweir 310cdf0e10cSrcweir if(isInEpsilonRange(aCandidate, rTestPosition, fDistance)) 311cdf0e10cSrcweir { 312cdf0e10cSrcweir return true; 313cdf0e10cSrcweir } 314cdf0e10cSrcweir } 315cdf0e10cSrcweir 316cdf0e10cSrcweir return false; 317cdf0e10cSrcweir } 318cdf0e10cSrcweir 319cdf0e10cSrcweir B3DPolyPolygon createB3DPolyPolygonFromB2DPolyPolygon(const B2DPolyPolygon& rCandidate, double fZCoordinate) 320cdf0e10cSrcweir { 321cdf0e10cSrcweir const sal_uInt32 nPolygonCount(rCandidate.count()); 322cdf0e10cSrcweir B3DPolyPolygon aRetval; 323cdf0e10cSrcweir 324cdf0e10cSrcweir for(sal_uInt32 a(0L); a < nPolygonCount; a++) 325cdf0e10cSrcweir { 326cdf0e10cSrcweir B2DPolygon aCandidate(rCandidate.getB2DPolygon(a)); 327cdf0e10cSrcweir 328cdf0e10cSrcweir aRetval.append(createB3DPolygonFromB2DPolygon(aCandidate, fZCoordinate)); 329cdf0e10cSrcweir } 330cdf0e10cSrcweir 331cdf0e10cSrcweir return aRetval; 332cdf0e10cSrcweir } 333cdf0e10cSrcweir 334cdf0e10cSrcweir B2DPolyPolygon createB2DPolyPolygonFromB3DPolyPolygon(const B3DPolyPolygon& rCandidate, const B3DHomMatrix& rMat) 335cdf0e10cSrcweir { 336cdf0e10cSrcweir const sal_uInt32 nPolygonCount(rCandidate.count()); 337cdf0e10cSrcweir B2DPolyPolygon aRetval; 338cdf0e10cSrcweir 339cdf0e10cSrcweir for(sal_uInt32 a(0L); a < nPolygonCount; a++) 340cdf0e10cSrcweir { 341cdf0e10cSrcweir B3DPolygon aCandidate(rCandidate.getB3DPolygon(a)); 342cdf0e10cSrcweir 343cdf0e10cSrcweir aRetval.append(createB2DPolygonFromB3DPolygon(aCandidate, rMat)); 344cdf0e10cSrcweir } 345cdf0e10cSrcweir 346cdf0e10cSrcweir return aRetval; 347cdf0e10cSrcweir } 348cdf0e10cSrcweir 349cdf0e10cSrcweir double getSmallestDistancePointToPolyPolygon(const B2DPolyPolygon& rCandidate, const B2DPoint& rTestPoint, sal_uInt32& rPolygonIndex, sal_uInt32& rEdgeIndex, double& rCut) 350cdf0e10cSrcweir { 351cdf0e10cSrcweir double fRetval(DBL_MAX); 352cdf0e10cSrcweir const double fZero(0.0); 353cdf0e10cSrcweir const sal_uInt32 nPolygonCount(rCandidate.count()); 354cdf0e10cSrcweir 355cdf0e10cSrcweir for(sal_uInt32 a(0L); a < nPolygonCount; a++) 356cdf0e10cSrcweir { 357cdf0e10cSrcweir const B2DPolygon aCandidate(rCandidate.getB2DPolygon(a)); 358cdf0e10cSrcweir sal_uInt32 nNewEdgeIndex; 359cdf0e10cSrcweir double fNewCut; 360cdf0e10cSrcweir const double fNewDistance(getSmallestDistancePointToPolygon(aCandidate, rTestPoint, nNewEdgeIndex, fNewCut)); 361cdf0e10cSrcweir 362cdf0e10cSrcweir if(DBL_MAX == fRetval || fNewDistance < fRetval) 363cdf0e10cSrcweir { 364cdf0e10cSrcweir fRetval = fNewDistance; 365cdf0e10cSrcweir rPolygonIndex = a; 366cdf0e10cSrcweir rEdgeIndex = nNewEdgeIndex; 367cdf0e10cSrcweir rCut = fNewCut; 368cdf0e10cSrcweir 369cdf0e10cSrcweir if(fTools::equal(fRetval, fZero)) 370cdf0e10cSrcweir { 371cdf0e10cSrcweir // already found zero distance, cannot get better. Ensure numerical zero value and end loop. 372cdf0e10cSrcweir fRetval = 0.0; 373cdf0e10cSrcweir break; 374cdf0e10cSrcweir } 375cdf0e10cSrcweir } 376cdf0e10cSrcweir } 377cdf0e10cSrcweir 378cdf0e10cSrcweir return fRetval; 379cdf0e10cSrcweir } 380cdf0e10cSrcweir 381cdf0e10cSrcweir B2DPolyPolygon distort(const B2DPolyPolygon& rCandidate, const B2DRange& rOriginal, const B2DPoint& rTopLeft, const B2DPoint& rTopRight, const B2DPoint& rBottomLeft, const B2DPoint& rBottomRight) 382cdf0e10cSrcweir { 383cdf0e10cSrcweir const sal_uInt32 nPolygonCount(rCandidate.count()); 384cdf0e10cSrcweir B2DPolyPolygon aRetval; 385cdf0e10cSrcweir 386cdf0e10cSrcweir for(sal_uInt32 a(0L); a < nPolygonCount; a++) 387cdf0e10cSrcweir { 388cdf0e10cSrcweir const B2DPolygon aCandidate(rCandidate.getB2DPolygon(a)); 389cdf0e10cSrcweir 390cdf0e10cSrcweir aRetval.append(distort(aCandidate, rOriginal, rTopLeft, rTopRight, rBottomLeft, rBottomRight)); 391cdf0e10cSrcweir } 392cdf0e10cSrcweir 393cdf0e10cSrcweir return aRetval; 394cdf0e10cSrcweir } 395cdf0e10cSrcweir 396cdf0e10cSrcweir B2DPolyPolygon rotateAroundPoint(const B2DPolyPolygon& rCandidate, const B2DPoint& rCenter, double fAngle) 397cdf0e10cSrcweir { 398cdf0e10cSrcweir const sal_uInt32 nPolygonCount(rCandidate.count()); 399cdf0e10cSrcweir B2DPolyPolygon aRetval; 400cdf0e10cSrcweir 401cdf0e10cSrcweir for(sal_uInt32 a(0L); a < nPolygonCount; a++) 402cdf0e10cSrcweir { 403cdf0e10cSrcweir const B2DPolygon aCandidate(rCandidate.getB2DPolygon(a)); 404cdf0e10cSrcweir 405cdf0e10cSrcweir aRetval.append(rotateAroundPoint(aCandidate, rCenter, fAngle)); 406cdf0e10cSrcweir } 407cdf0e10cSrcweir 408cdf0e10cSrcweir return aRetval; 409cdf0e10cSrcweir } 410cdf0e10cSrcweir 411cdf0e10cSrcweir B2DPolyPolygon expandToCurve(const B2DPolyPolygon& rCandidate) 412cdf0e10cSrcweir { 413cdf0e10cSrcweir const sal_uInt32 nPolygonCount(rCandidate.count()); 414cdf0e10cSrcweir B2DPolyPolygon aRetval; 415cdf0e10cSrcweir 416cdf0e10cSrcweir for(sal_uInt32 a(0L); a < nPolygonCount; a++) 417cdf0e10cSrcweir { 418cdf0e10cSrcweir const B2DPolygon aCandidate(rCandidate.getB2DPolygon(a)); 419cdf0e10cSrcweir 420cdf0e10cSrcweir aRetval.append(expandToCurve(aCandidate)); 421cdf0e10cSrcweir } 422cdf0e10cSrcweir 423cdf0e10cSrcweir return aRetval; 424cdf0e10cSrcweir } 425cdf0e10cSrcweir 426cdf0e10cSrcweir B2DPolyPolygon setContinuity(const B2DPolyPolygon& rCandidate, B2VectorContinuity eContinuity) 427cdf0e10cSrcweir { 428cdf0e10cSrcweir if(rCandidate.areControlPointsUsed()) 429cdf0e10cSrcweir { 430cdf0e10cSrcweir const sal_uInt32 nPolygonCount(rCandidate.count()); 431cdf0e10cSrcweir B2DPolyPolygon aRetval; 432cdf0e10cSrcweir 433cdf0e10cSrcweir for(sal_uInt32 a(0L); a < nPolygonCount; a++) 434cdf0e10cSrcweir { 435cdf0e10cSrcweir const B2DPolygon aCandidate(rCandidate.getB2DPolygon(a)); 436cdf0e10cSrcweir 437cdf0e10cSrcweir aRetval.append(setContinuity(aCandidate, eContinuity)); 438cdf0e10cSrcweir } 439cdf0e10cSrcweir 440cdf0e10cSrcweir return aRetval; 441cdf0e10cSrcweir } 442cdf0e10cSrcweir else 443cdf0e10cSrcweir { 444cdf0e10cSrcweir return rCandidate; 445cdf0e10cSrcweir } 446cdf0e10cSrcweir } 447cdf0e10cSrcweir 448cdf0e10cSrcweir B2DPolyPolygon growInNormalDirection(const B2DPolyPolygon& rCandidate, double fValue) 449cdf0e10cSrcweir { 450cdf0e10cSrcweir if(0.0 != fValue) 451cdf0e10cSrcweir { 452cdf0e10cSrcweir B2DPolyPolygon aRetval; 453cdf0e10cSrcweir 454cdf0e10cSrcweir for(sal_uInt32 a(0L); a < rCandidate.count(); a++) 455cdf0e10cSrcweir { 456cdf0e10cSrcweir aRetval.append(growInNormalDirection(rCandidate.getB2DPolygon(a), fValue)); 457cdf0e10cSrcweir } 458cdf0e10cSrcweir 459cdf0e10cSrcweir return aRetval; 460cdf0e10cSrcweir } 461cdf0e10cSrcweir else 462cdf0e10cSrcweir { 463cdf0e10cSrcweir return rCandidate; 464cdf0e10cSrcweir } 465cdf0e10cSrcweir } 466cdf0e10cSrcweir 467cdf0e10cSrcweir void correctGrowShrinkPolygonPair(B2DPolyPolygon& /*rOriginal*/, B2DPolyPolygon& /*rGrown*/) 468cdf0e10cSrcweir { 469cdf0e10cSrcweir } 470cdf0e10cSrcweir 471cdf0e10cSrcweir B2DPolyPolygon reSegmentPolyPolygon(const B2DPolyPolygon& rCandidate, sal_uInt32 nSegments) 472cdf0e10cSrcweir { 473cdf0e10cSrcweir B2DPolyPolygon aRetval; 474cdf0e10cSrcweir 475cdf0e10cSrcweir for(sal_uInt32 a(0L); a < rCandidate.count(); a++) 476cdf0e10cSrcweir { 477cdf0e10cSrcweir aRetval.append(reSegmentPolygon(rCandidate.getB2DPolygon(a), nSegments)); 478cdf0e10cSrcweir } 479cdf0e10cSrcweir 480cdf0e10cSrcweir return aRetval; 481cdf0e10cSrcweir } 482cdf0e10cSrcweir 483cdf0e10cSrcweir B2DPolyPolygon interpolate(const B2DPolyPolygon& rOld1, const B2DPolyPolygon& rOld2, double t) 484cdf0e10cSrcweir { 485cdf0e10cSrcweir OSL_ENSURE(rOld1.count() == rOld2.count(), "B2DPolyPolygon interpolate: Different geometry (!)"); 486cdf0e10cSrcweir B2DPolyPolygon aRetval; 487cdf0e10cSrcweir 488cdf0e10cSrcweir for(sal_uInt32 a(0L); a < rOld1.count(); a++) 489cdf0e10cSrcweir { 490cdf0e10cSrcweir aRetval.append(interpolate(rOld1.getB2DPolygon(a), rOld2.getB2DPolygon(a), t)); 491cdf0e10cSrcweir } 492cdf0e10cSrcweir 493cdf0e10cSrcweir return aRetval; 494cdf0e10cSrcweir } 495cdf0e10cSrcweir 496cdf0e10cSrcweir bool isRectangle( const B2DPolyPolygon& rPoly ) 497cdf0e10cSrcweir { 498cdf0e10cSrcweir // exclude some cheap cases first 499cdf0e10cSrcweir if( rPoly.count() != 1 ) 500cdf0e10cSrcweir return false; 501cdf0e10cSrcweir 502cdf0e10cSrcweir return isRectangle( rPoly.getB2DPolygon(0) ); 503cdf0e10cSrcweir } 504cdf0e10cSrcweir 505cdf0e10cSrcweir // #i76891# 506cdf0e10cSrcweir B2DPolyPolygon simplifyCurveSegments(const B2DPolyPolygon& rCandidate) 507cdf0e10cSrcweir { 508cdf0e10cSrcweir if(rCandidate.areControlPointsUsed()) 509cdf0e10cSrcweir { 510cdf0e10cSrcweir B2DPolyPolygon aRetval; 511cdf0e10cSrcweir 512cdf0e10cSrcweir for(sal_uInt32 a(0L); a < rCandidate.count(); a++) 513cdf0e10cSrcweir { 514cdf0e10cSrcweir aRetval.append(simplifyCurveSegments(rCandidate.getB2DPolygon(a))); 515cdf0e10cSrcweir } 516cdf0e10cSrcweir 517cdf0e10cSrcweir return aRetval; 518cdf0e10cSrcweir } 519cdf0e10cSrcweir else 520cdf0e10cSrcweir { 521cdf0e10cSrcweir return rCandidate; 522cdf0e10cSrcweir } 523cdf0e10cSrcweir } 524cdf0e10cSrcweir 525cdf0e10cSrcweir B2DPolyPolygon reSegmentPolyPolygonEdges(const B2DPolyPolygon& rCandidate, sal_uInt32 nSubEdges, bool bHandleCurvedEdges, bool bHandleStraightEdges) 526cdf0e10cSrcweir { 527cdf0e10cSrcweir B2DPolyPolygon aRetval; 528cdf0e10cSrcweir 529cdf0e10cSrcweir for(sal_uInt32 a(0L); a < rCandidate.count(); a++) 530cdf0e10cSrcweir { 531cdf0e10cSrcweir aRetval.append(reSegmentPolygonEdges(rCandidate.getB2DPolygon(a), nSubEdges, bHandleCurvedEdges, bHandleStraightEdges)); 532cdf0e10cSrcweir } 533cdf0e10cSrcweir 534cdf0e10cSrcweir return aRetval; 535cdf0e10cSrcweir } 536cdf0e10cSrcweir 537cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////// 538cdf0e10cSrcweir // comparators with tolerance for 2D PolyPolygons 539cdf0e10cSrcweir 540cdf0e10cSrcweir bool equal(const B2DPolyPolygon& rCandidateA, const B2DPolyPolygon& rCandidateB, const double& rfSmallValue) 541cdf0e10cSrcweir { 542cdf0e10cSrcweir const sal_uInt32 nPolygonCount(rCandidateA.count()); 543cdf0e10cSrcweir 544cdf0e10cSrcweir if(nPolygonCount != rCandidateB.count()) 545cdf0e10cSrcweir return false; 546cdf0e10cSrcweir 547cdf0e10cSrcweir for(sal_uInt32 a(0); a < nPolygonCount; a++) 548cdf0e10cSrcweir { 549cdf0e10cSrcweir const B2DPolygon aCandidate(rCandidateA.getB2DPolygon(a)); 550cdf0e10cSrcweir 551cdf0e10cSrcweir if(!equal(aCandidate, rCandidateB.getB2DPolygon(a), rfSmallValue)) 552cdf0e10cSrcweir return false; 553cdf0e10cSrcweir } 554cdf0e10cSrcweir 555cdf0e10cSrcweir return true; 556cdf0e10cSrcweir } 557cdf0e10cSrcweir 558cdf0e10cSrcweir bool equal(const B2DPolyPolygon& rCandidateA, const B2DPolyPolygon& rCandidateB) 559cdf0e10cSrcweir { 560cdf0e10cSrcweir const double fSmallValue(fTools::getSmallValue()); 561cdf0e10cSrcweir 562cdf0e10cSrcweir return equal(rCandidateA, rCandidateB, fSmallValue); 563cdf0e10cSrcweir } 564cdf0e10cSrcweir 565cdf0e10cSrcweir B2DPolyPolygon snapPointsOfHorizontalOrVerticalEdges(const B2DPolyPolygon& rCandidate) 566cdf0e10cSrcweir { 567cdf0e10cSrcweir B2DPolyPolygon aRetval; 568cdf0e10cSrcweir 569cdf0e10cSrcweir for(sal_uInt32 a(0L); a < rCandidate.count(); a++) 570cdf0e10cSrcweir { 571cdf0e10cSrcweir aRetval.append(snapPointsOfHorizontalOrVerticalEdges(rCandidate.getB2DPolygon(a))); 572cdf0e10cSrcweir } 573cdf0e10cSrcweir 574cdf0e10cSrcweir return aRetval; 575cdf0e10cSrcweir } 576cdf0e10cSrcweir 577cdf0e10cSrcweir } // end of namespace tools 578cdf0e10cSrcweir } // end of namespace basegfx 579cdf0e10cSrcweir 580cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////// 581cdf0e10cSrcweir // eof 582