findIntersectionPointsWithShortestEdgeBtnSourceAndTarget = (
sourceX,
sourceY,
targetX,
targetY,
mappingNodes,
edgeLength,
bEdgeWrappingConfig,
boundaryConfig
) => {
let intersectionPoints = new Array();
let shortestEuclideanDistance = Number.MAX_VALUE;
if (mappingNodes == null) intersectionPoints = null;
else {
for (let mappingNode of mappingNodes) {
let intersectedX1 = 0;
let intersectedY1 = 0;
let intersectedX2 = 0;
let intersectedY2 = 0;
let intersectedX3 = 0;
let intersectedY3 = 0;
let intersectedX4 = 0;
let intersectedY4 = 0;
if (
mappingNode.intersectedX != 0 &&
mappingNode.intersectedY != 0 &&
bEdgeWrappingConfig[1]
) {
if (
mappingNode.intersectedX == boundaryConfig.oneThirdWidth &&
mappingNode.intersectedY == boundaryConfig.oneThirdHeight
) {
let testX1 = mappingNode.intersectedX;
let testY1 = getYGivenXAndSrcMappingNodes(
sourceX,
sourceY,
mappingNode.x,
mappingNode.y,
mappingNode.intersectedX
);
let testY2 = mappingNode.intersectedY;
let testX2 = getXGivenYAndSrcMappingNodes(
sourceX,
sourceY,
mappingNode.x,
mappingNode.y,
mappingNode.intersectedY
);
//check whether testY1 is within center square boundary
if (
testY1 >= boundaryConfig.oneThirdHeight &&
testY1 <= boundaryConfig.twoThirdsHeight
) {
intersectedX1 = mappingNode.intersectedX;
intersectedY1 = testY1;
intersectedX2 = testX2 + boundaryConfig.oneThirdWidth;
intersectedY2 = testY2 + boundaryConfig.oneThirdHeight;
intersectedX3 = intersectedX1 + boundaryConfig.oneThirdWidth;
intersectedY3 = intersectedY1;
intersectedX4 = testX2 + boundaryConfig.oneThirdWidth;
intersectedY4 = testY2;
} else if (
testX2 >= boundaryConfig.oneThirdWidth &&
testX2 <= boundaryConfig.twoThirdsWidth
) {
intersectedX1 = testX2;
intersectedY1 = mappingNode.intersectedY;
intersectedX2 = testX1 + boundaryConfig.oneThirdWidth;
intersectedY2 = testY1 + boundaryConfig.oneThirdHeight;
intersectedX3 = intersectedX1;
intersectedY3 = intersectedY1 + boundaryConfig.oneThirdHeight;
intersectedX4 = testX1;
intersectedY4 = testY1 + boundaryConfig.oneThirdHeight;
}
}
//upper-right corner
else if (
mappingNode.intersectedX == boundaryConfig.twoThirdsWidth &&
mappingNode.intersectedY == boundaryConfig.oneThirdHeight
) {
let testX1 = mappingNode.intersectedX;
let testY1 = getYGivenXAndSrcMappingNodes(
sourceX,
sourceY,
mappingNode.x,
mappingNode.y,
mappingNode.intersectedX
);
let testY2 = mappingNode.intersectedY;
let testX2 = getXGivenYAndSrcMappingNodes(
sourceX,
sourceY,
mappingNode.x,
mappingNode.y,
mappingNode.intersectedY
);
//check whether testY1 is within center square boundary
if (
testY1 >= boundaryConfig.oneThirdHeight &&
testY1 <= boundaryConfig.twoThirdsHeight
) {
intersectedX1 = mappingNode.intersectedX;
intersectedY1 = testY1;
intersectedX2 = testX2 - boundaryConfig.oneThirdWidth;
intersectedY2 = testY2 + boundaryConfig.oneThirdHeight;
intersectedX3 = intersectedX1 - boundaryConfig.oneThirdWidth;
intersectedY3 = intersectedY1;
intersectedX4 = testX2 - boundaryConfig.oneThirdWidth;
intersectedY4 = testY2;
} else if (
testX2 >= boundaryConfig.oneThirdWidth &&
testX2 <= boundaryConfig.twoThirdsWidth
) {
intersectedX1 = testX2;
intersectedY1 = mappingNode.intersectedY;
intersectedX2 = testX1 - boundaryConfig.oneThirdWidth;
intersectedY2 = testY1 + boundaryConfig.oneThirdHeight;
intersectedX3 = intersectedX1;
intersectedY3 = intersectedY1 + boundaryConfig.oneThirdHeight;
intersectedX4 = testX1;
intersectedY4 = testY1 + boundaryConfig.oneThirdHeight;
}
}
//bottom-right corner
else if (
mappingNode.intersectedX == boundaryConfig.twoThirdsWidth &&
mappingNode.intersectedY == boundaryConfig.twoThirdsHeight
) {
let testX1 = mappingNode.intersectedX;
let testY1 = getYGivenXAndSrcMappingNodes(
sourceX,
sourceY,
mappingNode.x,
mappingNode.y,
mappingNode.intersectedX
);
let testY2 = mappingNode.intersectedY;
let testX2 = getXGivenYAndSrcMappingNodes(
sourceX,
sourceY,
mappingNode.x,
mappingNode.y,
mappingNode.intersectedY
);
//check whether testY1 is within center square boundary
if (
testY1 >= boundaryConfig.oneThirdHeight &&
testY1 <= boundaryConfig.twoThirdsHeight
) {
intersectedX1 = mappingNode.intersectedX;
intersectedY1 = testY1;
intersectedX2 = testX2 - boundaryConfig.oneThirdWidth;
intersectedY2 = testY2 - boundaryConfig.oneThirdHeight;
intersectedX3 = intersectedX1 - boundaryConfig.oneThirdWidth;
intersectedY3 = intersectedY1;
intersectedX4 = testX2 - boundaryConfig.oneThirdWidth;
intersectedY4 = testY2;
} else if (
testX2 >= boundaryConfig.oneThirdWidth &&
testX2 <= boundaryConfig.twoThirdsWidth
) {
intersectedX1 = testX2;
intersectedY1 = mappingNode.intersectedY;
intersectedX2 = testX1 - boundaryConfig.oneThirdWidth;
intersectedY2 = testY1 - boundaryConfig.oneThirdHeight;
intersectedX3 = intersectedX1;
intersectedY3 = intersectedY1 - boundaryConfig.oneThirdHeight;
intersectedX4 = testX1;
intersectedY4 = testY1 - boundaryConfig.oneThirdHeight;
}
}
//bottom-left corner
else if (
mappingNode.intersectedX == boundaryConfig.oneThirdWidth &&
mappingNode.intersectedY == boundaryConfig.twoThirdsHeight
) {
let testX1 = mappingNode.intersectedX;
let testY1 = getYGivenXAndSrcMappingNodes(
sourceX,
sourceY,
mappingNode.x,
mappingNode.y,
mappingNode.intersectedX
);
let testY2 = mappingNode.intersectedY;
let testX2 = getXGivenYAndSrcMappingNodes(
sourceX,
sourceY,
mappingNode.x,
mappingNode.y,
mappingNode.intersectedY
);
//check whether testY1 is within center square boundary
if (
testY1 >= boundaryConfig.oneThirdHeight &&
testY1 <= boundaryConfig.twoThirdsHeight
) {
intersectedX1 = mappingNode.intersectedX;
intersectedY1 = testY1;
intersectedX2 = testX2 + boundaryConfig.oneThirdWidth;
intersectedY2 = testY2 - boundaryConfig.oneThirdHeight;
intersectedX3 = intersectedX1 + boundaryConfig.oneThirdWidth;
intersectedY3 = intersectedY1;
intersectedX4 = testX2 + boundaryConfig.oneThirdWidth;
intersectedY4 = testY2;
} else if (
testX2 >= boundaryConfig.oneThirdWidth &&
testX2 <= boundaryConfig.twoThirdsWidth
) {
intersectedX1 = testX2;
intersectedY1 = mappingNode.intersectedY;
intersectedX2 = testX1 + boundaryConfig.oneThirdWidth;
intersectedY2 = testY1 - boundaryConfig.oneThirdHeight;
intersectedX3 = intersectedX1;
intersectedY3 = intersectedY1 - boundaryConfig.oneThirdHeight;
intersectedX4 = testX1;
intersectedY4 = testY1 - boundaryConfig.oneThirdHeight;
}
}
} else if (mappingNode.intersectedX != 0 && bEdgeWrappingConfig[0]) {
intersectedX1 = mappingNode.intersectedX;
intersectedY1 = getYGivenXAndSrcMappingNodes(
sourceX,
sourceY,
mappingNode.x,
mappingNode.y,
mappingNode.intersectedX
);
intersectedX2 =
mappingNode.intersectedX == boundaryConfig.oneThirdWidth
? boundaryConfig.twoThirdsWidth
: boundaryConfig.oneThirdWidth;
intersectedY2 = intersectedY1;
} else if (mappingNode.intersectedY != 0 && bEdgeWrappingConfig[0]) {
intersectedY1 = mappingNode.intersectedY;
intersectedX1 = getXGivenYAndSrcMappingNodes(
sourceX,
sourceY,
mappingNode.x,
mappingNode.y,
mappingNode.intersectedY
);
intersectedX2 = intersectedX1;
intersectedY2 =
mappingNode.intersectedY == boundaryConfig.oneThirdHeight
? boundaryConfig.twoThirdsHeight
: boundaryConfig.oneThirdHeight;
}
let tmpDistanceBtnSourceAndIntersectPt1 = findEuclideanDistance(
intersectedX1,
intersectedY1,
sourceX,
sourceY
);
let tmpDistanceBtnTargetAndIntersectPt2 = findEuclideanDistance(
intersectedX2,
intersectedY2,
targetX,
targetY
);
let sumOfTwoEdgeSegmentLength =
tmpDistanceBtnSourceAndIntersectPt1 +
tmpDistanceBtnTargetAndIntersectPt2;
//compute sum of two edge segment for wrapping on adjacent squares
if (
bEdgeWrappingConfig[0] &&
(mappingNode.intersectedX == 0 || mappingNode.intersectedY == 0) &&
shortestEuclideanDistance > sumOfTwoEdgeSegmentLength
) {
if (mappingNode.intersectedX != 0 || mappingNode.intersectedY != 0) {
shortestEuclideanDistance = sumOfTwoEdgeSegmentLength;
edgeLength.value = shortestEuclideanDistance;
intersectionPoints.splice(0, intersectionPoints.length);
intersectionPoints.push({ x: intersectedX1, y: intersectedY1 });
intersectionPoints.push({ x: intersectedX2, y: intersectedY2 });
}
}
//compute sum of three edge segment for wrapping on corner squares
else if (
bEdgeWrappingConfig[1] &&
(mappingNode.intersectedX != 0 && mappingNode.intersectedY != 0) &&
shortestEuclideanDistance > sumOfTwoEdgeSegmentLength
) {
let tmpDistanceBtnIntersectPt3Pt4 = findEuclideanDistance(
intersectedX3,
intersectedY3,
intersectedX4,
intersectedY4
);
if (
shortestEuclideanDistance >
tmpDistanceBtnIntersectPt3Pt4 + sumOfTwoEdgeSegmentLength
) {
shortestEuclideanDistance =
tmpDistanceBtnIntersectPt3Pt4 + sumOfTwoEdgeSegmentLength;
edgeLength.value = shortestEuclideanDistance;
intersectionPoints.splice(0, intersectionPoints.length);
intersectionPoints.push({ x: intersectedX1, y: intersectedY1 });
intersectionPoints.push({ x: intersectedX2, y: intersectedY2 });
intersectionPoints.push({ x: intersectedX3, y: intersectedY3 });
intersectionPoints.push({ x: intersectedX4, y: intersectedY4 });
}
}
}
}
return intersectionPoints;
}