isOnLine method
dynamic
isOnLine(
- dynamic kx,
- dynamic ky,
- dynamic kw,
- dynamic kh,
- dynamic lineType,
- dynamic draw,
- dynamic pro,
- dynamic px,
- dynamic py,
Implementation
isOnLine(kx, ky, kw, kh, lineType, draw, pro, px, py) {
num x1 = 0, y1 = 0, x2 = 0, y2 = 0, x3 = 0, y3 = 0, y4 = 0, k = 0, b = 0;
var j = 0, jl = 0, inPointI = -1, wc = 13; //允许的误差
bool inPoint = false, inline = false, inRect = false;
var point = draw['p'];
var pointxy = [];
if (lineType == Line['ZX']) {
if (point.length >= 2) {
x1 = draw['startPoint']['x'];
y1 = draw['startPoint']['y'];
x2 = draw['stopPoint']['x'];
y2 = draw['stopPoint']['y'];
pointxy = [
{'x': x1, 'y': y1},
{'x': x2, 'y': y2},
];
//端点检测
j = 0;
jl = pointxy.length;
for (; j < jl; j++) {
if ((px - pointxy[j]['x']).abs() < wc &&
(py - pointxy[j]['y']).abs() < wc) {
inPoint = true;
inPointI = j;
return {
'inline': inline,
'inPoint': inPoint,
'inPointI': inPointI,
'point': pointxy
};
}
}
//x1 x2
k = (y2 - y1) / (x2 - x1);
b = y1 - k * x1;
//线上检测
inline = (py - (k * px + b)).abs() < wc;
if (inline) {
return {
'inline': inline,
'inPoint': inPoint,
'inPointI': inPointI,
'point': pointxy
};
}
return {
'inline': inline,
'inPoint': inPoint,
'inPointI': inPointI,
'point': pointxy
};
}
} else if (lineType == Line['SPZX']) {
if (point.length >= 1) {
pointxy = [draw['startPoint']];
// 端点检测范围
if ((px - draw['startPoint']['x']).abs() < wc &&
(py - draw['startPoint']['y']).abs() < wc) {
inPoint = true;
inPointI = 0;
return {
'inline': inline,
'inPoint': inPoint,
'inPointI': inPointI,
'point': pointxy
};
}
// 线上检测范围
inline = (py - draw['startPoint']['y']).abs() < wc;
return {
'inline': inline,
'inPoint': inPoint,
'inPointI': inPointI,
'point': pointxy
};
}
} else if (lineType == Line['CZZX']) {
if (point.length >= 1) {
pointxy = [draw['startPoint']];
// 端点检测范围
if ((px - draw['startPoint']['x']).abs() < wc &&
(py - draw['startPoint']['y']).abs() < wc) {
inPoint = true;
inPointI = 0;
return {
'inline': inline,
'inPoint': inPoint,
'inPointI': inPointI,
'point': pointxy
};
}
// 线上检测范围
inline = (px - draw['startPoint']['x']).abs() < wc;
return {
'inline': inline,
'inPoint': inPoint,
'inPointI': inPointI,
'point': pointxy
};
}
} else if (lineType == Line['XD']) {
if (point.length >= 2) {
pointxy = [draw['startPoint'], draw['stopPoint']];
// 端点检测范围
if ((px - draw['startPoint']['x']).abs() < wc &&
(py - draw['startPoint']['y']).abs() < wc) {
inPoint = true;
inPointI = 0;
return {
'inline': inline,
'inPoint': inPoint,
'inPointI': inPointI,
'point': pointxy
};
}
if ((px - draw['stopPoint']['x']).abs() < wc &&
(py - draw['stopPoint']['y']).abs() < wc) {
inPoint = true;
inPointI = 1;
return {
'inline': inline,
'inPoint': inPoint,
'inPointI': inPointI,
'point': pointxy
};
}
if (draw['startPoint']['x'] == draw['stopPoint']['x']) {
//竖线
inline = (px - draw['stopPoint']['x']).abs() < wc;
} else if (draw['startPoint']['y'] == draw['stopPoint']['y']) {
//横线
inline = (py - draw['stopPoint']['y']).abs() < wc;
} else {
inline = (py - callYfromKb(px, draw)).abs() < wc;
}
inRect = ((py >= draw['startPoint']['y'] &&
py <= draw['stopPoint']['y']) ||
(py >= draw['stopPoint']['y'] &&
py <= draw['startPoint']['y'])) &&
((px >= draw['startPoint']['x'] && px <= draw['stopPoint']['x']) ||
(px >= draw['stopPoint']['x'] &&
px <= draw['startPoint']['x']));
return {
'inline': inline && inRect,
'inPoint': inPoint,
'inPointI': inPointI,
'point': pointxy
};
}
} else if (lineType == Line['JT']) {
//同线段一样 只不过是线段尾部在绘制的时候增加了箭头样子
if (point.length >= 2) {
pointxy = [draw['startPoint'], draw['stopPoint']];
// 端点检测范围
if ((px - draw['startPoint']['x']).abs() < wc &&
(py - draw['startPoint']['y']).abs() < wc) {
inPoint = true;
inPointI = 0;
return {
'inline': inline,
'inPoint': inPoint,
'inPointI': inPointI,
'point': pointxy
};
}
if ((px - draw['stopPoint']['x']).abs() < wc &&
(py - draw['stopPoint']['y']).abs() < wc) {
inPoint = true;
inPointI = 1;
return {
'inline': inline,
'inPoint': inPoint,
'inPointI': inPointI,
'point': pointxy
};
}
if (draw['startPoint']['x'] == draw['stopPoint']['x']) {
//竖线
inline = (px - draw['stopPoint']['x']).abs() < wc;
} else if (draw['startPoint']['y'] == draw['stopPoint']['y']) {
//横线
inline = (py - draw['stopPoint']['y']).abs() < wc;
} else {
inline = (py - callYfromKb(px, draw)).abs() < wc;
}
inRect = ((py >= draw['startPoint']['y'] &&
py <= draw['stopPoint']['y']) ||
(py >= draw['stopPoint']['y'] &&
py <= draw['startPoint']['y'])) &&
((px >= draw['startPoint']['x'] && px <= draw['stopPoint']['x']) ||
(px >= draw['stopPoint']['x'] &&
px <= draw['startPoint']['x']));
return {
'inline': inline && inRect,
'inPoint': inPoint,
'inPointI': inPointI,
'point': pointxy
};
}
} else if (lineType == Line['SPXD']) {
if (point.length >= 2) {
pointxy = [draw['startPoint'], draw['stopPoint']];
// 端点检测范围
if ((px - draw['startPoint']['x']).abs() < wc &&
(py - draw['startPoint']['y']).abs() < wc) {
inPoint = true;
inPointI = 0;
return {
'inline': inline,
'inPoint': inPoint,
'inPointI': inPointI,
'point': pointxy
};
}
if ((px - draw['stopPoint']['x']).abs() < wc &&
(py - draw['stopPoint']['y']).abs() < wc) {
inPoint = true;
inPointI = 1;
return {
'inline': inline,
'inPoint': inPoint,
'inPointI': inPointI,
'point': pointxy
};
}
// 线上检测范围 通过直线方程(k*px+b)求出_x对应的_y 在通过传入的_y和求出的_y做差 <wc 则在线上
inline = (py - draw['startPoint']['y']).abs() < wc;
//线段内范围检测
inRect =
(px >= draw['startPoint']['x'] && px <= draw['stopPoint']['x']) ||
(px >= draw['stopPoint']['x'] && px <= draw['startPoint']['x']);
return {
'inline': inline && inRect,
'inPoint': inPoint,
'inPointI': inPointI,
'point': pointxy
};
}
} else if (lineType == Line['SX']) {
if (point.length >= 2) {
x1 = draw['startPoint']['x'];
y1 = draw['startPoint']['y'];
x2 = draw['stopPoint']['x'];
y2 = draw['stopPoint']['y'];
pointxy = [
{'x': x1, 'y': y1},
{'x': x2, 'y': y2},
];
//端点检测
j = 0;
jl = pointxy.length;
for (; j < jl; j++) {
if ((px - pointxy[j]['x']).abs() < wc &&
(py - pointxy[j]['y']).abs() < wc) {
inPoint = true;
inPointI = j;
return {
'inline': inline,
'inPoint': inPoint,
'inPointI': inPointI,
'point': pointxy
};
}
}
if (y2 <= y1) {
if (x2 <= x1) {
if (px <= x1 && py <= y1) inRect = true;
} else {
if (px >= x1 && py <= y1) inRect = true;
}
} else {
if (x2 <= x1) {
if (px <= x1 && py >= y1) inRect = true;
} else {
if (px >= x1 && py >= y1) inRect = true;
}
}
//x1 x2
k = (y2 - y1) / (x2 - x1);
b = y1 - k * x1;
//线上检测
inline = (py - (k * px + b)).abs() < wc;
if (inline && inRect) {
return {
'inline': inline && inRect,
'inPoint': inPoint,
'inPointI': inPointI,
'point': pointxy
};
}
return {
'inline': inline && inRect,
'inPoint': inPoint,
'inPointI': inPointI,
'point': pointxy
};
}
} else if (lineType == Line['SPSX']) {
if (point.length >= 2) {
pointxy = [draw['startPoint'], draw['stopPoint']];
if (draw['stopPoint']['x'] <= draw['startPoint']['x']) {
if (px <= draw['startPoint']['x']) {
inRect = true;
}
} else {
if (px >= draw['startPoint']['x']) {
inRect = true;
}
}
//端点范围检测
if ((px - draw['startPoint']['x']).abs() < wc &&
(py - draw['startPoint']['y']).abs() < wc) {
inPoint = true;
inPointI = 0;
return {
'inline': inline,
'inPoint': inPoint,
'inPointI': inPointI,
'point': pointxy
};
}
if ((px - draw['stopPoint']['x']).abs() < wc &&
(py - draw['stopPoint']['y']).abs() < wc) {
inPoint = true;
inPointI = 1;
return {
'inline': inline,
'inPoint': inPoint,
'inPointI': inPointI,
'point': pointxy
};
}
//线上范围检测
inline = (py - draw['startPoint']['y']).abs() < wc;
return {
'inline': inline && inRect,
'inPoint': inPoint,
'inPointI': inPointI,
'point': pointxy,
num: point.length
};
}
} else if (lineType == Line['JGX']) {
//和水平射线一样 只不过多了价格
if (point.length >= 1) {
pointxy = [draw['startPoint']];
//端点范围检测
// 端点检测范围
if ((px - draw['startPoint']['x']).abs() < wc &&
(py - draw['startPoint']['y']).abs() < wc) {
inPoint = true;
inPointI = 0;
return {
'inline': inline,
'inPoint': inPoint,
'inPointI': inPointI,
'point': pointxy
};
}
//线上范围检测
inRect = px >= draw['startPoint']['x'] + wc;
inline = (py - draw['startPoint']['y']).abs() < wc;
return {
'inline': inline && inRect,
'inPoint': inPoint,
'inPointI': inPointI,
'point': pointxy,
num: point.length
};
}
} else if (lineType == Line['SJ']) {
if (point.length >= 3) {
x1 = draw['startPoint']['x'];
y1 = draw['startPoint']['y'];
x2 = draw['secondPoint']['x'];
y2 = draw['secondPoint']['y'];
x3 = draw['stopPoint']['x'];
y3 = draw['stopPoint']['y'];
pointxy = [
{'x': x1, 'y': y1},
{'x': x2, 'y': y2},
{'x': x3, 'y': y3}
];
//端点检测
j = 0;
jl = pointxy.length;
for (; j < jl; j++) {
if ((px - pointxy[j]['x']).abs() < wc &&
(py - pointxy[j]['y']).abs() < wc) {
inPoint = true;
inPointI = j;
return {
'inline': inline,
'inPoint': inPoint,
'inPointI': inPointI,
'point': pointxy
};
}
}
//第一条线
callKb(x1, y1, x2, y2, draw);
inRect = ((py >= y1 && py <= y2) || (py >= y2 && py <= y1)) &&
((px >= x1 && px <= x2) || (px >= x2 && px <= x1));
if (draw['startPoint']['x'] == draw['secondPoint']['x']) {
//竖线
inline = (px - draw['secondPoint']['x']).abs() < wc;
} else if (draw['startPoint']['y'] == draw['secondPoint']['y']) {
//横线
inline = (py - draw['secondPoint']['y']).abs() < wc;
} else {
inline = (py - callYfromKb(px, draw)).abs() < wc;
}
if (inline && inRect) {
return {
'inline': inline && inRect,
'inPoint': inPoint,
'inPointI': inPointI,
'point': pointxy
};
}
//第二条线
callKb(x2, y2, x3, y3, draw);
inRect = ((py >= y2 && py <= y3) || (py >= y3 && py <= y2)) &&
((px >= x2 && px <= x3) || (px >= x3 && px <= x2));
if (draw['secondPoint']['x'] == draw['stopPoint']['x']) {
//竖线
inline = (px - draw['stopPoint']['x']).abs() < wc;
} else if (draw['secondPoint']['y'] == draw['stopPoint']['y']) {
//横线
inline = (py - draw['stopPoint']['y']).abs() < wc;
} else {
inline = (py - callYfromKb(px, draw)).abs() < wc;
}
if (inline && inRect) {
return {
'inline': inline && inRect,
'inPoint': inPoint,
'inPointI': inPointI,
'point': pointxy
};
}
//第三条线
callKb(x3, y3, x1, y1, draw);
inRect = ((py >= y3 && py <= y1) || (py >= y1 && py <= y3)) &&
((px >= x3 && px <= x1) || (px >= x1 && px <= x3));
if (draw['startPoint']['x'] == draw['stopPoint']['x']) {
//竖线
inline = (px - draw['stopPoint']['x']).abs() < wc;
} else if (draw['startPoint']['y'] == draw['stopPoint']['y']) {
//横线
inline = (py - draw['stopPoint']['y']).abs() < wc;
} else {
inline = (py - callYfromKb(px, draw)).abs() < wc;
}
if (inline && inRect) {
return {
'inline': inline && inRect,
'inPoint': inPoint,
'inPointI': inPointI,
'point': pointxy
};
}
return {
'inline': inline && inRect,
'inPoint': inPoint,
'inPointI': inPointI,
'point': pointxy
};
}
} else if (lineType == Line['JX']) {
if (point.length >= 2) {
x1 = draw['startPoint']['x'];
y1 = draw['startPoint']['y'];
x2 = draw['stopPoint']['x'];
y2 = draw['stopPoint']['y'];
pointxy = [
{'x': x1, 'y': y1},
{'x': x2, 'y': y2}
];
//端点检测
j = 0;
jl = pointxy.length;
for (; j < jl; j++) {
if ((px - pointxy[j]['x']).abs() < wc &&
(py - pointxy[j]['y']).abs() < wc) {
inPoint = true;
inPointI = j;
return {
'inline': inline,
'inPoint': inPoint,
'inPointI': inPointI,
'point': pointxy
};
}
}
//线上检测 采取坐标判断方式
if ((px >= x1 - 1 && px <= x2 + 1) || (px >= x2 - 1 && px <= x1 + 1)) {
if ((py - y1).abs() < wc || (py - y2).abs() < wc) {
return {
'inline': true,
'inPoint': inPoint,
'inPointI': inPointI,
'point': pointxy
};
}
}
if ((py >= y1 - 1 && py <= y2 + 1) || (py >= y2 - 1 && py <= y1 + 1)) {
if ((px - x1).abs() < wc || (px - x2).abs() < wc) {
return {
'inline': true,
'inPoint': inPoint,
'inPointI': inPointI,
'point': pointxy
};
}
}
return {
'inline': inline,
'inPoint': inPoint,
'inPointI': inPointI,
'point': pointxy
};
}
} else if (lineType == Line['PXSX']) {
if (point.length >= 3) {
x1 = draw['startPoint']['x'];
y1 = draw['startPoint']['y'];
x2 = draw['secondPoint']['x'];
y2 = draw['secondPoint']['y'];
x3 = draw['stopPoint']['x'];
y3 = draw['stopPoint']['y'];
pointxy = [
{'x': x1, 'y': y1},
{'x': x2, 'y': y2},
{'x': x3, 'y': y3}
];
//端点检测
j = 0;
jl = pointxy.length;
for (; j < jl; j++) {
if ((px - pointxy[j]['x']).abs() < wc &&
(py - pointxy[j]['y']).abs() < wc) {
inPoint = true;
inPointI = j;
return {
'inline': inline,
'inPoint': inPoint,
'inPointI': inPointI,
'point': pointxy
};
}
}
if (y2 <= y1) {
if (x2 <= x1) {
if (px <= x1 && py <= y1) inRect = true;
} else {
if (px >= x1 && py <= y1) inRect = true;
}
} else {
if (x2 <= x1) {
if (px <= x1 && py >= y1) inRect = true;
} else {
if (px >= x1 && py >= y1) inRect = true;
}
}
//x1 x2
k = (y2 - y1) / (x2 - x1);
b = y1 - k * x1;
//线上检测
inline = (py - (k * px + b)).abs() < wc;
if (inline && inRect) {
return {
'inline': inline && inRect,
'inPoint': inPoint,
'inPointI': inPointI,
'point': pointxy
};
}
if (y2 <= y1) {
if (x2 <= x1) {
if (px <= x3 && py <= y3) inRect = true;
} else {
if (px >= x3 && py <= y3) inRect = true;
}
} else {
if (x2 <= x1) {
if (px <= x3 && py >= y3) inRect = true;
} else {
if (px >= x3 && py >= y3) inRect = true;
}
}
//x3 不用在计算新的k因为是平行线 只需利用k从新计算b
b = y3 - k * x3;
//线上检测
inline = (py - (k * px + b)).abs() < wc;
if (inline && inRect) {
return {
'inline': inline && inRect,
'inPoint': inPoint,
'inPointI': inPointI,
'point': pointxy
};
}
return {
'inline': inline && inRect,
'inPoint': inPoint,
'inPointI': inPointI,
'point': pointxy
};
}
} else if (lineType == Line['PXZX']) {
if (point.length >= 3) {
x1 = draw['startPoint']['x'];
y1 = draw['startPoint']['y'];
x2 = draw['secondPoint']['x'];
y2 = draw['secondPoint']['y'];
x3 = draw['stopPoint']['x'];
y3 = draw['stopPoint']['y'];
pointxy = [
{'x': x1, 'y': y1},
{'x': x2, 'y': y2},
{'x': x3, 'y': y3}
];
//端点检测
j = 0;
jl = pointxy.length;
for (; j < jl; j++) {
if ((px - pointxy[j]['x']).abs() < wc &&
(py - pointxy[j]['y']).abs() < wc) {
inPoint = true;
inPointI = j;
return {
'inline': inline,
'inPoint': inPoint,
'inPointI': inPointI,
'point': pointxy
};
}
}
//x1 x2
k = (y2 - y1) / (x2 - x1);
b = y1 - k * x1;
//线上检测
inline = (py - (k * px + b)).abs() < wc;
if (inline) {
return {
'inline': inline,
'inPoint': inPoint,
'inPointI': inPointI,
'point': pointxy
};
}
//x3 不用在计算新的k因为是平行线 只需利用k从新计算b
b = y3 - k * x3;
//线上检测
inline = (py - (k * px + b)).abs() < wc;
if (inline) {
return {
'inline': inline,
'inPoint': inPoint,
'inPointI': inPointI,
'point': pointxy
};
}
return {
'inline': inline,
'inPoint': inPoint,
'inPointI': inPointI,
'point': pointxy
};
}
} else if (lineType == Line['TDX']) {
//3个点
if (point.length >= 3) {
x1 = draw['startPoint']['x'];
y1 = draw['startPoint']['y'];
x2 = draw['secondPoint']['x'];
y2 = draw['secondPoint']['y'];
x3 = draw['stopPoint']['x'];
y3 = draw['stopPoint']['y'];
pointxy = [
{'x': x1, 'y': y1},
{'x': x2, 'y': y2},
{'x': x3, 'y': y3}
];
//端点检测
j = 0;
jl = pointxy.length;
for (; j < jl; j++) {
if ((px - pointxy[j]['x']).abs() < wc &&
(py - pointxy[j]['y']).abs() < wc) {
inPoint = true;
inPointI = j;
return {
'inline': inline,
'inPoint': inPoint,
'inPointI': inPointI,
'point': pointxy
};
}
}
//x1 x2 中间线
k = (y2 - y1) / (x2 - x1);
b = y1 - k * x1;
if (draw['startPoint']['x'] == draw['secondPoint']['x']) {
//竖线
inline = (px - draw['secondPoint']['x']).abs() < wc;
} else if (draw['startPoint']['y'] == draw['secondPoint']['y']) {
//横线
inline = (py - draw['secondPoint']['y']).abs() < wc;
} else {
inline = (py - (k * px + b)).abs() < wc;
}
if (inline) {
return {
'inline': inline,
'inPoint': inPoint,
'inPointI': inPointI,
'point': pointxy
};
}
//根据x3位置求出中间线_y位置
var p1 = k * x3 + b;
//根据_y位置和y3求出另外一根线位置
y4 = p1 - (y3 - p1);
//x3 不用在计算新的k因为是平行线 只需利用k从新计算b 通道1
b = y3 - k * x3;
if (draw['startPoint']['x'] == draw['secondPoint']['x']) {
//竖线
inline = (px -
(draw['startPoint']['x'] +
(draw['stopPoint']['x'] - draw['startPoint']['x'])
.abs()))
.abs() <
wc;
} else if (draw['startPoint']['y'] == draw['secondPoint']['y']) {
//横线
inline = (py -
(draw['startPoint']['y'] +
(draw['stopPoint']['y'] - draw['startPoint']['y'])
.abs()))
.abs() <
wc;
} else {
//斜线
inline = (py - (k * px + b)).abs() < wc;
}
if (inline) {
return {
'inline': inline,
'inPoint': inPoint,
'inPointI': inPointI,
'point': pointxy
};
}
b = y4 - k * x3;
if (draw['startPoint']['x'] == draw['secondPoint']['x']) {
//竖线
inline = (px -
(draw['startPoint']['x'] -
(draw['stopPoint']['x'] - draw['startPoint']['x'])
.abs()))
.abs() <
wc;
} else if (draw['startPoint']['y'] == draw['secondPoint']['y']) {
//横线
inline = (py -
(draw['startPoint']['y'] -
(draw['stopPoint']['y'] - draw['startPoint']['y'])
.abs()))
.abs() <
wc;
} else {
//斜线
inline = (py - (k * px + b)).abs() < wc;
}
if (inline) {
return {
'inline': inline,
'inPoint': inPoint,
'inPointI': inPointI,
'point': pointxy
};
}
return {
'inline': inline,
'inPoint': inPoint,
'inPointI': inPointI,
'point': pointxy
};
}
} else if (lineType == Line['FBNQ']) {
if (point.length >= 2) {
x1 = draw['startPoint']['x'];
y1 = draw['startPoint']['y'];
x2 = draw['stopPoint']['x'];
y2 = draw['stopPoint']['y'];
pointxy = [
{'x': x1, 'y': y1},
{'x': x2, 'y': y2}
];
//端点范围检测
j = 0;
jl = pointxy.length;
for (; j < jl; j++) {
if ((px - pointxy[j]['x']).abs() < wc &&
(py - pointxy[j]['y']).abs() < wc) {
inPoint = true;
inPointI = j;
return {
'inline': inline,
'inPoint': inPoint,
'inPointI': inPointI,
'point': pointxy
};
}
}
inline = (py - y1).abs() < wc;
//线上范围检测
var jg = (point[0]['y']- point[1]['y']).abs();
if (jg > 0 && !inline) {
var dic = y2 < y1 ? 1 : -1; // -1 向上画线 1向下画线
dynamic yy, pp;
dic *= 1;
for (var i = 1, il = FBNQP.length - 1; i < il; i++) {
pp = (point[0]['y']) + dic * jg * FBNQP[i];
yy = ky + Tools.priceToY(pro.kYh, pp, pro.kYMin, pro.kScale);
inline = (py - yy).abs() < wc;
if (inline) {
break;
}
}
}
if (!inline) {
inline = (py - y2).abs() < wc;
}
inRect = px >= x1 + wc;
return {
'inline': inline && inRect,
'inPoint': inPoint,
'inPointI': inPointI,
'point': pointxy
};
}
} else if (lineType == Line['FBNQSX']) {
if (point.length >= 2) {
x1 = draw['startPoint']['x'];
y1 = draw['startPoint']['y'];
x2 = draw['stopPoint']['x'];
y2 = draw['stopPoint']['y'];
pointxy = [
{'x': x1, 'y': y1},
{'x': x2, 'y': y2},
];
//端点检测
j = 0;
jl = pointxy.length;
for (; j < jl; j++) {
if ((px - pointxy[j]['x']).abs() < wc &&
(py - pointxy[j]['y']).abs() < wc) {
inPoint = true;
inPointI = j;
return {
'inline': inline,
'inPoint': inPoint,
'inPointI': inPointI,
'point': pointxy
};
}
}
if (y2 <= y1) {
if (x2 <= x1) {
if (px <= x1 && py <= y1) inRect = true;
} else {
if (px >= x1 && py <= y1) inRect = true;
}
} else {
if (x2 <= x1) {
if (px <= x1 && py >= y1) inRect = true;
} else {
if (px >= x1 && py >= y1) inRect = true;
}
}
//x1 x2
k = (y2 - y1) / (x2 - x1);
b = y1 - k * x1;
//线上检测
inline = (py - (k * px + b)).abs() < wc;
if (inline && inRect) {
return {
'inline': inline && inRect,
'inPoint': inPoint,
'inPointI': inPointI,
'point': pointxy
};
}
//斐波那契斜线检测
var fbnqsxdraw = {};
for (var i = 0, il = FBNQSXP.length; i < il; i++) {
fbnqsxdraw['startPoint'] = {
'x': draw['startPoint']['x'],
'y': draw['startPoint']['y']
};
fbnqsxdraw['stopPoint'] = {
'x': draw["sxPoint$i"]['x'],
'y': draw["sxPoint$i"]['y']
};
x1 = fbnqsxdraw['startPoint']['x'];
y1 = fbnqsxdraw['startPoint']['y'];
x2 = fbnqsxdraw['stopPoint']['x'];
y2 = fbnqsxdraw['stopPoint']['y'];
if (y2 <= y1) {
if (x2 <= x1) {
if (px <= x1 && py <= y1) inRect = true;
} else {
if (px >= x1 && py <= y1) inRect = true;
}
} else {
if (x2 <= x1) {
if (px <= x1 && py >= y1) inRect = true;
} else {
if (px >= x1 && py >= y1) inRect = true;
}
}
//x1 x2
k = (y2 - y1) / (x2 - x1);
b = y1 - k * x1;
//线上检测
inline = (py - (k * px + b)).abs() < wc;
if (inline && inRect) {
return {
'inline': inline && inRect,
'inPoint': inPoint,
'inPointI': inPointI,
'point': pointxy
};
}
}
return {
'inline': inline && inRect,
'inPoint': inPoint,
'inPointI': inPointI,
'point': pointxy
};
}
} else {
return {
'inline': inline,
'inPoint': inPoint,
'inPointI': inPointI,
'point': pointxy
};
}
}