lib/geometry.js
function getLineIntersect([ line1Begin, line1End ], [ line2Begin, line2End ]) {
	let [ x1Begin, y1Begin ] = line1Begin;
	let [ x1End, y1End ] = line1End;
	let [ x2Begin, y2Begin ] = line2Begin;
	let [ x2End, y2End ] = line2End;
	if ((x1Begin === x1End && y1Begin === y1End) || (x2Begin === x2End && y2Begin === y2End)) {
		throw new XError(XError.INVALID_ARGUMENT, 'start and end point of line must not be the same');
	}

	let slope1 = roundToFiveSignificantDigits((y1Begin - y1End) / (x1Begin - x1End));
	let intercept1;
	if (x1Begin === x1End) {
		intercept1 = x1Begin;
	} else if (y1Begin === y1End) {
		intercept1 = y1Begin;
	} else {
		intercept1 = roundToFiveSignificantDigits((y1Begin * x1End - y1End * x1Begin) / (x1End - x1Begin));
	}
	let slope2 = roundToFiveSignificantDigits((y2Begin - y2End) / (x2Begin - x2End));
	let intercept2;
	if (x2Begin === x2End) {
		intercept2 = x2Begin;
	} else if (y2Begin === y2End) {
		intercept2 = y2Begin;
	} else {
		intercept2 = roundToFiveSignificantDigits((y2Begin * x2End - y2End * x2Begin) / (x2End - x2Begin));
	}

	let intersectX, intersectY;

	if (slope1 === slope2 || (Math.abs(slope1) === Infinity && Math.abs(slope2) === Infinity)) {
		throw new XError(XError.INVALID_ARGUMENT, 'Can\'t get intersect of lines with the same slope');
	} else {
		if (Math.abs(slope1) === Infinity) {
			intersectX = x1Begin;
			intersectY = roundToFiveSignificantDigits(slope2 * x1Begin + intercept2);
		} else if (Math.abs(slope2) === Infinity) {
			intersectX = x2Begin;
			intersectY = roundToFiveSignificantDigits(slope1 * x2Begin + intercept1);
		} else if (slope1 === 0) {
			intersectY = y1Begin;
			intersectX = roundToFiveSignificantDigits((intersectY - intercept2) / slope2);
		} else if (slope2 === 0) {
			intersectY = y2Begin;
			intersectX = roundToFiveSignificantDigits((intersectY - intercept1) / slope1);
		} else {
			intersectX = roundToFiveSignificantDigits((intercept2 - intercept1) / (slope1 - slope2));
			intersectY = roundToFiveSignificantDigits(((slope1 * intercept2)
				- (slope2 * intercept1)) / (slope1 - slope2));
		}
	}

	return [ intersectX, intersectY ];
}
function getLineIntersect([ line1Begin, line1End ], [ line2Begin, line2End ]) {
	let [ x1Begin, y1Begin ] = line1Begin;
	let [ x1End, y1End ] = line1End;
	let [ x2Begin, y2Begin ] = line2Begin;
	let [ x2End, y2End ] = line2End;
	if ((x1Begin === x1End && y1Begin === y1End) || (x2Begin === x2End && y2Begin === y2End)) {
		throw new XError(XError.INVALID_ARGUMENT, 'start and end point of line must not be the same');
	}

	let slope1 = roundToFiveSignificantDigits((y1Begin - y1End) / (x1Begin - x1End));
	let intercept1;
	if (x1Begin === x1End) {
		intercept1 = x1Begin;
	} else if (y1Begin === y1End) {
		intercept1 = y1Begin;
	} else {
		intercept1 = roundToFiveSignificantDigits((y1Begin * x1End - y1End * x1Begin) / (x1End - x1Begin));
	}
	let slope2 = roundToFiveSignificantDigits((y2Begin - y2End) / (x2Begin - x2End));
	let intercept2;
	if (x2Begin === x2End) {
		intercept2 = x2Begin;
	} else if (y2Begin === y2End) {
		intercept2 = y2Begin;
	} else {
		intercept2 = roundToFiveSignificantDigits((y2Begin * x2End - y2End * x2Begin) / (x2End - x2Begin));
	}

	let intersectX, intersectY;

	if (slope1 === slope2 || (Math.abs(slope1) === Infinity && Math.abs(slope2) === Infinity)) {
		throw new XError(XError.INVALID_ARGUMENT, 'Can\'t get intersect of lines with the same slope');
	} else {
		if (Math.abs(slope1) === Infinity) {
			intersectX = x1Begin;
			intersectY = roundToFiveSignificantDigits(slope2 * x1Begin + intercept2);
		} else if (Math.abs(slope2) === Infinity) {
			intersectX = x2Begin;
			intersectY = roundToFiveSignificantDigits(slope1 * x2Begin + intercept1);
		} else if (slope1 === 0) {
			intersectY = y1Begin;
			intersectX = roundToFiveSignificantDigits((intersectY - intercept2) / slope2);
		} else if (slope2 === 0) {
			intersectY = y2Begin;
			intersectX = roundToFiveSignificantDigits((intersectY - intercept1) / slope1);
		} else {
			intersectX = roundToFiveSignificantDigits((intercept2 - intercept1) / (slope1 - slope2));
			intersectY = roundToFiveSignificantDigits(((slope1 * intercept2)
				- (slope2 * intercept1)) / (slope1 - slope2));
		}
	}

	return [ intersectX, intersectY ];
}
function getLineIntersect ( [ line1Begin , line1End ] , [ line2Begin , line2End ] ) { let [ x1Begin , y1Begin ] = line1Begin ; let [ x1End , y1End ] = line1End ; let [ x2Begin , y2Begin ] = line2Begin ; let [ x2End , y2End ] = line2End ; if ( ( x1Begin === x1End && y1Begin === y1End ) || ( x2Begin === x2End && y2Begin === y2End ) ) { throw new XError ( XError . INVALID_ARGUMENT , 'start and end point of line must not be the same' ) ; } let slope1 = roundToFiveSignificantDigits ( ( y1Begin - y1End ) / ( x1Begin - x1End ) ) ; let intercept1 ; if ( x1Begin === x1End ) { intercept1 = x1Begin ; } else if ( y1Begin === y1End ) { intercept1 = y1Begin ; } else { intercept1 = roundToFiveSignificantDigits ( ( y1Begin * x1End - y1End * x1Begin ) / ( x1End - x1Begin ) ) ; } let slope2 = roundToFiveSignificantDigits ( ( y2Begin - y2End ) / ( x2Begin - x2End ) ) ; let intercept2 ; if ( x2Begin === x2End ) { intercept2 = x2Begin ; } else if ( y2Begin === y2End ) { intercept2 = y2Begin ; } else { intercept2 = roundToFiveSignificantDigits ( ( y2Begin * x2End - y2End * x2Begin ) / ( x2End - x2Begin ) ) ; } let intersectX , intersectY ; if ( slope1 === slope2 || ( Math . abs ( slope1 ) === Infinity && Math . abs ( slope2 ) === Infinity ) ) { throw new XError ( XError . INVALID_ARGUMENT , 'Can\'t get intersect of lines with the same slope' ) ; } else { if ( Math . abs ( slope1 ) === Infinity ) { intersectX = x1Begin ; intersectY = roundToFiveSignificantDigits ( slope2 * x1Begin + intercept2 ) ; } else if ( Math . abs ( slope2 ) === Infinity ) { intersectX = x2Begin ; intersectY = roundToFiveSignificantDigits ( slope1 * x2Begin + intercept1 ) ; } else if ( slope1 === 0 ) { intersectY = y1Begin ; intersectX = roundToFiveSignificantDigits ( ( intersectY - intercept2 ) / slope2 ) ; } else if ( slope2 === 0 ) { intersectY = y2Begin ; intersectX = roundToFiveSignificantDigits ( ( intersectY - intercept1 ) / slope1 ) ; } else { intersectX = roundToFiveSignificantDigits ( ( intercept2 - intercept1 ) / ( slope1 - slope2 ) ) ; intersectY = roundToFiveSignificantDigits ( ( ( slope1 * intercept2 ) - ( slope2 * intercept1 ) ) / ( slope1 - slope2 ) ) ; } } return [ intersectX , intersectY ] ; }
Get the intersect point of two lines

@method getLineIntersect
@param {Number[]} line1Begin - coordianates of first point in line1
@param {Number[]} line1End - coordianates of second point of line1
@param {Number[]} line2Begin - coordianates of first point in line2
@param {Number[]} line2End -  coordianates of second point of line2
@return {Number[]} - returns the coordianates of intersect point
Get the intersect point of two lines