|
@@ -32,8 +32,7 @@ export default class MathUtil {
|
|
|
}
|
|
|
|
|
|
const parametera = (point1.y - point2.y) / (point1.x - point2.x);
|
|
|
- const parameterb =
|
|
|
- (point1.x * point2.y - point2.x * point1.y) / (point1.x - point2.x);
|
|
|
+ const parameterb = (point1.x * point2.y - point2.x * point1.y) / (point1.x - point2.x);
|
|
|
if (this.getFixed(parametera) == 0) {
|
|
|
return { y: this.getFixed(parameterb) };
|
|
|
}
|
|
@@ -82,10 +81,7 @@ export default class MathUtil {
|
|
|
var perpendicularVector = { x: -slope, y: 1 };
|
|
|
|
|
|
// 将垂直向量归一化为单位向量
|
|
|
- var length = Math.sqrt(
|
|
|
- perpendicularVector.x * perpendicularVector.x +
|
|
|
- perpendicularVector.y * perpendicularVector.y
|
|
|
- );
|
|
|
+ var length = Math.sqrt(perpendicularVector.x * perpendicularVector.x + perpendicularVector.y * perpendicularVector.y);
|
|
|
perpendicularVector.x /= length;
|
|
|
perpendicularVector.y /= length;
|
|
|
|
|
@@ -113,9 +109,7 @@ export default class MathUtil {
|
|
|
}
|
|
|
|
|
|
distanceForPoints(point1, point2) {
|
|
|
- return Math.sqrt(
|
|
|
- Math.pow(point1.x - point2.x, 2) + Math.pow(point1.y - point2.y, 2)
|
|
|
- );
|
|
|
+ return Math.sqrt(Math.pow(point1.x - point2.x, 2) + Math.pow(point1.y - point2.y, 2));
|
|
|
}
|
|
|
|
|
|
//与line平行且两条线直接的距离是distance的两条线
|
|
@@ -206,10 +200,7 @@ export default class MathUtil {
|
|
|
if (angle > 180) {
|
|
|
angle = 360 - angle;
|
|
|
}
|
|
|
- if (
|
|
|
- Math.abs((angle1 + angle3) / 2 - angle) <
|
|
|
- Math.abs((angle2 + angle4) / 2 - angle)
|
|
|
- ) {
|
|
|
+ if (Math.abs((angle1 + angle3) / 2 - angle) < Math.abs((angle2 + angle4) / 2 - angle)) {
|
|
|
return { p1: point1, p2: point3 };
|
|
|
} else {
|
|
|
return { p1: point2, p2: point4 };
|
|
@@ -247,10 +238,7 @@ export default class MathUtil {
|
|
|
if (this.isParallel(parameter1, parameter2)) {
|
|
|
return null;
|
|
|
}
|
|
|
- if (
|
|
|
- typeof parameter1.a == "undefined" &&
|
|
|
- typeof parameter2.a != "undefined"
|
|
|
- ) {
|
|
|
+ if (typeof parameter1.a == "undefined" && typeof parameter2.a != "undefined") {
|
|
|
if (parameter1.x) {
|
|
|
return {
|
|
|
x: parameter1.x,
|
|
@@ -262,10 +250,7 @@ export default class MathUtil {
|
|
|
y: parameter1.y,
|
|
|
};
|
|
|
}
|
|
|
- } else if (
|
|
|
- typeof parameter2.a == "undefined" &&
|
|
|
- typeof parameter1.a != "undefined"
|
|
|
- ) {
|
|
|
+ } else if (typeof parameter2.a == "undefined" && typeof parameter1.a != "undefined") {
|
|
|
if (parameter2.x) {
|
|
|
return {
|
|
|
x: parameter2.x,
|
|
@@ -277,16 +262,10 @@ export default class MathUtil {
|
|
|
y: parameter2.y,
|
|
|
};
|
|
|
}
|
|
|
- } else if (
|
|
|
- typeof parameter2.a == "undefined" &&
|
|
|
- typeof parameter1.a == "undefined"
|
|
|
- ) {
|
|
|
+ } else if (typeof parameter2.a == "undefined" && typeof parameter1.a == "undefined") {
|
|
|
if (parameter1.hasOwnProperty("x") && parameter2.hasOwnProperty("y")) {
|
|
|
return { x: parameter1.x, y: parameter2.y };
|
|
|
- } else if (
|
|
|
- parameter1.hasOwnProperty("y") &&
|
|
|
- parameter2.hasOwnProperty("x")
|
|
|
- ) {
|
|
|
+ } else if (parameter1.hasOwnProperty("y") && parameter2.hasOwnProperty("x")) {
|
|
|
return { x: parameter2.x, y: parameter1.y };
|
|
|
} else {
|
|
|
return null;
|
|
@@ -297,11 +276,8 @@ export default class MathUtil {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
- let joinpointx =
|
|
|
- (parameter2.b - parameter1.b) / (parameter1.a - parameter2.a);
|
|
|
- let joinpointy =
|
|
|
- (parameter1.a * parameter2.b - parameter2.a * parameter1.b) /
|
|
|
- (parameter1.a - parameter2.a);
|
|
|
+ let joinpointx = (parameter2.b - parameter1.b) / (parameter1.a - parameter2.a);
|
|
|
+ let joinpointy = (parameter1.a * parameter2.b - parameter2.a * parameter1.b) / (parameter1.a - parameter2.a);
|
|
|
|
|
|
let point = { x: joinpointx, y: joinpointy };
|
|
|
return point;
|
|
@@ -318,17 +294,8 @@ export default class MathUtil {
|
|
|
}
|
|
|
|
|
|
// 线段所在直线的交点坐标 (x , y)
|
|
|
- const x =
|
|
|
- ((b.x - a.x) * (d.x - c.x) * (c.y - a.y) +
|
|
|
- (b.y - a.y) * (d.x - c.x) * a.x -
|
|
|
- (d.y - c.y) * (b.x - a.x) * c.x) /
|
|
|
- denominator;
|
|
|
- const y =
|
|
|
- -(
|
|
|
- (b.y - a.y) * (d.y - c.y) * (c.x - a.x) +
|
|
|
- (b.x - a.x) * (d.y - c.y) * a.y -
|
|
|
- (d.x - c.x) * (b.y - a.y) * c.y
|
|
|
- ) / denominator;
|
|
|
+ const x = ((b.x - a.x) * (d.x - c.x) * (c.y - a.y) + (b.y - a.y) * (d.x - c.x) * a.x - (d.y - c.y) * (b.x - a.x) * c.x) / denominator;
|
|
|
+ const y = -((b.y - a.y) * (d.y - c.y) * (c.x - a.x) + (b.x - a.x) * (d.y - c.y) * a.y - (d.x - c.x) * (b.y - a.y) * c.y) / denominator;
|
|
|
|
|
|
return { x: x, y: y };
|
|
|
}
|
|
@@ -340,12 +307,7 @@ export default class MathUtil {
|
|
|
const x = join.x;
|
|
|
const y = join.y; // 交点在线段1上 且交点也在线段2上
|
|
|
/** 2 判断交点是否在两条线段上 **/
|
|
|
- if (
|
|
|
- (x - a.x) * (x - b.x) <= 0.001 &&
|
|
|
- (y - a.y) * (y - b.y) <= 0.001 &&
|
|
|
- (x - c.x) * (x - d.x) <= 0.001 &&
|
|
|
- (y - c.y) * (y - d.y) <= 0.001
|
|
|
- ) {
|
|
|
+ if ((x - a.x) * (x - b.x) <= 0.001 && (y - a.y) * (y - b.y) <= 0.001 && (x - c.x) * (x - d.x) <= 0.001 && (y - c.y) * (y - d.y) <= 0.001) {
|
|
|
// 返回交点p
|
|
|
return {
|
|
|
x: x,
|
|
@@ -503,8 +465,7 @@ export default class MathUtil {
|
|
|
if (!minDis) {
|
|
|
minDis = Constant.minLen;
|
|
|
}
|
|
|
- let dis1 =
|
|
|
- this.getDistance(startPoint, point) + this.getDistance(endPoint, point);
|
|
|
+ let dis1 = this.getDistance(startPoint, point) + this.getDistance(endPoint, point);
|
|
|
let dis2 = this.getDistance(startPoint, endPoint);
|
|
|
if (Math.abs(dis1 - dis2) < minDis) {
|
|
|
return true;
|
|
@@ -572,8 +533,7 @@ export default class MathUtil {
|
|
|
const xj = pt2.x;
|
|
|
const yj = pt2.y;
|
|
|
|
|
|
- const intersect =
|
|
|
- yi > y != yj > y && x < ((xj - xi) * (y - yi)) / (yj - yi) + xi;
|
|
|
+ const intersect = yi > y != yj > y && x < ((xj - xi) * (y - yi)) / (yj - yi) + xi;
|
|
|
if (intersect) inside = !inside;
|
|
|
}
|
|
|
|
|
@@ -582,9 +542,7 @@ export default class MathUtil {
|
|
|
|
|
|
//a表示横轴,b表示竖轴
|
|
|
isPointInElliptic(point, center, a, b) {
|
|
|
- let r =
|
|
|
- Math.pow((point.x - center.x) / a, 2) +
|
|
|
- Math.pow((point.y - center.y) / b, 2);
|
|
|
+ let r = Math.pow((point.x - center.x) / a, 2) + Math.pow((point.y - center.y) / b, 2);
|
|
|
|
|
|
if (r <= 1) {
|
|
|
return true;
|
|
@@ -602,10 +560,7 @@ export default class MathUtil {
|
|
|
const dis = this.getDistance(point1, point2);
|
|
|
const dis1 = this.getDistance(join, point1);
|
|
|
const dis2 = this.getDistance(join, point2);
|
|
|
- if (
|
|
|
- this.getDistance(join, point1) > dis ||
|
|
|
- this.getDistance(join, point2) > dis
|
|
|
- ) {
|
|
|
+ if (this.getDistance(join, point1) > dis || this.getDistance(join, point2) > dis) {
|
|
|
// 在线段外
|
|
|
if (dis1 < dis2 && dis1 < minDistance) {
|
|
|
return { type: 1, join: point1 };
|
|
@@ -626,10 +581,7 @@ export default class MathUtil {
|
|
|
}
|
|
|
|
|
|
PointInSegment(Q, pi, pj, minDis) {
|
|
|
- if (
|
|
|
- this.getDistance(Q, pi) < Constant.minAdsorbPix ||
|
|
|
- this.getDistance(Q, pj) < Constant.minAdsorbPix
|
|
|
- ) {
|
|
|
+ if (this.getDistance(Q, pi) < Constant.minAdsorbPix || this.getDistance(Q, pj) < Constant.minAdsorbPix) {
|
|
|
return true;
|
|
|
}
|
|
|
|
|
@@ -684,11 +636,7 @@ export default class MathUtil {
|
|
|
const dot_product_AP = AP.x * AB_direction.x + AP.y * AB_direction.y;
|
|
|
const dot_product_BP = BP.x * AB_direction.x + BP.y * AB_direction.y;
|
|
|
//return dot_product_AP >= 0 && dot_product_BP <= 0 && Math.abs(AP.x * BP.y - AP.y * BP.x) <= AB_length * Number.EPSILON;
|
|
|
- return (
|
|
|
- dot_product_AP >= 0 &&
|
|
|
- dot_product_BP <= 0 &&
|
|
|
- Math.abs(AP.x * BP.y - AP.y * BP.x) <= 0.01
|
|
|
- );
|
|
|
+ return dot_product_AP >= 0 && dot_product_BP <= 0 && Math.abs(AP.x * BP.y - AP.y * BP.x) <= 0.01;
|
|
|
}
|
|
|
|
|
|
clonePoint(p1, p2) {
|
|
@@ -747,12 +695,7 @@ export default class MathUtil {
|
|
|
}
|
|
|
const join = this.getIntersectionPoint2(point1, point2, point3, point4);
|
|
|
if (join != null) {
|
|
|
- if (
|
|
|
- this.getDistance(point1, join) > dis &&
|
|
|
- this.getDistance(point2, join) > dis &&
|
|
|
- this.getDistance(point3, join) > dis &&
|
|
|
- this.getDistance(point4, join) > dis
|
|
|
- ) {
|
|
|
+ if (this.getDistance(point1, join) > dis && this.getDistance(point2, join) > dis && this.getDistance(point3, join) > dis && this.getDistance(point4, join) > dis) {
|
|
|
if (
|
|
|
this.getDistance(point1, join) < this.getDistance(point1, point2) &&
|
|
|
this.getDistance(point2, join) < this.getDistance(point1, point2) &&
|
|
@@ -765,10 +708,7 @@ export default class MathUtil {
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
- if (
|
|
|
- this.PointInSegment(point1, point3, point4) ||
|
|
|
- this.PointInSegment(point2, point3, point4)
|
|
|
- ) {
|
|
|
+ if (this.PointInSegment(point1, point3, point4) || this.PointInSegment(point2, point3, point4)) {
|
|
|
return true;
|
|
|
}
|
|
|
}
|
|
@@ -874,8 +814,7 @@ export default class MathUtil {
|
|
|
return 0;
|
|
|
}
|
|
|
let s = points[0].y * (points[point_num - 1].x - points[1].x);
|
|
|
- for (let i = 1; i < point_num; ++i)
|
|
|
- s += points[i].y * (points[i - 1].x - points[(i + 1) % point_num].x);
|
|
|
+ for (let i = 1; i < point_num; ++i) s += points[i].y * (points[i - 1].x - points[(i + 1) % point_num].x);
|
|
|
return Math.abs(s / 2.0);
|
|
|
}
|
|
|
|
|
@@ -883,13 +822,7 @@ export default class MathUtil {
|
|
|
getPolygonCore(points) {
|
|
|
function Area(p0, p1, p2) {
|
|
|
let area = 0.0;
|
|
|
- area =
|
|
|
- p0.x * p1.y +
|
|
|
- p1.x * p2.y +
|
|
|
- p2.x * p0.y -
|
|
|
- p1.x * p0.y -
|
|
|
- p2.x * p1.y -
|
|
|
- p0.x * p2.y;
|
|
|
+ area = p0.x * p1.y + p1.x * p2.y + p2.x * p0.y - p1.x * p0.y - p2.x * p1.y - p0.x * p2.y;
|
|
|
return area / 2;
|
|
|
}
|
|
|
|
|
@@ -1357,15 +1290,9 @@ export default class MathUtil {
|
|
|
|
|
|
let delta;
|
|
|
if (v > 1) {
|
|
|
- delta = this.pointMinus(
|
|
|
- p1,
|
|
|
- this.pointPlus(pt, this.pointScale(this.pointMinus(p2, pt), 1 / v))
|
|
|
- );
|
|
|
+ delta = this.pointMinus(p1, this.pointPlus(pt, this.pointScale(this.pointMinus(p2, pt), 1 / v)));
|
|
|
} else {
|
|
|
- delta = this.pointMinus(
|
|
|
- this.pointPlus(pt, this.pointScale(this.pointMinus(p1, pt), v)),
|
|
|
- p2
|
|
|
- );
|
|
|
+ delta = this.pointMinus(this.pointPlus(pt, this.pointScale(this.pointMinus(p1, pt), v)), p2);
|
|
|
}
|
|
|
delta = this.pointScale(delta, scale);
|
|
|
|
|
@@ -1384,12 +1311,7 @@ export default class MathUtil {
|
|
|
const curves = [];
|
|
|
let preControl1, preControl2;
|
|
|
for (let i = 0; i < points.length - 2; i++) {
|
|
|
- const { control1, control2 } = this.getCurvesControls(
|
|
|
- points[i],
|
|
|
- points[i + 1],
|
|
|
- points[i + 2],
|
|
|
- scale
|
|
|
- );
|
|
|
+ const { control1, control2 } = this.getCurvesControls(points[i], points[i + 1], points[i + 2], scale);
|
|
|
|
|
|
curves.push({
|
|
|
start: points[i],
|
|
@@ -1452,9 +1374,7 @@ export default class MathUtil {
|
|
|
const xs1 = m1 < 0 ? -1 : 1;
|
|
|
const xs2 = m2 < 0 ? -1 : 1;
|
|
|
|
|
|
- t1 =
|
|
|
- (-b - (m1 * xs1) ** (1 / 3) * xs1 - (m2 * xs2) ** (1 / 3) * xs2) /
|
|
|
- (3 * a);
|
|
|
+ t1 = (-b - (m1 * xs1) ** (1 / 3) * xs1 - (m2 * xs2) ** (1 / 3) * xs2) / (3 * a);
|
|
|
// 涉及虚数,可不考虑。i ** 2 = -1
|
|
|
}
|
|
|
|
|
@@ -1473,16 +1393,8 @@ export default class MathUtil {
|
|
|
|
|
|
if (A > 0 && T < 1 && T > -1) {
|
|
|
t1 = (-b - 2 * A ** (1 / 2) * Math.cos(theta / 3)) / (3 * a);
|
|
|
- t2 =
|
|
|
- (-b +
|
|
|
- A ** (1 / 2) *
|
|
|
- (Math.cos(theta / 3) + 3 ** (1 / 2) * Math.sin(theta / 3))) /
|
|
|
- (3 * a);
|
|
|
- t3 =
|
|
|
- (-b +
|
|
|
- A ** (1 / 2) *
|
|
|
- (Math.cos(theta / 3) - 3 ** (1 / 2) * Math.sin(theta / 3))) /
|
|
|
- (3 * a);
|
|
|
+ t2 = (-b + A ** (1 / 2) * (Math.cos(theta / 3) + 3 ** (1 / 2) * Math.sin(theta / 3))) / (3 * a);
|
|
|
+ t3 = (-b + A ** (1 / 2) * (Math.cos(theta / 3) - 3 ** (1 / 2) * Math.sin(theta / 3))) / (3 * a);
|
|
|
}
|
|
|
}
|
|
|
return [t1, t2, t3];
|
|
@@ -1503,16 +1415,8 @@ export default class MathUtil {
|
|
|
const { x: cx1, y: cy1 } = cp1;
|
|
|
const { x: cx2, y: cy2 } = cp2;
|
|
|
|
|
|
- const x =
|
|
|
- x1 * (1 - t) * (1 - t) * (1 - t) +
|
|
|
- 3 * cx1 * t * (1 - t) * (1 - t) +
|
|
|
- 3 * cx2 * t * t * (1 - t) +
|
|
|
- x2 * t * t * t;
|
|
|
- const y =
|
|
|
- y1 * (1 - t) * (1 - t) * (1 - t) +
|
|
|
- 3 * cy1 * t * (1 - t) * (1 - t) +
|
|
|
- 3 * cy2 * t * t * (1 - t) +
|
|
|
- y2 * t * t * t;
|
|
|
+ const x = x1 * (1 - t) * (1 - t) * (1 - t) + 3 * cx1 * t * (1 - t) * (1 - t) + 3 * cx2 * t * t * (1 - t) + x2 * t * t * t;
|
|
|
+ const y = y1 * (1 - t) * (1 - t) * (1 - t) + 3 * cy1 * t * (1 - t) * (1 - t) + 3 * cy2 * t * t * (1 - t) + y2 * t * t * t;
|
|
|
return { x, y };
|
|
|
}
|
|
|
|
|
@@ -1527,16 +1431,8 @@ export default class MathUtil {
|
|
|
// 参数化方式在曲线上取一系列的点
|
|
|
var pointsOnCurve = [];
|
|
|
for (var t = 0; t <= 1; t += 0.01) {
|
|
|
- var x =
|
|
|
- Math.pow(1 - t, 3) * p0.x +
|
|
|
- 3 * Math.pow(1 - t, 2) * t * p1.x +
|
|
|
- 3 * (1 - t) * Math.pow(t, 2) * p2.x +
|
|
|
- Math.pow(t, 3) * p3.x;
|
|
|
- var y =
|
|
|
- Math.pow(1 - t, 3) * p0.y +
|
|
|
- 3 * Math.pow(1 - t, 2) * t * p1.y +
|
|
|
- 3 * (1 - t) * Math.pow(t, 2) * p2.y +
|
|
|
- Math.pow(t, 3) * p3.y;
|
|
|
+ var x = Math.pow(1 - t, 3) * p0.x + 3 * Math.pow(1 - t, 2) * t * p1.x + 3 * (1 - t) * Math.pow(t, 2) * p2.x + Math.pow(t, 3) * p3.x;
|
|
|
+ var y = Math.pow(1 - t, 3) * p0.y + 3 * Math.pow(1 - t, 2) * t * p1.y + 3 * (1 - t) * Math.pow(t, 2) * p2.y + Math.pow(t, 3) * p3.y;
|
|
|
pointsOnCurve.push({ x: x, y: y });
|
|
|
}
|
|
|
|
|
@@ -1544,10 +1440,7 @@ export default class MathUtil {
|
|
|
var shortestDistance = Number.MAX_VALUE;
|
|
|
var closestPoint;
|
|
|
for (var i = 0; i < pointsOnCurve.length; i++) {
|
|
|
- var distance = Math.sqrt(
|
|
|
- Math.pow(pointsOnCurve[i].x - target.x, 2) +
|
|
|
- Math.pow(pointsOnCurve[i].y - target.y, 2)
|
|
|
- );
|
|
|
+ var distance = Math.sqrt(Math.pow(pointsOnCurve[i].x - target.x, 2) + Math.pow(pointsOnCurve[i].y - target.y, 2));
|
|
|
if (distance < shortestDistance) {
|
|
|
shortestDistance = distance;
|
|
|
closestPoint = pointsOnCurve[i];
|
|
@@ -1564,23 +1457,11 @@ export default class MathUtil {
|
|
|
const { x: offsetX, y: offsetY } = position;
|
|
|
let results = [];
|
|
|
// 用 x 求出对应的 t,用 t 求相应位置的 y,再比较得出的 y 与 offsetY 之间的差值
|
|
|
- const tsx = this.getThreeBezierT(
|
|
|
- curve.start.x,
|
|
|
- curve.controls[0].x,
|
|
|
- curve.controls[1].x,
|
|
|
- curve.end.x,
|
|
|
- offsetX
|
|
|
- );
|
|
|
+ const tsx = this.getThreeBezierT(curve.start.x, curve.controls[0].x, curve.controls[1].x, curve.end.x, offsetX);
|
|
|
console.log(tsx);
|
|
|
for (let x = 0; x < 3; x++) {
|
|
|
if (tsx[x] <= 1 && tsx[x] >= 0) {
|
|
|
- const point = this.getThreeBezierPoint(
|
|
|
- tsx[x],
|
|
|
- curve.start,
|
|
|
- curve.controls[0],
|
|
|
- curve.controls[1],
|
|
|
- curve.end
|
|
|
- );
|
|
|
+ const point = this.getThreeBezierPoint(tsx[x], curve.start, curve.controls[0], curve.controls[1], curve.end);
|
|
|
// if (Math.abs(point.y - offsetY) < rang) {
|
|
|
results.push({
|
|
|
position: point,
|
|
@@ -1590,22 +1471,10 @@ export default class MathUtil {
|
|
|
}
|
|
|
}
|
|
|
// 如果上述没有结果,则用 y 求出对应的 t,再用 t 求出对应的 x,与 offsetX 进行匹配
|
|
|
- const tsy = this.getThreeBezierT(
|
|
|
- curve.start.y,
|
|
|
- curve.controls[0].y,
|
|
|
- curve.controls[1].y,
|
|
|
- curve.end.y,
|
|
|
- offsetY
|
|
|
- );
|
|
|
+ const tsy = this.getThreeBezierT(curve.start.y, curve.controls[0].y, curve.controls[1].y, curve.end.y, offsetY);
|
|
|
for (let y = 0; y < 3; y++) {
|
|
|
if (tsy[y] <= 1 && tsy[y] >= 0) {
|
|
|
- const point = this.getThreeBezierPoint(
|
|
|
- tsy[y],
|
|
|
- curve.start,
|
|
|
- curve.controls[0],
|
|
|
- curve.controls[1],
|
|
|
- curve.end
|
|
|
- );
|
|
|
+ const point = this.getThreeBezierPoint(tsy[y], curve.start, curve.controls[0], curve.controls[1], curve.end);
|
|
|
// if (Math.abs(point.x - offsetX) < rang) {
|
|
|
results.push({
|
|
|
position: point,
|
|
@@ -1646,15 +1515,9 @@ export default class MathUtil {
|
|
|
getHitInfoForCurves(pos, curves, roadWidth) {
|
|
|
let joinInfo;
|
|
|
for (const curve of curves) {
|
|
|
- const tempJoinInfo =
|
|
|
- curve.controls.length === 2
|
|
|
- ? this.getHitInfoForThreeBezier(pos, curve, roadWidth / 2)
|
|
|
- : this.getHitInfoForTwoBezier(pos, curve);
|
|
|
-
|
|
|
- if (
|
|
|
- !joinInfo ||
|
|
|
- (tempJoinInfo && tempJoinInfo.distance < joinInfo.distance)
|
|
|
- ) {
|
|
|
+ const tempJoinInfo = curve.controls.length === 2 ? this.getHitInfoForThreeBezier(pos, curve, roadWidth / 2) : this.getHitInfoForTwoBezier(pos, curve);
|
|
|
+
|
|
|
+ if (!joinInfo || (tempJoinInfo && tempJoinInfo.distance < joinInfo.distance)) {
|
|
|
joinInfo = tempJoinInfo;
|
|
|
}
|
|
|
}
|
|
@@ -1663,15 +1526,9 @@ export default class MathUtil {
|
|
|
|
|
|
getHitInfoForCurve(pos, curve, roadWidth) {
|
|
|
let joinInfo;
|
|
|
- const tempJoinInfo =
|
|
|
- curve.controls.length === 2
|
|
|
- ? this.getHitInfoForThreeBezier(pos, curve, roadWidth / 2)
|
|
|
- : this.getHitInfoForTwoBezier(pos, curve);
|
|
|
+ const tempJoinInfo = curve.controls.length === 2 ? this.getHitInfoForThreeBezier(pos, curve, roadWidth / 2) : this.getHitInfoForTwoBezier(pos, curve);
|
|
|
|
|
|
- if (
|
|
|
- !joinInfo ||
|
|
|
- (tempJoinInfo && tempJoinInfo.distance < joinInfo.distance)
|
|
|
- ) {
|
|
|
+ if (!joinInfo || (tempJoinInfo && tempJoinInfo.distance < joinInfo.distance)) {
|
|
|
joinInfo = tempJoinInfo;
|
|
|
}
|
|
|
return joinInfo;
|
|
@@ -1701,10 +1558,7 @@ export default class MathUtil {
|
|
|
}
|
|
|
}
|
|
|
if (index == -1) {
|
|
|
- if (
|
|
|
- minDisToPoint >
|
|
|
- mathUtil.getDistance(position, points[points.length - 1])
|
|
|
- ) {
|
|
|
+ if (minDisToPoint > mathUtil.getDistance(position, points[points.length - 1])) {
|
|
|
return points.length;
|
|
|
} else {
|
|
|
return minPointIndex;
|
|
@@ -1738,10 +1592,7 @@ export default class MathUtil {
|
|
|
}
|
|
|
}
|
|
|
if ((index = -1)) {
|
|
|
- if (
|
|
|
- minDisToPoint >
|
|
|
- mathUtil.getDistance(position, points[points.length - 1])
|
|
|
- ) {
|
|
|
+ if (minDisToPoint > mathUtil.getDistance(position, points[points.length - 1])) {
|
|
|
return points.length - 2;
|
|
|
} else {
|
|
|
return minPointIndex;
|
|
@@ -1794,43 +1645,23 @@ export default class MathUtil {
|
|
|
if (mathUtil.equalPoint(points[i], points[i + 1])) {
|
|
|
return null;
|
|
|
}
|
|
|
- let leftEdgePoins1 = this.RectangleVertex(
|
|
|
- points[i],
|
|
|
- points[i + 1],
|
|
|
- leftWidth * 2
|
|
|
- );
|
|
|
- let leftLine1 = mathUtil.createLine1(
|
|
|
- leftEdgePoins1.leftEdgeStart,
|
|
|
- leftEdgePoins1.leftEdgeEnd
|
|
|
- );
|
|
|
+ let leftEdgePoins1 = this.RectangleVertex(points[i], points[i + 1], leftWidth * 2);
|
|
|
+ let leftLine1 = mathUtil.createLine1(leftEdgePoins1.leftEdgeStart, leftEdgePoins1.leftEdgeEnd);
|
|
|
if (i != points.length - 2) {
|
|
|
if (mathUtil.equalPoint(points[i + 2], points[i + 1])) {
|
|
|
return null;
|
|
|
}
|
|
|
- let leftEdgePoins2 = this.RectangleVertex(
|
|
|
- points[i + 1],
|
|
|
- points[i + 2],
|
|
|
- leftWidth * 2
|
|
|
- );
|
|
|
-
|
|
|
- let leftLine2 = mathUtil.createLine1(
|
|
|
- leftEdgePoins2.leftEdgeStart,
|
|
|
- leftEdgePoins2.leftEdgeEnd
|
|
|
- );
|
|
|
+ let leftEdgePoins2 = this.RectangleVertex(points[i + 1], points[i + 2], leftWidth * 2);
|
|
|
+
|
|
|
+ let leftLine2 = mathUtil.createLine1(leftEdgePoins2.leftEdgeStart, leftEdgePoins2.leftEdgeEnd);
|
|
|
let join = mathUtil.getIntersectionPoint(leftLine1, leftLine2);
|
|
|
if (join != null) {
|
|
|
leftEdgePoints[i + 1] = join;
|
|
|
} else {
|
|
|
- leftEdgePoints[i + 1] = mathUtil.getJoinLinePoint(
|
|
|
- points[i + 1],
|
|
|
- leftLine1
|
|
|
- );
|
|
|
+ leftEdgePoints[i + 1] = mathUtil.getJoinLinePoint(points[i + 1], leftLine1);
|
|
|
}
|
|
|
} else {
|
|
|
- leftEdgePoints[i + 1] = mathUtil.getJoinLinePoint(
|
|
|
- points[i + 1],
|
|
|
- leftLine1
|
|
|
- );
|
|
|
+ leftEdgePoints[i + 1] = mathUtil.getJoinLinePoint(points[i + 1], leftLine1);
|
|
|
}
|
|
|
if (!leftEdgePoints[0]) {
|
|
|
leftEdgePoints[0] = mathUtil.getJoinLinePoint(points[0], leftLine1);
|
|
@@ -1841,43 +1672,23 @@ export default class MathUtil {
|
|
|
if (mathUtil.equalPoint(points[i], points[i + 1])) {
|
|
|
return null;
|
|
|
}
|
|
|
- let rightEdgePoins1 = this.RectangleVertex(
|
|
|
- points[i],
|
|
|
- points[i + 1],
|
|
|
- rightWidth * 2
|
|
|
- );
|
|
|
- let rightLine1 = mathUtil.createLine1(
|
|
|
- rightEdgePoins1.rightEdgeStart,
|
|
|
- rightEdgePoins1.rightEdgeEnd
|
|
|
- );
|
|
|
+ let rightEdgePoins1 = this.RectangleVertex(points[i], points[i + 1], rightWidth * 2);
|
|
|
+ let rightLine1 = mathUtil.createLine1(rightEdgePoins1.rightEdgeStart, rightEdgePoins1.rightEdgeEnd);
|
|
|
if (i != points.length - 2) {
|
|
|
if (mathUtil.equalPoint(points[i + 2], points[i + 1])) {
|
|
|
return null;
|
|
|
}
|
|
|
- let rightEdgePoins2 = this.RectangleVertex(
|
|
|
- points[i + 1],
|
|
|
- points[i + 2],
|
|
|
- rightWidth * 2
|
|
|
- );
|
|
|
-
|
|
|
- let rightLine2 = mathUtil.createLine1(
|
|
|
- rightEdgePoins2.rightEdgeStart,
|
|
|
- rightEdgePoins2.rightEdgeEnd
|
|
|
- );
|
|
|
+ let rightEdgePoins2 = this.RectangleVertex(points[i + 1], points[i + 2], rightWidth * 2);
|
|
|
+
|
|
|
+ let rightLine2 = mathUtil.createLine1(rightEdgePoins2.rightEdgeStart, rightEdgePoins2.rightEdgeEnd);
|
|
|
let join = mathUtil.getIntersectionPoint(rightLine1, rightLine2);
|
|
|
if (join != null) {
|
|
|
rightEdgePoints[i + 1] = join;
|
|
|
} else {
|
|
|
- rightEdgePoints[i + 1] = mathUtil.getJoinLinePoint(
|
|
|
- points[i + 1],
|
|
|
- rightLine1
|
|
|
- );
|
|
|
+ rightEdgePoints[i + 1] = mathUtil.getJoinLinePoint(points[i + 1], rightLine1);
|
|
|
}
|
|
|
} else {
|
|
|
- rightEdgePoints[i + 1] = mathUtil.getJoinLinePoint(
|
|
|
- points[i + 1],
|
|
|
- rightLine1
|
|
|
- );
|
|
|
+ rightEdgePoints[i + 1] = mathUtil.getJoinLinePoint(points[i + 1], rightLine1);
|
|
|
}
|
|
|
|
|
|
if (!rightEdgePoints[0]) {
|
|
@@ -1937,7 +1748,7 @@ export default class MathUtil {
|
|
|
return `rgb(${r},${g},${b})`;
|
|
|
}
|
|
|
|
|
|
- //获取选段内距离末端断点某个位置点的坐标
|
|
|
+ //获取选段内距离末端端点某个位置点的坐标
|
|
|
/**
|
|
|
*
|
|
|
* @param {*} startPoint //线段起点
|
|
@@ -1945,7 +1756,7 @@ export default class MathUtil {
|
|
|
* @param {*} targetPointDistance //目标点到终点的距离
|
|
|
* @returns
|
|
|
*/
|
|
|
- getLinePointPos(startPoint, endPoint, targetPointDistance) {
|
|
|
+ getLineEndPointPos(startPoint, endPoint, targetPointDistance) {
|
|
|
if (!targetPointDistance) {
|
|
|
targetPointDistance = Constant.roadWidthTipsDistance;
|
|
|
}
|
|
@@ -1963,6 +1774,7 @@ export default class MathUtil {
|
|
|
};
|
|
|
return targetPoint;
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
|
|
|
const mathUtil = new MathUtil();
|