修复宽度变化的bug (待测试)
parent
ae77ffdbdb
commit
f9e316c547
|
@ -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,28 +72,51 @@ 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;
|
||||||
std::shared_ptr<Line> nowLine;
|
tmpLines.clear();
|
||||||
switch (l.size()) {
|
for (int i = 0; i < inLines.size(); i++) {
|
||||||
case 2: {
|
int endIndex = i;
|
||||||
nowLine.reset(new StraightLine(l));
|
double totalLength = 0;
|
||||||
break;
|
while (endIndex < inLines.size() && *inLines[endIndex].rbegin() == *inLines[endIndex + 1].begin()) {
|
||||||
|
endIndex++;
|
||||||
}
|
}
|
||||||
case 3: case 4: nowLine.reset(new CubicBezier(l)); break;
|
// 计算总长度
|
||||||
default: break;
|
for (int j = i; j <= endIndex; j++) {
|
||||||
|
PointVector& l = inLines[j];
|
||||||
|
std::shared_ptr<Line> nowLine;
|
||||||
|
switch (l.size()) {
|
||||||
|
case 2: {
|
||||||
|
nowLine = make_shared<StraightLine>(l);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 4: nowLine = make_shared<CubicBezier>(l); break;
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
totalLength += nowLine->getIntegralByT(1);
|
||||||
|
tmpLines.push_back(nowLine);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 防止在同一直线与 X 轴平行上
|
//单调化并求比例
|
||||||
if (isOffset) {
|
double prefixLength = 0;
|
||||||
nowLine->upwardOffsetForY(true, 1e-5);
|
for (auto nowLine : tmpLines) {
|
||||||
|
// 防止在同一直线与 X 轴平行上
|
||||||
|
double nowLineLength = nowLine->getIntegralByT(1);
|
||||||
|
nowLine->setRate({ prefixLength / totalLength, (prefixLength + nowLineLength) / totalLength });
|
||||||
|
prefixLength += nowLineLength;
|
||||||
|
|
||||||
|
if (isOffset) {
|
||||||
|
nowLine->upwardOffsetForY(true, 1e-5);
|
||||||
|
}
|
||||||
|
isOffset = false;
|
||||||
|
if (nowLine->direction(true) == 0) {
|
||||||
|
nowLine->upwardOffsetForY(false, 1e-5);
|
||||||
|
isOffset = true;
|
||||||
|
}
|
||||||
|
nowLine->monotonization(outLines);
|
||||||
|
outLines.push_back(nowLine);
|
||||||
}
|
}
|
||||||
isOffset = false;
|
tmpLines.clear();
|
||||||
if (nowLine->direction(true) == 0) {
|
i = endIndex;
|
||||||
nowLine->upwardOffsetForY(false, 1e-5);
|
|
||||||
isOffset = true;
|
|
||||||
}
|
|
||||||
nowLine->monotonization(outLines);
|
|
||||||
outLines.push_back(nowLine);
|
|
||||||
}
|
}
|
||||||
// 防止在首尾直线在与 X 轴平行上
|
// 防止在首尾直线在与 X 轴平行上
|
||||||
int siz = outLines.size();
|
int siz = outLines.size();
|
||||||
|
|
Loading…
Reference in New Issue