diff --git a/ArchitectureColoredPainting/CubicBezier.cpp b/ArchitectureColoredPainting/CubicBezier.cpp index d9e4caf..2ca4425 100644 --- a/ArchitectureColoredPainting/CubicBezier.cpp +++ b/ArchitectureColoredPainting/CubicBezier.cpp @@ -4,7 +4,7 @@ double CubicBezier::getLineValueByT(double t, bool isY) { vector p; if (isY) p = vY; else p = vX; - float pt = 1 - t; + double pt = 1 - t; return pt * pt * pt * p[0] + 3 * t * pt * pt * p[1] + 3 * t * t * pt * p[2] + t * t * t * p[3]; } @@ -106,7 +106,7 @@ int CubicBezier::judgeBoundIntersection(double xy, double l, double r, bool isY) valueBegin = *vY.begin(); valueEnd = *vY.rbegin(); } - if ((valueBegin - xy) * (valueEnd - xy) >= eps) return 0; + if ((valueBegin - xy) * (valueEnd - xy) >= 0) return 0; double t = findTByValue(xy, isY); double value = getLineValueByT(t, !isY); if (l <= value && value <= r && fabs(t) > eps && fabs(1 - t) > eps) { diff --git a/ArchitectureColoredPainting/Line.cpp b/ArchitectureColoredPainting/Line.cpp index 7a166b4..53a4e02 100644 --- a/ArchitectureColoredPainting/Line.cpp +++ b/ArchitectureColoredPainting/Line.cpp @@ -23,7 +23,7 @@ vector Line::toPointVector() const { Point Line::operator[](int index) const { return { vX[index], vY[index] }; } - + Point Line::getPointByIndex(int index) const { return operator[](index); } @@ -61,7 +61,7 @@ Point Line::getEnd() { } int Line::direction(bool isY) { - float valueBegin = *vX.begin(), valueEnd = *vX.rbegin(); + double valueBegin = *vX.begin(), valueEnd = *vX.rbegin(); if (isY) { valueBegin = *vY.begin(); valueEnd = *vY.rbegin(); diff --git a/ArchitectureColoredPainting/ShortCutTree.cpp b/ArchitectureColoredPainting/ShortCutTree.cpp index 5eed0b1..94c3ecd 100644 --- a/ArchitectureColoredPainting/ShortCutTree.cpp +++ b/ArchitectureColoredPainting/ShortCutTree.cpp @@ -210,7 +210,7 @@ void ShortCutTree::spliteToShortCutTree() { } else { ShortCutNode seTreeNode, swTreeNode; - float xMid = (nowTreeNode.bound.x() + nowTreeNode.bound.z()) / 2; + float xMid = (nowTreeNode.bound.x() + nowTreeNode.bound.z()) / 2+1e-5; seTreeNode.bound = QVector4D(xMid, nowTreeNode.bound.y(), nowTreeNode.bound.z(), yMid); isDivided |= handleShortCutNode(nowTreeNode, seTreeNode, segment.first, generatedTreeNodes, sumIncrement); swTreeNode.bound = QVector4D(nowTreeNode.bound.x(), nowTreeNode.bound.y(), xMid, yMid); diff --git a/ArchitectureColoredPainting/StraightLine.cpp b/ArchitectureColoredPainting/StraightLine.cpp index 3a609f1..606e4af 100644 --- a/ArchitectureColoredPainting/StraightLine.cpp +++ b/ArchitectureColoredPainting/StraightLine.cpp @@ -1,7 +1,7 @@ #include "StraightLine.h" double StraightLine::getLineValueByT(double t, bool isY) { - float valueBegin, valueEnd; + double valueBegin, valueEnd; if (isY) { valueBegin = *vY.begin(); valueEnd = *vY.rbegin(); @@ -16,11 +16,11 @@ double StraightLine::getLineValueByT(double t, bool isY) { double StraightLine::findTByValue(double value, bool isY) { Point pointBegin = getPointByIndex(0), pointEnd = getPointByIndex(1); if (!isY) { - if(fabs(pointBegin.x - pointEnd.x) <= eps) return 0; + if(fabs(pointBegin.x - pointEnd.x) <= eps) return 0.0; return (value - pointBegin.x) / (pointEnd.x - pointBegin.x); } else { - if (fabs(pointBegin.y - pointEnd.y) <= eps) return 0; + if (fabs(pointBegin.y - pointEnd.y) <= eps) return 0.0; return (value - pointBegin.y) / (pointEnd.y - pointBegin.y); } } @@ -31,10 +31,10 @@ int StraightLine::judgeBoundIntersection(double xy, double l, double r, bool isY swap(pointBegin.x, pointBegin.y); swap(pointEnd.x, pointEnd.y); } - if ((pointBegin.x - xy) * (pointEnd.x - xy) >= eps) return 0; + if ((pointBegin.x - xy) * (pointEnd.x - xy) >= 0) return 0; if (direction(isY)) { - float t = findTByValue(xy, isY); - float value = getLineValueByT(t, !isY); + double t = findTByValue(xy, isY); + double value = getLineValueByT(t, !isY); if (l <= value && value <= r && fabs(t) > eps && fabs(1-t) > eps) { return 1 + direction(isY); }