dev-VirtualTexture
wuyize 2022-10-09 20:25:12 +08:00
commit 382051e341
4 changed files with 49 additions and 49 deletions

View File

@ -77,13 +77,13 @@ void CubicBezier::splitBezierCubic(double t, vector<LinePtr>& res) {
void CubicBezier::monotonization(vector <LinePtr>& res) {
transformToCubic();
vector<double> re;
re.clear();
findPointsOfDivison(vX, re);
findPointsOfDivison(vY, re);
sort(re.begin(), re.end());
vector<double> breakPointsT;
breakPointsT.clear();
findPointsOfDivison(vX, breakPointsT);
findPointsOfDivison(vY, breakPointsT);
sort(breakPointsT.begin(), breakPointsT.end());
double lt = -1, x = 0, y = 0;
for (double&t : re) {
for (double&t : breakPointsT) {
if (fabs(t - lt) <= eps) continue;
splitBezierCubic(t, res);
lt = t;
@ -91,12 +91,12 @@ void CubicBezier::monotonization(vector <LinePtr>& res) {
}
double CubicBezier::findTByValue(double value, bool isY) {
double l = 0, r = 1, be = 0;
if (isY) be = vY[0];
else be = vX[0];
double l = 0, r = 1, valueBegin = 0;
if (isY) valueBegin = vY[0];
else valueBegin = vX[0];
while (fabs(r-l) > eps) {
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;
}
else {
@ -107,12 +107,12 @@ double CubicBezier::findTByValue(double value, 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) {
be = *vY.begin();
en = *vY.rbegin();
valueBegin = *vY.begin();
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 value = getLineValueByT(t, !isY);
if (l <= value && value <= r && fabs(t) > eps && fabs(1 - t) > eps) {

View File

@ -61,13 +61,13 @@ Point Line::getEnd() {
}
int Line::direction(bool isY) {
float be = *vX.begin(), en = *vX.rbegin();
float valueBegin = *vX.begin(), valueEnd = *vX.rbegin();
if (isY) {
be = *vY.begin();
en = *vY.rbegin();
valueBegin = *vY.begin();
valueEnd = *vY.rbegin();
}
if (fabs(en - be) <= eps) return 0;
else if (be < en) return 1;
if (fabs(valueEnd - valueBegin) <= eps) return 0;
else if (valueBegin < valueEnd) return 1;
else return 2;
}

View File

@ -47,7 +47,7 @@ void ShortCutTree::generateShortCutsegmentement(ShortCutNode& nowTreeNode) {
Point p = {0, 0};
vector<int> v;
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) {
v.push_back(numLine);
if (type == 2) {
@ -56,23 +56,23 @@ void ShortCutTree::generateShortCutsegmentement(ShortCutNode& nowTreeNode) {
if (type == 3) {
p = allLine[lineIndex]->getBegin();
}
be = getPointIndex({ p.x, nowTreeNode.bound.w() });
en = getPointIndex(p);
lineIndexs.push_back(be);
lineIndexs.push_back(be);
lineIndexs.push_back(en);
lineIndexs.push_back(en);
lineIndexBegin = getPointIndex({ p.x, nowTreeNode.bound.w() });
lineIndexEnd = getPointIndex(p);
lineIndexs.push_back(lineIndexBegin);
lineIndexs.push_back(lineIndexBegin);
lineIndexs.push_back(lineIndexEnd);
lineIndexs.push_back(lineIndexEnd);
numLine++;
}
}
if (nowTreeNode.windingIncrement != 0) {
v.push_back(numLine);
int be = getPointIndex({ nowTreeNode.bound.z(), nowTreeNode.bound.y()});
int en = getPointIndex({ nowTreeNode.bound.z(), nowTreeNode.bound.w() });
lineIndexs.push_back(be);
lineIndexs.push_back(be);
lineIndexs.push_back(en);
lineIndexs.push_back(en);
int lineIndexBegin = getPointIndex({ nowTreeNode.bound.z(), nowTreeNode.bound.y()});
int lineIndexEnd = getPointIndex({ nowTreeNode.bound.z(), nowTreeNode.bound.w() });
lineIndexs.push_back(lineIndexBegin);
lineIndexs.push_back(lineIndexBegin);
lineIndexs.push_back(lineIndexEnd);
lineIndexs.push_back(lineIndexEnd);
numLine++;
}
for (int& lineIndex : v) {

View File

@ -1,37 +1,37 @@
#include "StraightLine.h"
double StraightLine::getLineValueByT(double t, bool isY) {
float pBe, pEn;
float valueBegin, valueEnd;
if (isY) {
pBe = *vY.begin();
pEn = *vY.rbegin();
valueBegin = *vY.begin();
valueEnd = *vY.rbegin();
}
else {
pBe = *vX.begin();
pEn = *vY.rbegin();
valueBegin = *vX.begin();
valueEnd = *vY.rbegin();
}
return t * (pEn - pBe) + pBe;
return t * (valueEnd - valueBegin) + valueBegin;
}
double StraightLine::findTByValue(double value, bool isY) {
Point be = getPointByIndex(0), en = getPointByIndex(1);
Point pointBegin = getPointByIndex(0), pointEnd = getPointByIndex(1);
if (!isY) {
if(fabs(be.x - en.x) <= eps) return 0;
return (value - be.x) / (en.x - be.x);
if(fabs(pointBegin.x - pointEnd.x) <= eps) return 0;
return (value - pointBegin.x) / (pointEnd.x - pointBegin.x);
}
else {
if (fabs(be.y - en.y) <= eps) return 0;
return (value - be.y) / (en.y - be.y);
if (fabs(pointBegin.y - pointEnd.y) <= eps) return 0;
return (value - pointBegin.y) / (pointEnd.y - pointBegin.y);
}
}
int StraightLine::judgeBoundIntersection(double xy, double l, double r, bool isY) {
Point be = getBegin(), en = getEnd();
Point pointBegin = getBegin(), pointEnd = getEnd();
if (isY) {
swap(be.x, be.y);
swap(en.x, en.y);
swap(pointBegin.x, pointBegin.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)) {
float t = findTByValue(xy, isY);
float value = getLineValueByT(t, !isY);
@ -40,8 +40,8 @@ int StraightLine::judgeBoundIntersection(double xy, double l, double r, bool isY
}
return 0;
} else {
if (be.y <= l && en.y < l) return 0;
if (be.y >= r && en.y > r) return 0;
if (pointBegin.y <= l && pointEnd.y < l) return 0;
if (pointBegin.y >= r && pointEnd.y > r) return 0;
return 1;
}
return 0;