Описание функции pointsEqual
function pointsEqual(point1, point2) {
if (!point1)
return false;
if (!point2)
return false;
// return point1.x == point2.x && point1.y == point2.y;
return numbersEqual(pointsDistance(point1, point2), 0);
}
function numbersEqual(num1, num2) {
return Math.abs(num2 - num1) < 1e-14;
}
function pointsDistance(point1, point2) {
return Math.pow(Math.pow(point2.x - point1.x, 2) + Math.pow(point2.y - point1.y, 2), 0.5);
}
|