You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

457 lines
9.1 KiB
C++

1 month ago
#include "MLFuncom.h"
#include "MLVector.h"
MLFuncom::MLFuncom()
{
}
MLFuncom::~MLFuncom()
{
}
void swap(double& a, double& b)
{
double tmp;
tmp = a;
a = b;
b = tmp;
}
//<2F>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>
bool Equ(double dVal1, double dVal2)
{
if (abs(dVal2 - dVal1) < DOUBLE_ERROR)
return true;
return false;
}
bool Equ(double dVal1, double dVal2, int dot)
{
if (dot == 0)
{
return Equ(dVal1, dVal2);
}
double error = 1.0;
for (int i = 0; i < dot; i++)
{
error *= 0.1;
}
if (fabs(dVal1 - dVal2) <= error)
{
return true;
}
return false;
}
double GetDistance(const MLPlNode& dpt1, const MLPlNode& dpt2)
{
double dxa = dpt2.x - dpt1.x;
double dya = dpt2.y - dpt1.y;
return sqrt(dxa * dxa + dya * dya);
}
double GetDistance(double dx1, double dy1, double dx2, double dy2)
{
return sqrt(pow(dx2 - dx1, 2) + pow(dy2 - dy1, 2));
}
double GetDistance(const MLPlNode& dpt, const MLPlNode& dpt1, const MLPlNode& dpt2, MLPlNode& dptDest)
{
MLPoint ptDest;
double dis = GetDistance(dpt.toPoint(), dpt1.toPoint(), dpt2.toPoint(), ptDest);
dptDest = ptDest.toPlNode();
return dis;
}
double GetDistance(const MLPoint& dpt, const MLPoint& dpt1, const MLPoint& dpt2, MLPoint& dptDest)
{
if (Equ(dpt1.x, dpt2.x) && Equ(dpt1.y, dpt2.y))
{
dptDest.x = (dpt1.x + dpt2.x) / 2.0;
dptDest.y = (dpt1.y + dpt2.y) / 2.0;
}
else if (Equ(dpt1.x, dpt2.x))
{
dptDest.x = (dpt1.x + dpt2.x) / 2.0;
dptDest.y = dpt.y;
}
else if (Equ(dpt1.y, dpt2.y))
{
dptDest.x = dpt.x;
dptDest.y = (dpt1.y + dpt2.y) / 2.0;
}
else
{
double slope1 = (dpt2.y - dpt1.y) / (dpt2.x - dpt1.x);
double slope2 = -1.0 / slope1; // <20><><EFBFBD><EFBFBD>б<EFBFBD>ʵ<EFBFBD><CAB5><EFBFBD>ֱ<EFBFBD><D6B1>б<EFBFBD>ʵĸ<CAB5><C4B8><EFBFBD><EFBFBD><EFBFBD>
dptDest.x = (dpt.y - dpt1.y + slope1 * dpt1.x - slope2 * dpt.x) / (slope1 - slope2);
dptDest.y = slope1 * (dptDest.x - dpt1.x) + dpt1.y;
}
if (abs(dpt2.x - dpt1.x) > abs(dpt2.y - dpt1.y))
{
if (dpt1.x > dpt2.x)
{
if (dptDest.x < dpt2.x)
dptDest = dpt2;
else if (dptDest.x > dpt1.x)
dptDest = dpt1;
}
else
{
if (dptDest.x < dpt1.x)
dptDest = dpt1;
else if (dptDest.x > dpt2.x)
dptDest = dpt2;
}
}
else
{
if (dpt1.y > dpt2.y)
{
if (dptDest.y < dpt2.y)
dptDest = dpt2;
else if (dptDest.y > dpt1.y)
dptDest = dpt1;
}
else
{
if (dptDest.y < dpt1.y)
dptDest = dpt1;
else if (dptDest.y > dpt2.y)
dptDest = dpt2;
}
}
return GetDistance(dpt, dptDest);
}
int LineLine(double L1x1, double L1y1, double L1x2, double L1y2, double* L2x1, double* L2y1, double* L2x2, double* L2y2, bool bExtend1 /*= false*/)
{
/*
0 <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֱ<EFBFBD>߶β<EFBFBD><EFBFBD>
1 <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֱ<EFBFBD>߶<EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͨ<EFBFBD><EFBFBD>(*L2x1,*L2y1)<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2 <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֱ<EFBFBD>߶β<EFBFBD><EFBFBD>ֺ<EFBFBD><EFBFBD>غ<EFBFBD>,<EFBFBD>غ϶ε<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֱ<EFBFBD>ͨ<EFBFBD><EFBFBD>(*L2x1,*L2y1)<EFBFBD><EFBFBD>(*L2x2,*L2y2)<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*/
double xx1, xx2, yy1, yy2;
double x1, x2, y1, y2, n1, n2, n3, n4;
double k1, k2;
double oldx = *L2x1;
double oldy = *L2y1;
//<2F><><EFBFBD>µ<EFBFBD>һ<EFBFBD><D2BB>ֱ<EFBFBD>߶ε<DFB6><CEB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E3B0B4>Խ<EFBFBD><D4BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С<EFBFBD><D0A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD>(xx1,yy1)<29><>(xx2,yy2)<29><>
if (L1x1 > L1x2)
{
xx1 = L1x2;
xx2 = L1x1;
yy1 = L1y2;
yy2 = L1y1;
}
else
{
xx1 = L1x1;
xx2 = L1x2;
yy1 = L1y1;
yy2 = L1y2;
}
if (fabs(xx1 - xx2) <= 0. && fabs(yy1 - yy2) < 0.) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һֱ<D2BB>߶<EFBFBD><DFB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬ,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>0 (<28><><EFBFBD>ཻ)
return 0;
//<2F><><EFBFBD>µڶ<C2B5><DAB6><EFBFBD>ֱ<EFBFBD>߶ε<DFB6><CEB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E3B0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С<EFBFBD><D0A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD>(x1,y1)<29><>(x2,y2)<29><>
if (*L2x1 > *L2x2)
{
x1 = *L2x2;
x2 = *L2x1;
y1 = *L2y2;
y2 = *L2y1;
}
else
{
x1 = *L2x1;
x2 = *L2x2;
y1 = *L2y1;
y2 = *L2y2;
}
if (fabs(x1 - x2) <= 0. && fabs(y1 - y2) < 0.) //<2F><><EFBFBD><EFBFBD><EFBFBD>ڶ<EFBFBD>ֱ<EFBFBD>߶<EFBFBD><DFB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬ,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>0 (<28><><EFBFBD>ཻ)
return 0;
if (fabs(x1 - x2) <= 0. && fabs(xx1 - xx2) <= 0.)//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֱ<EFBFBD>߶<EFBFBD><DFB6>Ǽ<EFBFBD>ֱ<EFBFBD><D6B1>
{
if (x1 != xx1) // <20><><EFBFBD><EFBFBD>ƽ<EFBFBD>м<EFBFBD>ֱ<EFBFBD>ߵĺ<DFB5><C4BA><EFBFBD><EFBFBD>겻ͬ,<2C><><EFBFBD><EFBFBD>ֱ<EFBFBD>߲<EFBFBD><DFB2>
return 0;
*L2x1 = x1; //<2F>õ<EFBFBD><C3B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĺ<EFBFBD><C4BA><EFBFBD><EFBFBD><EFBFBD>
n1 = MIN(yy1, yy2); //<2F><>һ<EFBFBD><D2BB>ֱ<EFBFBD>߶ε<DFB6><CEB5><EFBFBD>С<EFBFBD><D0A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
n2 = MAX(yy1, yy2); //<2F><>һ<EFBFBD><D2BB>ֱ<EFBFBD>߶ε<DFB6><CEB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
n3 = MIN(y1, y2); //<2F>ڶ<EFBFBD><DAB6><EFBFBD>ֱ<EFBFBD>߶ε<DFB6><CEB5><EFBFBD>С<EFBFBD><D0A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
n4 = MAX(y1, y2); //<2F>ڶ<EFBFBD><DAB6><EFBFBD>ֱ<EFBFBD>߶ε<DFB6><CEB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if (n1 > n4 || n2 < n3) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬ<EFBFBD>ļ<EFBFBD>ֱ<EFBFBD><D6B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD>н<EFBFBD><D0BD><EFBFBD>,<2C><><EFBFBD><EFBFBD>ֱ<EFBFBD>߲<EFBFBD><DFB2>
return 0;
else if (n1 == n4 || n2 == n3) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬ<EFBFBD>ļ<EFBFBD>ֱ<EFBFBD><D6B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ཻ(<28><><EFBFBD><EFBFBD>)
{
if (n1 == n4) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>ֱ<EFBFBD>ߵĿ<DFB5><C4BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڶ<EFBFBD><DAB6><EFBFBD>ֱ<EFBFBD>ߵ<EFBFBD><DFB5>յ<EFBFBD><D5B5><EFBFBD>ͬ
{
*L2y1 = n1;
return 1;
}
if (n2 == n3) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>ֱ<EFBFBD>ߵ<EFBFBD><DFB5>յ<EFBFBD><D5B5><EFBFBD><EFBFBD>ڶ<EFBFBD><DAB6><EFBFBD>ֱ<EFBFBD>ߵ<EFBFBD><DFB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬ
{
*L2y1 = n2;
return 1;
}
}
else //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֱ<EFBFBD>ߵ<EFBFBD><DFB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ص<EFBFBD>
{
*L2x2 = x1;
*L2y1 = MAX(n1, n3); //<2F>ص<EFBFBD>ֱ<EFBFBD>߶ε<DFB6><CEB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*L2y2 = MIN(n2, n4); //<2F>ص<EFBFBD>ֱ<EFBFBD>߶ε<DFB6><CEB5>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD>
return 2;
}
}
else if (fabs(x1 - x2) <= 0. && xx1 != xx2) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>ֱ<EFBFBD><D6B1><EFBFBD><EFBFBD>б<EFBFBD><D0B1>,<2C>ڶ<EFBFBD><DAB6><EFBFBD>ֱ<EFBFBD><D6B1><EFBFBD>Ǽ<EFBFBD>ֱ<EFBFBD><D6B1>
{
*L2x1 = x1; //<2F>õ<EFBFBD><C3B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĺ<EFBFBD><C4BA><EFBFBD><EFBFBD><EFBFBD>
//if (!(x1 >= xx1 && x1 <= xx2) || !bExtend1) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><C3BB><EFBFBD>ڵ<EFBFBD>һ<EFBFBD><D2BB>ֱ<EFBFBD>߶εĺ<CEB5><C4BA><EFBFBD><EFBFBD>Χ<EAB7B6><CEA7>,<2C><EFBFBD><E0B2BB>
// return 0;
if (!(x1 >= xx1 && x1 <= xx2) || &bExtend1) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><C3BB><EFBFBD>ڵ<EFBFBD>һ<EFBFBD><D2BB>ֱ<EFBFBD>߶εĺ<CEB5><C4BA><EFBFBD><EFBFBD>Χ<EAB7B6><CEA7>,<2C><EFBFBD><E0B2BB>
return 0;
*L2y1 = yy1 + (x1 - xx1) / (xx2 - xx1)*(yy2 - yy1);//<2F><><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD><C3B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if ((*L2y1 >= y1 && *L2y1 <= y2 || *L2y1 >= y2 && *L2y1 <= y1))//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڵڶ<DAB5><DAB6><EFBFBD>ֱ<EFBFBD>߶<EFBFBD><DFB6><EFBFBD><EFBFBD>Χ<EAB7B6><CEA7>
return 1;
else
{
// Ҫ<>ָ<EFBFBD>һ<EFBFBD>£<EFBFBD><C2A3><EFBFBD>Ϊ<EFBFBD><CEAA>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>п<EFBFBD><D0BF><EFBFBD>Ҫ<EFBFBD>õ<EFBFBD>
*L2x1 = oldx;
*L2y1 = oldy;
return 0;
}
}
else if ((x1 != x2) && fabs(xx1 - xx2) <= 0.)
{
*L2x1 = xx1;
if (!(xx1 >= x1 && xx1 <= x2)) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><C3BB><EFBFBD>ڵڶ<DAB5><DAB6><EFBFBD>ֱ<EFBFBD>߶εĺ<CEB5><C4BA><EFBFBD><EFBFBD>Χ<EAB7B6><CEA7>,<2C><EFBFBD><E0B2BB>
return 0;
*L2y1 = y1 + (xx1 - x1) / (x2 - x1)*(y2 - y1);//<2F><><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD><C3B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if (bExtend1)
{
return 1;
}
if ((*L2y1 >= yy1 && *L2y1 <= yy2 || *L2y1 >= yy2 && *L2y1 <= yy1))//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD>һ<EFBFBD><D2BB>ֱ<EFBFBD>߶<EFBFBD><DFB6><EFBFBD><EFBFBD>Χ<EAB7B6><CEA7>
return 1;
else
{
// Ҫ<>ָ<EFBFBD>һ<EFBFBD>£<EFBFBD><C2A3><EFBFBD>Ϊ<EFBFBD><CEAA>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>п<EFBFBD><D0BF><EFBFBD>Ҫ<EFBFBD>õ<EFBFBD>
*L2x1 = oldx;
*L2y1 = oldy;
return 0;
}
}
else //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD><D0B1>
{
//<2F>õ<EFBFBD><C3B5><EFBFBD><EFBFBD><EFBFBD>ֱ<EFBFBD>ߵ<EFBFBD>б<EFBFBD><D0B1>
k1 = (y2 - y1) / (x2 - x1);
k2 = (yy2 - yy1) / (xx2 - xx1);
if (k1 == k2) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֱ<EFBFBD><D6B1>ƽ<EFBFBD><C6BD>
{
if (x1 > xx2 || x2 < xx1) //<2F><><EFBFBD><EFBFBD>ֱ<EFBFBD>ߺ<EFBFBD><DFBA><EFBFBD><EFBFBD><EFBFBD>ص<EFBFBD>
return 0;
else
{
//<2F><><EFBFBD>·ֱ<C2B7><D6B1>õ<EFBFBD>ͬһ<CDAC><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>x1<78><31>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֱ<EFBFBD><D6B1><EFBFBD>ϵ<EFBFBD><CFB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
n1 = y1 + (0 - x1)*k1;
n2 = yy1 + (0 - x1)*k2;
if (n1 != n2)
return 0;
else
{
n3 = MAX(xx1, x1);
n4 = MIN(xx2, x2);
*L2x1 = n3;
*L2y1 = y1 + (n3 - x1)*k1;
if (n3 == n4)
return 1;
else
{
*L2x2 = n4;
*L2y2 = y1 + (n4 - x1)*k1;
return 2;
}
}
}
}
else ////<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֱ<EFBFBD>߲<EFBFBD>ƽ<EFBFBD><C6BD>
{
*L2x1 = (yy1 - y1 + x1 * k1 - xx1 * k2) / (k1 - k2); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*L2y1 = y1 + (*L2x1 - x1)*k1; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if (bExtend1)//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һֱ<D2BB>߶<EFBFBD><DFB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӳ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڵڶ<DAB5>ֱ<EFBFBD>߶<EFBFBD><DFB6><EFBFBD>
{
if (*L2x1 >= x1 && *L2x1 <= x2)
return 1;
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֱ<EFBFBD>߶εĺ<CEB5><C4BA><EFBFBD><EFBFBD>Χ<EAB7B6><CEA7>
if ((*L2x1 >= x1 && *L2x1 <= x2) && (*L2x1 >= xx1 && *L2x1 <= xx2))
return 1;
else
{
// Ҫ<>ָ<EFBFBD>һ<EFBFBD>£<EFBFBD><C2A3><EFBFBD>Ϊ<EFBFBD><CEAA>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>п<EFBFBD><D0BF><EFBFBD>Ҫ<EFBFBD>õ<EFBFBD>
*L2x1 = oldx;
*L2y1 = oldy;
return 0;
}
}
}
return 0;
}
bool ptInRect(const MLRect& Rect, double dbx, double dby)
{
if (dbx > Rect.left&& dbx <Rect.right && dby > Rect.bottom && dby < Rect.top)
return true;
return false;
}
//<2F><><EFBFBD><EFBFBD>
int bs(double dbKey, MLPline& pline, int nKey/*=3*/)
{
int num = pline.getCount();
int i1, i2, i;
i1 = 0; i2 = num - 1;
if (nKey == 3)
{
if (pline.getTailPt().l >= pline.getHeadPt().l)
{
if (dbKey > pline.getTailPt().l)return num + 100;
if (dbKey < pline.getHeadPt().l)return -100;
}
else if (pline.getTailPt().l < pline.getHeadPt().l)
{
if (dbKey < pline.getTailPt().l)return num + 100;
if (dbKey > pline.getHeadPt().l)return -100;
}
if (fabs(dbKey - pline.getHeadPt().l) < 1e-10)return 0;
if (fabs(dbKey - pline.getTailPt().l) < 1e-10)return i2 - 1;
while (i2 - i1 > 1)
{
i = (i1 + i2) / 2;
if ((dbKey - pline[i].l)*(dbKey - pline[i2].l) > 1e-10)
i2 = i;
else
i1 = i;
}
}
return i1;
}
double CZ(double x0, double x1, double x2, double y1, double y2)
{
double s;
s = x2 - x1;
if (fabs(s) < 1e-30)
return y1;
s = y1 + (y2 - y1) / s * (x0 - x1);
return s;
}
double cz(double dbKey, int nIndex, MLPline& pline, int nKey1, int nKey2)
{
double dbVable1 = 0.0, dbVable2 = 0.0;
double dbKey1 = 0.0, dbKey2 = 0.0;
int nKey = nIndex;
if (nKey1 == 3)
{
dbKey1 = pline[nKey].l;
dbKey2 = pline[nKey + 1].l;
}
/*if(nKey1 ==4)
{
dbKey1 = pline[nKey].s;
dbKey2 = pline[nKey+1].s;
}*/
if (nKey2 == 0)
{
dbVable1 = pline[nKey].x;
dbVable2 = pline[nKey + 1].x;
}
if (nKey2 == 1)
{
dbVable1 = pline[nKey].y;
dbVable2 = pline[nKey + 1].y;
}
return CZ(dbKey, dbKey1, dbKey2, dbVable1, dbVable2);
}
// <20>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֮<EFBFBD><D6AE><EFBFBD><EFBFBD>ϵ
bool CrossRtRt(const MLRect& rect1, const MLRect& rect2)
{
int nx1, ny1, nx2, ny2;
int nx3, ny3, nx4, ny4;
nx1 = rect1.left;
ny1 = rect1.top;
nx2 = rect1.right;
ny2 = rect1.bottom;
nx3 = rect2.left;
ny3 = rect2.top;
nx4 = rect2.right;
ny4 = rect2.bottom;
int m = (nx1 > nx4) | (nx2 < nx3);
int n = (ny2 > ny3) | (ny1 < ny4);
if (m | n)
return false; //<2F><><EFBFBD>
else
return true; //<2F>
//return false;
}
QString ToString(int nVal)
{
QString strVal = QString("%1").arg(nVal);
return strVal;
}
QString ToString(double dVal)
{
QString strVal = QString("%1").arg(dVal);
return strVal;
}
QString ToString(double dVal, int nDotNum)
{
QString strVal = QString("%1").arg(dVal, 0, 'f', nDotNum);
return strVal;
}