b2dpolypolygoncutter.cxx (ddde725d) b2dpolypolygoncutter.cxx (d8ed516e)
1/**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance

--- 96 unchanged lines hidden (view full) ---

105 }
106 };
107
108 //////////////////////////////////////////////////////////////////////////////
109
110 typedef ::std::vector< PN > PNV;
111 typedef ::std::vector< VN > VNV;
112 typedef ::std::vector< SN > SNV;
1/**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance

--- 96 unchanged lines hidden (view full) ---

105 }
106 };
107
108 //////////////////////////////////////////////////////////////////////////////
109
110 typedef ::std::vector< PN > PNV;
111 typedef ::std::vector< VN > VNV;
112 typedef ::std::vector< SN > SNV;
113 typedef ::std::pair< basegfx::B2DPoint /*orig*/, basegfx::B2DPoint /*repl*/ > CorrectionPair;
114 typedef ::std::vector< CorrectionPair > CorrectionTable;
113
114 //////////////////////////////////////////////////////////////////////////////
115
116 class solver
117 {
118 private:
119 const B2DPolyPolygon maOriginal;
120 PNV maPNV;
121 VNV maVNV;
122 SNV maSNV;
115
116 //////////////////////////////////////////////////////////////////////////////
117
118 class solver
119 {
120 private:
121 const B2DPolyPolygon maOriginal;
122 PNV maPNV;
123 VNV maVNV;
124 SNV maSNV;
125 CorrectionTable maCorrectionTable;
123
124 unsigned mbIsCurve : 1;
125 unsigned mbChanged : 1;
126
127 void impAddPolygon(const sal_uInt32 aPos, const B2DPolygon& rGeometry)
128 {
129 const sal_uInt32 nCount(rGeometry.count());
130 PN aNewPN;

--- 326 unchanged lines hidden (view full) ---

457 {
458 // crossover
459 impSwitchNext(rPNa, rPNb);
460 }
461 }
462 }
463 }
464
126
127 unsigned mbIsCurve : 1;
128 unsigned mbChanged : 1;
129
130 void impAddPolygon(const sal_uInt32 aPos, const B2DPolygon& rGeometry)
131 {
132 const sal_uInt32 nCount(rGeometry.count());
133 PN aNewPN;

--- 326 unchanged lines hidden (view full) ---

460 {
461 // crossover
462 impSwitchNext(rPNa, rPNb);
463 }
464 }
465 }
466 }
467
465 void impSolve()
466 {
467 // sort by point to identify common nodes
468 ::std::sort(maSNV.begin(), maSNV.end());
468 void impSolve()
469 {
470 // sort by point to identify common nodes easier
471 ::std::sort(maSNV.begin(), maSNV.end());
469
472
470 // handle common nodes
471 const sal_uInt32 nNodeCount(maSNV.size());
473 // handle common nodes
474 const sal_uInt32 nNodeCount(maSNV.size());
475 sal_uInt32 a(0);
472
476
473 for(sal_uInt32 a(0); a < nNodeCount - 1; a++)
474 {
475 // test a before using it, not after. Also use nPointCount instead of aSortNodes.size()
477 // snap unsharp-equal points
478 if(nNodeCount)
479 {
480 basegfx::B2DPoint* pLast(&maSNV[0].mpPN->maPoint);
481
482 for(a = 1; a < nNodeCount; a++)
483 {
484 basegfx::B2DPoint* pCurrent(&maSNV[a].mpPN->maPoint);
485
486 if(pLast->equal(*pCurrent) && (pLast->getX() != pCurrent->getX() || pLast->getY() != pCurrent->getY()))
487 {
488 const basegfx::B2DPoint aMiddle((*pLast + *pCurrent) * 0.5);
489
490 if(pLast->getX() != aMiddle.getX() || pLast->getY() != aMiddle.getY())
491 {
492 maCorrectionTable.push_back(CorrectionPair(*pLast, aMiddle));
493 *pLast = aMiddle;
494 }
495
496 if(pCurrent->getX() != aMiddle.getX() || pCurrent->getY() != aMiddle.getY())
497 {
498 maCorrectionTable.push_back(CorrectionPair(*pCurrent, aMiddle));
499 *pCurrent = aMiddle;
500 }
501 }
502
503 pLast = pCurrent;
504 }
505 }
506
507 for(a = 0; a < nNodeCount - 1; a++)
508 {
509 // test a before using it, not after. Also use nPointCount instead of aSortNodes.size()
476 PN& rPNb = *(maSNV[a].mpPN);
477
510 PN& rPNb = *(maSNV[a].mpPN);
511
478 for(sal_uInt32 b(a + 1); b < nNodeCount && rPNb.maPoint.equal(maSNV[b].mpPN->maPoint); b++)
479 {
480 impHandleCommon(rPNb, *maSNV[b].mpPN);
481 }
482 }
483 }
512 for(sal_uInt32 b(a + 1); b < nNodeCount && rPNb.maPoint.equal(maSNV[b].mpPN->maPoint); b++)
513 {
514 impHandleCommon(rPNb, *maSNV[b].mpPN);
515 }
516 }
517 }
484
485 public:
486 solver(const B2DPolygon& rOriginal)
487 : maOriginal(B2DPolyPolygon(rOriginal)),
488 mbIsCurve(false),
489 mbChanged(false)
490 {
491 const sal_uInt32 nOriginalCount(rOriginal.count());

--- 141 unchanged lines hidden (view full) ---

633 // close and add
634 aNewPart.setClosed(true);
635 aRetval.append(aNewPart);
636 }
637 }
638
639 return aRetval;
640 }
518
519 public:
520 solver(const B2DPolygon& rOriginal)
521 : maOriginal(B2DPolyPolygon(rOriginal)),
522 mbIsCurve(false),
523 mbChanged(false)
524 {
525 const sal_uInt32 nOriginalCount(rOriginal.count());

--- 141 unchanged lines hidden (view full) ---

667 // close and add
668 aNewPart.setClosed(true);
669 aRetval.append(aNewPart);
670 }
671 }
672
673 return aRetval;
674 }
641 else
642 {
643 // no change, return original
644 return maOriginal;
645 }
646 }
675 else
676 {
677 const sal_uInt32 nCorrectionSize(maCorrectionTable.size());
678
679 // no change, return original
680 if(!nCorrectionSize)
681 {
682 return maOriginal;
683 }
684
685 // apply coordinate corrections to ensure inside/outside correctness after solving
686 const sal_uInt32 nPolygonCount(maOriginal.count());
687 basegfx::B2DPolyPolygon aRetval(maOriginal);
688
689 for(sal_uInt32 a(0); a < nPolygonCount; a++)
690 {
691 basegfx::B2DPolygon aTemp(aRetval.getB2DPolygon(a));
692 const sal_uInt32 nPointCount(aTemp.count());
693 bool bChanged;
694
695 for(sal_uInt32 b(0); b < nPointCount; b++)
696 {
697 const basegfx::B2DPoint aCandidate(aTemp.getB2DPoint(b));
698
699 for(sal_uInt32 c(0); c < nCorrectionSize; c++)
700 {
701 if(maCorrectionTable[c].first.getX() == aCandidate.getX() && maCorrectionTable[c].first.getY() == aCandidate.getY())
702 {
703 aTemp.setB2DPoint(b, maCorrectionTable[c].second);
704 bChanged = true;
705 }
706 }
707 }
708
709 if(bChanged)
710 {
711 aRetval.setB2DPolygon(a, aTemp);
712 }
713 }
714
715 return aRetval;
716 }
717 }
647 };
648
649 //////////////////////////////////////////////////////////////////////////////
650
651 } // end of anonymous namespace
652} // end of namespace basegfx
653
654//////////////////////////////////////////////////////////////////////////////

--- 444 unchanged lines hidden ---
718 };
719
720 //////////////////////////////////////////////////////////////////////////////
721
722 } // end of anonymous namespace
723} // end of namespace basegfx
724
725//////////////////////////////////////////////////////////////////////////////

--- 444 unchanged lines hidden ---