修复宽度变化的bug (待测试)

main
yang.yongquan 2023-03-29 17:05:02 +08:00
parent ae77ffdbdb
commit f9e316c547
1 changed files with 42 additions and 18 deletions

View File

@ -8,6 +8,7 @@ using std::set;
using std::pair; using std::pair;
using std::vector; using std::vector;
using std::queue; using std::queue;
using std::make_shared;
void LineTree::init() { void LineTree::init() {
restOfTreeNodes.clear(); restOfTreeNodes.clear();
@ -71,18 +72,38 @@ bool LineTree::isLineEqual(PointIndexVector& a, PointIndexVector& b) const {
void LineTree::monotonization(vector<PointVector>& inLines, vector<std::shared_ptr<Line>>& outLines) { void LineTree::monotonization(vector<PointVector>& inLines, vector<std::shared_ptr<Line>>& outLines) {
bool isOffset = false; bool isOffset = false;
for (PointVector& l : inLines) { vector<std::shared_ptr<Line> > tmpLines;
tmpLines.clear();
for (int i = 0; i < inLines.size(); i++) {
int endIndex = i;
double totalLength = 0;
while (endIndex < inLines.size() && *inLines[endIndex].rbegin() == *inLines[endIndex + 1].begin()) {
endIndex++;
}
// 셕炬悧낀똑
for (int j = i; j <= endIndex; j++) {
PointVector& l = inLines[j];
std::shared_ptr<Line> nowLine; std::shared_ptr<Line> nowLine;
switch (l.size()) { switch (l.size()) {
case 2: { case 2: {
nowLine.reset(new StraightLine(l)); nowLine = make_shared<StraightLine>(l);
break; break;
} }
case 3: case 4: nowLine.reset(new CubicBezier(l)); break; case 4: nowLine = make_shared<CubicBezier>(l); break;
default: break; default: break;
} }
totalLength += nowLine->getIntegralByT(1);
tmpLines.push_back(nowLine);
}
//데딧뺏깻헹궐절
double prefixLength = 0;
for (auto nowLine : tmpLines) {
// 防止在同一直线与 X 轴平行上 // 防止在同一直线与 X 轴平行上
double nowLineLength = nowLine->getIntegralByT(1);
nowLine->setRate({ prefixLength / totalLength, (prefixLength + nowLineLength) / totalLength });
prefixLength += nowLineLength;
if (isOffset) { if (isOffset) {
nowLine->upwardOffsetForY(true, 1e-5); nowLine->upwardOffsetForY(true, 1e-5);
} }
@ -94,6 +115,9 @@ void LineTree::monotonization(vector<PointVector>& inLines, vector<std::shared_p
nowLine->monotonization(outLines); nowLine->monotonization(outLines);
outLines.push_back(nowLine); outLines.push_back(nowLine);
} }
tmpLines.clear();
i = endIndex;
}
// 防止在首尾直线在与 X 轴平行上 // 防止在首尾直线在与 X 轴平行上
int siz = outLines.size(); int siz = outLines.size();
if (!(outLines[0]->getBegin() == outLines[siz - 1]->getEnd())) if (!(outLines[0]->getBegin() == outLines[siz - 1]->getEnd()))