From da2cda55e5cd7612f79ad783aa82290230d2d18a Mon Sep 17 00:00:00 2001 From: "yang.yongquan" <3395816735@qq.com> Date: Mon, 23 Jan 2023 23:16:44 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/Renderer/Painting/Line.cpp | 13 ++++++++----- .../src/Renderer/Painting/Line.h | 4 +++- .../src/Renderer/Painting/LineTree.cpp | 1 + 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/ArchitectureColoredPainting/src/Renderer/Painting/Line.cpp b/ArchitectureColoredPainting/src/Renderer/Painting/Line.cpp index 462b32c..f26afd7 100644 --- a/ArchitectureColoredPainting/src/Renderer/Painting/Line.cpp +++ b/ArchitectureColoredPainting/src/Renderer/Painting/Line.cpp @@ -14,6 +14,8 @@ Line::Line(vector Vp) { vX.push_back(now.x); vY.push_back(now.y); } + if (*vY.rbegin() < vY[0]) leftType = 0; + else leftType = 1; } int Line::size() { @@ -127,11 +129,12 @@ Point Line::getMinDistancePointOnSide(double xy, double l, double r, bool isY) { } int Line::getPointSideOfLine(Point p) { - // 1 为左侧, 2 为右侧 - double z = (p.x - vX[0]) * (*vY.rbegin() - vY[0]) - (p.y - vY[0]) * (*vX.rbegin() - vX[0]); - if (z == 0) return 0; - else if(z>0) return 1; - else return 2; + //0 为在线上, 1 为左侧, 2 为右侧 + double t = findTByValue(p.y, true); + double x = getLineValueByT(t, false); + if (fabs(x - p.x) <= eps) return 0; + 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) { diff --git a/ArchitectureColoredPainting/src/Renderer/Painting/Line.h b/ArchitectureColoredPainting/src/Renderer/Painting/Line.h index 75bb0e4..7730fa6 100644 --- a/ArchitectureColoredPainting/src/Renderer/Painting/Line.h +++ b/ArchitectureColoredPainting/src/Renderer/Painting/Line.h @@ -35,9 +35,10 @@ namespace Renderer class Line { + // leftType 为 1 左侧向右有一个交点, 0 没有交点 protected: std::vector vX, vY; - int siz; + int siz, leftType; public: typedef std::shared_ptr LinePtr; Line() :siz(0) {} @@ -52,6 +53,7 @@ namespace Renderer virtual int judgeOneSideIntersection(double xy, double l, double r, bool isY) = 0; virtual double getMinDistanceFromPoint(Point p) = 0; 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 judgeIntersection(QVector4D bound); int getPointSideOfLine(Point p); diff --git a/ArchitectureColoredPainting/src/Renderer/Painting/LineTree.cpp b/ArchitectureColoredPainting/src/Renderer/Painting/LineTree.cpp index b5b9c57..c45897f 100644 --- a/ArchitectureColoredPainting/src/Renderer/Painting/LineTree.cpp +++ b/ArchitectureColoredPainting/src/Renderer/Painting/LineTree.cpp @@ -218,6 +218,7 @@ void LineTree::spliteToLineTree() { } void LineTree::buildLineTree(std::vector& lineSet, double width, int type) { + // lineTpye 为 0 两侧, 1 为逆时针方向左侧, 2 为逆时针右侧 init(); lineWidth = width; lineType = type;