/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * 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 regarding copyright * ownership. The ASF licenses this file 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 .
*/
public:
EdgeEntry(const B2DPoint& rStart, const B2DPoint& rEnd)
: mpNext(nullptr),
maStart(rStart),
maEnd(rEnd),
mfAtan2(0.0)
{ // make sure edge goes down. If horizontal, let it go to the right (left-handed). bool bSwap(false);
booloperator<(const EdgeEntry& rComp) const
{ if(::basegfx::fTools::equal(maStart.getY(), rComp.maStart.getY()))
{ if(::basegfx::fTools::equal(maStart.getX(), rComp.maStart.getX()))
{ // same in x and y -> same start point. Sort emitting vectors from left to right. return (mfAtan2 > rComp.mfAtan2);
}
// but not on point if(!rTestPoint.equal(pEdgeA->getEnd()) && !rTestPoint.equal(pEdgeB->getEnd()))
{ // found point in triangle -> split triangle inserting two edges
EdgeEntry* pStart = new EdgeEntry(pEdgeA->getStart(), rTestPoint);
EdgeEntry* pEnd = new EdgeEntry(*pStart);
maNewEdgeEntries.emplace_back(pStart);
maNewEdgeEntries.emplace_back(pEnd);
// consume as long as there are edges
Triangulator::Triangulator(const B2DPolyPolygon& rCandidate)
: mpList(nullptr)
{ // add all available edges to the single linked local list which will be sorted // by Y,X,atan2 when adding nodes if(rCandidate.count())
{ for(constauto& rPolygonCandidate : rCandidate)
{ const sal_uInt32 nCount {rPolygonCandidate.count()};
while(mpList)
{ if(mpList->getNext() && mpList->getNext()->getStart().equal(mpList->getStart()))
{ // next candidate. There are two edges and start point is equal. // Length is not zero.
EdgeEntry* pEdgeA = mpList;
EdgeEntry* pEdgeB = pEdgeA->getNext();
if( pEdgeA->getEnd().equal(pEdgeB->getEnd()) )
{ // start and end equal -> neutral triangle, delete both
mpList = pEdgeB->getNext();
} else
{ const B2DVector aLeft(pEdgeA->getEnd() - pEdgeA->getStart()); const B2DVector aRight(pEdgeB->getEnd() - pEdgeA->getStart());
if(getOrientation(aLeft, aRight) == B2VectorOrientation::Neutral)
{ // edges are parallel and have different length -> neutral triangle, // delete both edges and handle closing edge
mpList = pEdgeB->getNext();
handleClosingEdge(pEdgeA->getEnd(), pEdgeB->getEnd());
} else
{ // not parallel, look for points inside
B2DRange aRange(pEdgeA->getStart(), pEdgeA->getEnd());
aRange.expand(pEdgeB->getEnd());
EdgeEntry* pTestEdge = pEdgeB->getNext(); bool bNoPointInTriangle(true);
// look for start point in triangle while(bNoPointInTriangle && pTestEdge)
{ if(aRange.getMaxY() < pTestEdge->getStart().getY())
{ // edge is below test range and edges are sorted -> stop looking break;
} else
{ // do not look for edges with same start point, they are sorted and cannot end inside. if(!pTestEdge->getStart().equal(pEdgeA->getStart()))
{ if(aRange.isInside(pTestEdge->getStart()))
{
bNoPointInTriangle = CheckPointInTriangle(pEdgeA, pEdgeB, pTestEdge->getStart());
}
}
}
// next candidate
pTestEdge = pTestEdge->getNext();
}
if(bNoPointInTriangle)
{ // look for end point in triangle
pTestEdge = pEdgeB->getNext();
while(bNoPointInTriangle && pTestEdge)
{ if(aRange.getMaxY() < pTestEdge->getStart().getY())
{ // edge is below test range and edges are sorted -> stop looking break;
} else
{ // do not look for edges with same end point, they are sorted and cannot end inside. if(!pTestEdge->getEnd().equal(pEdgeA->getStart()))
{ if(aRange.isInside(pTestEdge->getEnd()))
{
bNoPointInTriangle = CheckPointInTriangle(pEdgeA, pEdgeB, pTestEdge->getEnd());
}
}
}
// next candidate
pTestEdge = pTestEdge->getNext();
}
}
if(bNoPointInTriangle)
{ // create triangle, remove edges, handle closing edge
mpList = pEdgeB->getNext();
createTriangle(pEdgeA->getStart(), pEdgeB->getEnd(), pEdgeA->getEnd());
handleClosingEdge(pEdgeA->getEnd(), pEdgeB->getEnd());
}
}
}
} else
{ // only one entry at start point, delete it
mpList = mpList->getNext();
}
}
}
} // end of anonymous namespace
} // end of namespace basegfx
// subdivide locally (triangulate does not work with beziers), remove double and neutral points
B2DPolygon aCandidate(rCandidate.areControlPointsUsed() ? utils::adaptiveSubdivideByAngle(rCandidate) : rCandidate);
aCandidate.removeDoublePoints();
aCandidate = utils::removeNeutralPoints(aCandidate);
if(aCandidate.count() == 2)
{ // candidate IS a triangle, just append
aRetval.emplace_back(
aCandidate.getB2DPoint(0),
aCandidate.getB2DPoint(1),
aCandidate.getB2DPoint(2));
} elseif(aCandidate.count() > 2)
{ if(utils::isConvex(aCandidate))
{ // polygon is convex, just use a triangle fan
utils::addTriangleFan(aCandidate, aRetval);
} else
{ // polygon is concave. const B2DPolyPolygon aCandPolyPoly(aCandidate);
Triangulator aTriangulator(aCandPolyPoly);
// subdivide locally (triangulate does not work with beziers)
B2DPolyPolygon aCandidate(rCandidate.areControlPointsUsed() ? utils::adaptiveSubdivideByAngle(rCandidate) : rCandidate);
if(aCandidate.count() == 1)
{ // single polygon -> single polygon triangulation const B2DPolygon& aSinglePolygon(aCandidate.getB2DPolygon(0));
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.