添加注释

dev-VirtualTexture
yang.yongquan 2023-01-23 23:16:44 +08:00
parent 4f9720ba89
commit da2cda55e5
3 changed files with 12 additions and 6 deletions

View File

@ -14,6 +14,8 @@ Line::Line(vector<Point> Vp) {
vX.push_back(now.x); vX.push_back(now.x);
vY.push_back(now.y); vY.push_back(now.y);
} }
if (*vY.rbegin() < vY[0]) leftType = 0;
else leftType = 1;
} }
int Line::size() { int Line::size() {
@ -127,11 +129,12 @@ Point Line::getMinDistancePointOnSide(double xy, double l, double r, bool isY) {
} }
int Line::getPointSideOfLine(Point p) { int Line::getPointSideOfLine(Point p) {
// 1 为左侧, 2 为右侧 //0 为在线上, 1 为左侧, 2 为右侧
double z = (p.x - vX[0]) * (*vY.rbegin() - vY[0]) - (p.y - vY[0]) * (*vX.rbegin() - vX[0]); double t = findTByValue(p.y, true);
if (z == 0) return 0; double x = getLineValueByT(t, false);
else if(z>0) return 1; if (fabs(x - p.x) <= eps) return 0;
else return 2; else if (x < p.x) return 1 + (leftType == 1);
else return 1 + (leftType == 0);
} }
bool Line::judgeOneSideIntersectionWithWidth(double xy, double l, double r, bool isY, double width, int type) { bool Line::judgeOneSideIntersectionWithWidth(double xy, double l, double r, bool isY, double width, int type) {

View File

@ -35,9 +35,10 @@ namespace Renderer
class Line class Line
{ {
// leftType 为 1 左侧向右有一个交点, 0 没有交点
protected: protected:
std::vector<double> vX, vY; std::vector<double> vX, vY;
int siz; int siz, leftType;
public: public:
typedef std::shared_ptr<Line> LinePtr; typedef std::shared_ptr<Line> LinePtr;
Line() :siz(0) {} Line() :siz(0) {}
@ -52,6 +53,7 @@ namespace Renderer
virtual int judgeOneSideIntersection(double xy, double l, double r, bool isY) = 0; virtual int judgeOneSideIntersection(double xy, double l, double r, bool isY) = 0;
virtual double getMinDistanceFromPoint(Point p) = 0; virtual double getMinDistanceFromPoint(Point p) = 0;
bool judgeOneSideIntersectionWithWidth(double xy, double l, double r, bool isY, double width, int type); bool judgeOneSideIntersectionWithWidth(double xy, double l, double r, bool isY, double width, int type);
virtual double findTByValue(double value, bool isY) = 0;
bool judgeIntersectionWithWidth(QVector4D bound, double width, int type); bool judgeIntersectionWithWidth(QVector4D bound, double width, int type);
bool judgeIntersection(QVector4D bound); bool judgeIntersection(QVector4D bound);
int getPointSideOfLine(Point p); int getPointSideOfLine(Point p);

View File

@ -218,6 +218,7 @@ void LineTree::spliteToLineTree() {
} }
void LineTree::buildLineTree(std::vector<PointVector>& lineSet, double width, int type) { void LineTree::buildLineTree(std::vector<PointVector>& lineSet, double width, int type) {
// lineTpye 为 0 两侧, 1 为逆时针方向左侧, 2 为逆时针右侧
init(); init();
lineWidth = width; lineWidth = width;
lineType = type; lineType = type;