修改了一些精度问题
parent
6ca1b334bf
commit
656fa704a7
|
@ -4,7 +4,7 @@ double CubicBezier::getLineValueByT(double t, bool isY) {
|
||||||
vector<double> p;
|
vector<double> p;
|
||||||
if (isY) p = vY;
|
if (isY) p = vY;
|
||||||
else p = vX;
|
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];
|
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();
|
valueBegin = *vY.begin();
|
||||||
valueEnd = *vY.rbegin();
|
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 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,7 +61,7 @@ Point Line::getEnd() {
|
||||||
}
|
}
|
||||||
|
|
||||||
int Line::direction(bool isY) {
|
int Line::direction(bool isY) {
|
||||||
float valueBegin = *vX.begin(), valueEnd = *vX.rbegin();
|
double valueBegin = *vX.begin(), valueEnd = *vX.rbegin();
|
||||||
if (isY) {
|
if (isY) {
|
||||||
valueBegin = *vY.begin();
|
valueBegin = *vY.begin();
|
||||||
valueEnd = *vY.rbegin();
|
valueEnd = *vY.rbegin();
|
||||||
|
|
|
@ -210,7 +210,7 @@ void ShortCutTree::spliteToShortCutTree() {
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
ShortCutNode seTreeNode, swTreeNode;
|
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);
|
seTreeNode.bound = QVector4D(xMid, nowTreeNode.bound.y(), nowTreeNode.bound.z(), yMid);
|
||||||
isDivided |= handleShortCutNode(nowTreeNode, seTreeNode, segment.first, generatedTreeNodes, sumIncrement);
|
isDivided |= handleShortCutNode(nowTreeNode, seTreeNode, segment.first, generatedTreeNodes, sumIncrement);
|
||||||
swTreeNode.bound = QVector4D(nowTreeNode.bound.x(), nowTreeNode.bound.y(), xMid, yMid);
|
swTreeNode.bound = QVector4D(nowTreeNode.bound.x(), nowTreeNode.bound.y(), xMid, yMid);
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#include "StraightLine.h"
|
#include "StraightLine.h"
|
||||||
|
|
||||||
double StraightLine::getLineValueByT(double t, bool isY) {
|
double StraightLine::getLineValueByT(double t, bool isY) {
|
||||||
float valueBegin, valueEnd;
|
double valueBegin, valueEnd;
|
||||||
if (isY) {
|
if (isY) {
|
||||||
valueBegin = *vY.begin();
|
valueBegin = *vY.begin();
|
||||||
valueEnd = *vY.rbegin();
|
valueEnd = *vY.rbegin();
|
||||||
|
@ -16,11 +16,11 @@ double StraightLine::getLineValueByT(double t, bool isY) {
|
||||||
double StraightLine::findTByValue(double value, bool isY) {
|
double StraightLine::findTByValue(double value, bool isY) {
|
||||||
Point pointBegin = getPointByIndex(0), pointEnd = getPointByIndex(1);
|
Point pointBegin = getPointByIndex(0), pointEnd = getPointByIndex(1);
|
||||||
if (!isY) {
|
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);
|
return (value - pointBegin.x) / (pointEnd.x - pointBegin.x);
|
||||||
}
|
}
|
||||||
else {
|
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);
|
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(pointBegin.x, pointBegin.y);
|
||||||
swap(pointEnd.x, pointEnd.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)) {
|
if (direction(isY)) {
|
||||||
float t = findTByValue(xy, isY);
|
double t = findTByValue(xy, isY);
|
||||||
float 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) {
|
||||||
return 1 + direction(isY);
|
return 1 + direction(isY);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue