lib/geometry.js
function getLinearRingsIntersectState(linearRing1, linearRing2) {
	let isLinearRingsTouching = false;
	for (let i = 0; i < linearRing1.length - 1; i++) {
		for (let j = 0; j < linearRing2.length - 1; j++) {
			let state = getLineSegmentsIntersectState(
				[ linearRing2[j], linearRing2[j + 1] ], [ linearRing1[i], linearRing1[i + 1] ]);
			// the two linearRings intersect with each other
			if (state === INTERSECT) {
				return INTERSECT;
			}
			if (state !== UNINTERSECT) {
				isLinearRingsTouching = true;
			}
		}
	}
	if (!isLinearRingsTouching) {
		let foundOutside = false, foundInside = false;
		for (let i = 0; i < linearRing2.length - 1; i++) {
			let state = pointLinearRingState(linearRing2[i], linearRing1);
			if (state === OUTSIDE) {
				foundOutside = true;
			} else if (state === INSIDE) {
				foundInside = true;
			}
			if (foundInside && foundOutside) break;
		}
		if (foundOutside && foundInside) {
			return INTERSECT;
		} else if (foundInside) {
			return INSIDE;
		} else {
			return OUTSIDE;
		}
	} else {
		let foundOutside = false, foundInside = false;
		for (let i = 0; i < linearRing2.length - 1; i++) {
			for (let j = 0; j < 250; j++) {
				let randPoint = getRandPointInLineSegment([ linearRing2[i], linearRing2[i + 1] ]);
				let state = pointLinearRingState(randPoint, linearRing1);
				if (state === OUTSIDE) {
					foundOutside = true;
				} else if (state === INSIDE) {
					foundInside = true;
				}
				if (foundInside && foundInside) break;
			}
		}
		// The two linear rings are identical if all points of three levels are on the edges of linearRing1.
		// We mark identical linear ring as INSIDE
		if (!foundOutside && !foundInside) return INSIDE;
		if (foundOutside && foundInside) return INTERSECT;
		if (foundInside) return INSIDE;
		return OUTSIDE;
	}
}
function getLinearRingsIntersectState(linearRing1, linearRing2) {
	let isLinearRingsTouching = false;
	for (let i = 0; i < linearRing1.length - 1; i++) {
		for (let j = 0; j < linearRing2.length - 1; j++) {
			let state = getLineSegmentsIntersectState(
				[ linearRing2[j], linearRing2[j + 1] ], [ linearRing1[i], linearRing1[i + 1] ]);
			// the two linearRings intersect with each other
			if (state === INTERSECT) {
				return INTERSECT;
			}
			if (state !== UNINTERSECT) {
				isLinearRingsTouching = true;
			}
		}
	}
	if (!isLinearRingsTouching) {
		let foundOutside = false, foundInside = false;
		for (let i = 0; i < linearRing2.length - 1; i++) {
			let state = pointLinearRingState(linearRing2[i], linearRing1);
			if (state === OUTSIDE) {
				foundOutside = true;
			} else if (state === INSIDE) {
				foundInside = true;
			}
			if (foundInside && foundOutside) break;
		}
		if (foundOutside && foundInside) {
			return INTERSECT;
		} else if (foundInside) {
			return INSIDE;
		} else {
			return OUTSIDE;
		}
	} else {
		let foundOutside = false, foundInside = false;
		for (let i = 0; i < linearRing2.length - 1; i++) {
			for (let j = 0; j < 250; j++) {
				let randPoint = getRandPointInLineSegment([ linearRing2[i], linearRing2[i + 1] ]);
				let state = pointLinearRingState(randPoint, linearRing1);
				if (state === OUTSIDE) {
					foundOutside = true;
				} else if (state === INSIDE) {
					foundInside = true;
				}
				if (foundInside && foundInside) break;
			}
		}
		// The two linear rings are identical if all points of three levels are on the edges of linearRing1.
		// We mark identical linear ring as INSIDE
		if (!foundOutside && !foundInside) return INSIDE;
		if (foundOutside && foundInside) return INTERSECT;
		if (foundInside) return INSIDE;
		return OUTSIDE;
	}
}
function getLinearRingsIntersectState ( linearRing1 , linearRing2 ) { let isLinearRingsTouching = false ; for ( let i = 0 ; i < linearRing1 . length - 1 ; i ++ ) { for ( let j = 0 ; j < linearRing2 . length - 1 ; j ++ ) { let state = getLineSegmentsIntersectState ( [ linearRing2 [ j ] , linearRing2 [ j + 1 ] ] , [ linearRing1 [ i ] , linearRing1 [ i + 1 ] ] ) ; // the two linearRings intersect with each other if ( state === INTERSECT ) { return INTERSECT ; } if ( state !== UNINTERSECT ) { isLinearRingsTouching = true ; } } } if ( ! isLinearRingsTouching ) { let foundOutside = false , foundInside = false ; for ( let i = 0 ; i < linearRing2 . length - 1 ; i ++ ) { let state = pointLinearRingState ( linearRing2 [ i ] , linearRing1 ) ; if ( state === OUTSIDE ) { foundOutside = true ; } else if ( state === INSIDE ) { foundInside = true ; } if ( foundInside && foundOutside ) break ; } if ( foundOutside && foundInside ) { return INTERSECT ; } else if ( foundInside ) { return INSIDE ; } else { return OUTSIDE ; } } else { let foundOutside = false , foundInside = false ; for ( let i = 0 ; i < linearRing2 . length - 1 ; i ++ ) { for ( let j = 0 ; j < 250 ; j ++ ) { let randPoint = getRandPointInLineSegment ( [ linearRing2 [ i ] , linearRing2 [ i + 1 ] ] ) ; let state = pointLinearRingState ( randPoint , linearRing1 ) ; if ( state === OUTSIDE ) { foundOutside = true ; } else if ( state === INSIDE ) { foundInside = true ; } if ( foundInside && foundInside ) break ; } } // The two linear rings are identical if all points of three levels are on the edges of linearRing1. // We mark identical linear ring as INSIDE if ( ! foundOutside && ! foundInside ) return INSIDE ; if ( foundOutside && foundInside ) return INTERSECT ; if ( foundInside ) return INSIDE ; return OUTSIDE ; } }
Get the state of lienarRing2 in relationship to linearRing1

@method getLinearRingsIntersectState
@param {Number[][]} - coordinates of linearRing1
@param {Number\[][]} - coordinates of linearRing2
@return {String} - return the state. It can only be one of: 'intersect', 'outside'
and 'inside'
Get the state of lienarRing2 in relationship to linearRing1