Merge
commit
382051e341
|
@ -77,13 +77,13 @@ void CubicBezier::splitBezierCubic(double t, vector<LinePtr>& res) {
|
||||||
|
|
||||||
void CubicBezier::monotonization(vector <LinePtr>& res) {
|
void CubicBezier::monotonization(vector <LinePtr>& res) {
|
||||||
transformToCubic();
|
transformToCubic();
|
||||||
vector<double> re;
|
vector<double> breakPointsT;
|
||||||
re.clear();
|
breakPointsT.clear();
|
||||||
findPointsOfDivison(vX, re);
|
findPointsOfDivison(vX, breakPointsT);
|
||||||
findPointsOfDivison(vY, re);
|
findPointsOfDivison(vY, breakPointsT);
|
||||||
sort(re.begin(), re.end());
|
sort(breakPointsT.begin(), breakPointsT.end());
|
||||||
double lt = -1, x = 0, y = 0;
|
double lt = -1, x = 0, y = 0;
|
||||||
for (double&t : re) {
|
for (double&t : breakPointsT) {
|
||||||
if (fabs(t - lt) <= eps) continue;
|
if (fabs(t - lt) <= eps) continue;
|
||||||
splitBezierCubic(t, res);
|
splitBezierCubic(t, res);
|
||||||
lt = t;
|
lt = t;
|
||||||
|
@ -91,12 +91,12 @@ void CubicBezier::monotonization(vector <LinePtr>& res) {
|
||||||
}
|
}
|
||||||
|
|
||||||
double CubicBezier::findTByValue(double value, bool isY) {
|
double CubicBezier::findTByValue(double value, bool isY) {
|
||||||
double l = 0, r = 1, be = 0;
|
double l = 0, r = 1, valueBegin = 0;
|
||||||
if (isY) be = vY[0];
|
if (isY) valueBegin = vY[0];
|
||||||
else be = vX[0];
|
else valueBegin = vX[0];
|
||||||
while (fabs(r-l) > eps) {
|
while (fabs(r-l) > eps) {
|
||||||
double mid = (l + r) / 2, midValue = getLineValueByT(mid, isY);
|
double mid = (l + r) / 2, midValue = getLineValueByT(mid, isY);
|
||||||
if (fabs(midValue - be) > fabs(value - be)) {
|
if (fabs(midValue - valueBegin) > fabs(value - valueBegin)) {
|
||||||
r = mid;
|
r = mid;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -107,12 +107,12 @@ double CubicBezier::findTByValue(double value, bool isY) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int CubicBezier::judgeBoundIntersection(double xy, double l, double r, bool isY) {
|
int CubicBezier::judgeBoundIntersection(double xy, double l, double r, bool isY) {
|
||||||
double be = *vX.begin(), en = *vX.rbegin();
|
double valueBegin = *vX.begin(), valueEnd = *vX.rbegin();
|
||||||
if (isY) {
|
if (isY) {
|
||||||
be = *vY.begin();
|
valueBegin = *vY.begin();
|
||||||
en = *vY.rbegin();
|
valueEnd = *vY.rbegin();
|
||||||
}
|
}
|
||||||
if ((be - xy) * (en - xy) >= eps) return 0;
|
if ((valueBegin - xy) * (valueEnd - xy) >= eps) return 0;
|
||||||
double t = findTByValue(xy, isY);
|
double t = findTByValue(xy, isY);
|
||||||
double value = getLineValueByT(t, !isY);
|
double value = getLineValueByT(t, !isY);
|
||||||
if (l <= value && value <= r && fabs(t) > eps && fabs(1 - t) > eps) {
|
if (l <= value && value <= r && fabs(t) > eps && fabs(1 - t) > eps) {
|
||||||
|
|
|
@ -61,13 +61,13 @@ Point Line::getEnd() {
|
||||||
}
|
}
|
||||||
|
|
||||||
int Line::direction(bool isY) {
|
int Line::direction(bool isY) {
|
||||||
float be = *vX.begin(), en = *vX.rbegin();
|
float valueBegin = *vX.begin(), valueEnd = *vX.rbegin();
|
||||||
if (isY) {
|
if (isY) {
|
||||||
be = *vY.begin();
|
valueBegin = *vY.begin();
|
||||||
en = *vY.rbegin();
|
valueEnd = *vY.rbegin();
|
||||||
}
|
}
|
||||||
if (fabs(en - be) <= eps) return 0;
|
if (fabs(valueEnd - valueBegin) <= eps) return 0;
|
||||||
else if (be < en) return 1;
|
else if (valueBegin < valueEnd) return 1;
|
||||||
else return 2;
|
else return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -47,7 +47,7 @@ void ShortCutTree::generateShortCutsegmentement(ShortCutNode& nowTreeNode) {
|
||||||
Point p = {0, 0};
|
Point p = {0, 0};
|
||||||
vector<int> v;
|
vector<int> v;
|
||||||
for (int & lineIndex : nowTreeNode.lineSet) {
|
for (int & lineIndex : nowTreeNode.lineSet) {
|
||||||
int type = allLine[lineIndex]->judgeBoundIntersection(nowTreeNode.bound.z(), nowTreeNode.bound.y(), nowTreeNode.bound.w(), false), be, en;
|
int type = allLine[lineIndex]->judgeBoundIntersection(nowTreeNode.bound.z(), nowTreeNode.bound.y(), nowTreeNode.bound.w(), false), lineIndexBegin, lineIndexEnd;
|
||||||
if (type >= 2) {
|
if (type >= 2) {
|
||||||
v.push_back(numLine);
|
v.push_back(numLine);
|
||||||
if (type == 2) {
|
if (type == 2) {
|
||||||
|
@ -56,23 +56,23 @@ void ShortCutTree::generateShortCutsegmentement(ShortCutNode& nowTreeNode) {
|
||||||
if (type == 3) {
|
if (type == 3) {
|
||||||
p = allLine[lineIndex]->getBegin();
|
p = allLine[lineIndex]->getBegin();
|
||||||
}
|
}
|
||||||
be = getPointIndex({ p.x, nowTreeNode.bound.w() });
|
lineIndexBegin = getPointIndex({ p.x, nowTreeNode.bound.w() });
|
||||||
en = getPointIndex(p);
|
lineIndexEnd = getPointIndex(p);
|
||||||
lineIndexs.push_back(be);
|
lineIndexs.push_back(lineIndexBegin);
|
||||||
lineIndexs.push_back(be);
|
lineIndexs.push_back(lineIndexBegin);
|
||||||
lineIndexs.push_back(en);
|
lineIndexs.push_back(lineIndexEnd);
|
||||||
lineIndexs.push_back(en);
|
lineIndexs.push_back(lineIndexEnd);
|
||||||
numLine++;
|
numLine++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (nowTreeNode.windingIncrement != 0) {
|
if (nowTreeNode.windingIncrement != 0) {
|
||||||
v.push_back(numLine);
|
v.push_back(numLine);
|
||||||
int be = getPointIndex({ nowTreeNode.bound.z(), nowTreeNode.bound.y()});
|
int lineIndexBegin = getPointIndex({ nowTreeNode.bound.z(), nowTreeNode.bound.y()});
|
||||||
int en = getPointIndex({ nowTreeNode.bound.z(), nowTreeNode.bound.w() });
|
int lineIndexEnd = getPointIndex({ nowTreeNode.bound.z(), nowTreeNode.bound.w() });
|
||||||
lineIndexs.push_back(be);
|
lineIndexs.push_back(lineIndexBegin);
|
||||||
lineIndexs.push_back(be);
|
lineIndexs.push_back(lineIndexBegin);
|
||||||
lineIndexs.push_back(en);
|
lineIndexs.push_back(lineIndexEnd);
|
||||||
lineIndexs.push_back(en);
|
lineIndexs.push_back(lineIndexEnd);
|
||||||
numLine++;
|
numLine++;
|
||||||
}
|
}
|
||||||
for (int& lineIndex : v) {
|
for (int& lineIndex : v) {
|
||||||
|
|
|
@ -1,37 +1,37 @@
|
||||||
#include "StraightLine.h"
|
#include "StraightLine.h"
|
||||||
|
|
||||||
double StraightLine::getLineValueByT(double t, bool isY) {
|
double StraightLine::getLineValueByT(double t, bool isY) {
|
||||||
float pBe, pEn;
|
float valueBegin, valueEnd;
|
||||||
if (isY) {
|
if (isY) {
|
||||||
pBe = *vY.begin();
|
valueBegin = *vY.begin();
|
||||||
pEn = *vY.rbegin();
|
valueEnd = *vY.rbegin();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
pBe = *vX.begin();
|
valueBegin = *vX.begin();
|
||||||
pEn = *vY.rbegin();
|
valueEnd = *vY.rbegin();
|
||||||
}
|
}
|
||||||
return t * (pEn - pBe) + pBe;
|
return t * (valueEnd - valueBegin) + valueBegin;
|
||||||
}
|
}
|
||||||
|
|
||||||
double StraightLine::findTByValue(double value, bool isY) {
|
double StraightLine::findTByValue(double value, bool isY) {
|
||||||
Point be = getPointByIndex(0), en = getPointByIndex(1);
|
Point pointBegin = getPointByIndex(0), pointEnd = getPointByIndex(1);
|
||||||
if (!isY) {
|
if (!isY) {
|
||||||
if(fabs(be.x - en.x) <= eps) return 0;
|
if(fabs(pointBegin.x - pointEnd.x) <= eps) return 0;
|
||||||
return (value - be.x) / (en.x - be.x);
|
return (value - pointBegin.x) / (pointEnd.x - pointBegin.x);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (fabs(be.y - en.y) <= eps) return 0;
|
if (fabs(pointBegin.y - pointEnd.y) <= eps) return 0;
|
||||||
return (value - be.y) / (en.y - be.y);
|
return (value - pointBegin.y) / (pointEnd.y - pointBegin.y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int StraightLine::judgeBoundIntersection(double xy, double l, double r, bool isY) {
|
int StraightLine::judgeBoundIntersection(double xy, double l, double r, bool isY) {
|
||||||
Point be = getBegin(), en = getEnd();
|
Point pointBegin = getBegin(), pointEnd = getEnd();
|
||||||
if (isY) {
|
if (isY) {
|
||||||
swap(be.x, be.y);
|
swap(pointBegin.x, pointBegin.y);
|
||||||
swap(en.x, en.y);
|
swap(pointEnd.x, pointEnd.y);
|
||||||
}
|
}
|
||||||
if ((be.x - xy) * (en.x - xy) >= eps) return 0;
|
if ((pointBegin.x - xy) * (pointEnd.x - xy) >= eps) return 0;
|
||||||
if (direction(isY)) {
|
if (direction(isY)) {
|
||||||
float t = findTByValue(xy, isY);
|
float t = findTByValue(xy, isY);
|
||||||
float value = getLineValueByT(t, !isY);
|
float value = getLineValueByT(t, !isY);
|
||||||
|
@ -40,8 +40,8 @@ int StraightLine::judgeBoundIntersection(double xy, double l, double r, bool isY
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
if (be.y <= l && en.y < l) return 0;
|
if (pointBegin.y <= l && pointEnd.y < l) return 0;
|
||||||
if (be.y >= r && en.y > r) return 0;
|
if (pointBegin.y >= r && pointEnd.y > r) return 0;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Reference in New Issue