-
Creator 版本:2.0.10
-
目标平台:web
-
错误信息:creator.d.ts文件中,第5363行
pointLineDistance方法返回类型错误,正常应该是number类型
/**
!#en Calculate the distance of point to line.
!#zh 计算点到直线的距离。如果这是一条线段并且垂足不在线段内,则会计算点到线段端点的距离。
@param point The point
@param start The start point of line
@param end The end point of line
@param isSegment whether this line is a segment
*/
static pointLineDistance(point: Vec2, start: Vec2, end: Vec2, isSegment: boolean):boolean;
源码文件C:\CocosCreator_2.0.10\resources\engine\cocos2d\core\CCIntersection.js文件 line 319 如下:
/**
* !#en Calculate the distance of point to line.
* !#zh 计算点到直线的距离。如果这是一条线段并且垂足不在线段内,则会计算点到线段端点的距离。
* @method pointLineDistance
* @param {Vec2} point - The point
* @param {Vec2} start - The start point of line
* @param {Vec2} end - The end point of line
* @param {boolean} isSegment - whether this line is a segment
* @return {boolean}
*/
function pointLineDistance(point, start, end, isSegment) {
var dx = end.x - start.x;
var dy = end.y - start.y;
var d = dx*dx + dy*dy;
var t = ((point.x - start.x) * dx + (point.y - start.y) * dy) / d;
var p;
if (!isSegment) {
p = cc.v2(start.x + t * dx, start.y + t * dy);
}
else {
if (d) {
if (t < 0) p = start;
else if (t > 1) p = end;
else p = cc.v2(start.x + t * dx, start.y + t * dy);
}
else {
p = start;
}
}
dx = point.x - p.x;
dy = point.y - p.y;
return Math.sqrt(dx*dx + dy*dy);
}
望官方及时更正