lib/geometry.js
function pointLinearRingState(point, linearRing) {
	let { topLeftVertex, width, height } = getBoundingBox(linearRing);
	let [ minX, maxY ] = topLeftVertex;
	let maxX = minX + width;
	let minY = maxY - height;
	let [ x, y ] = point;
	if (x < minX || x > maxX || y < minY || y > maxY) return OUTSIDE;
	for (let i = 0; i < linearRing.length - 1; i++) {
		if (isPointInLine(point, [ linearRing[i], linearRing[i + 1] ])) {
			if (getPointLineSegmentState(point, [ linearRing[i], linearRing[i + 1] ])) {
				return TANGENT;
			}
		}
	}
	let numIntersect = 0;
	let slope = 0;
	let determinedState = false;
	while (!determinedState) {
		let state;
		let intercept = roundToFiveSignificantDigits(point[1] - slope * point[0]);
		let point2 = [ roundToFiveSignificantDigits(point[0] + 1),
			roundToFiveSignificantDigits(slope * (point[0] + 1) + intercept) ];
		for (let i = 0; i < linearRing.length - 1; i++) {
			state = getRayLineSegmentIntersectState([ point, point2 ], [ linearRing[i], linearRing[i + 1] ]);
			if (state === TANGENT || state === OVERLAP) {
				break;
			} else if (state === INTERSECT) {
				numIntersect++;
			}
		}
		if (state === INTERSECT || state === UNINTERSECT) {
			determinedState = true;
		} else {
			numIntersect = 0;
			slope += 0.01;
		}
	}
	return numIntersect % 2 === 1 ? INSIDE : OUTSIDE;
}
function pointLinearRingState(point, linearRing) {
	let { topLeftVertex, width, height } = getBoundingBox(linearRing);
	let [ minX, maxY ] = topLeftVertex;
	let maxX = minX + width;
	let minY = maxY - height;
	let [ x, y ] = point;
	if (x < minX || x > maxX || y < minY || y > maxY) return OUTSIDE;
	for (let i = 0; i < linearRing.length - 1; i++) {
		if (isPointInLine(point, [ linearRing[i], linearRing[i + 1] ])) {
			if (getPointLineSegmentState(point, [ linearRing[i], linearRing[i + 1] ])) {
				return TANGENT;
			}
		}
	}
	let numIntersect = 0;
	let slope = 0;
	let determinedState = false;
	while (!determinedState) {
		let state;
		let intercept = roundToFiveSignificantDigits(point[1] - slope * point[0]);
		let point2 = [ roundToFiveSignificantDigits(point[0] + 1),
			roundToFiveSignificantDigits(slope * (point[0] + 1) + intercept) ];
		for (let i = 0; i < linearRing.length - 1; i++) {
			state = getRayLineSegmentIntersectState([ point, point2 ], [ linearRing[i], linearRing[i + 1] ]);
			if (state === TANGENT || state === OVERLAP) {
				break;
			} else if (state === INTERSECT) {
				numIntersect++;
			}
		}
		if (state === INTERSECT || state === UNINTERSECT) {
			determinedState = true;
		} else {
			numIntersect = 0;
			slope += 0.01;
		}
	}
	return numIntersect % 2 === 1 ? INSIDE : OUTSIDE;
}
function pointLinearRingState ( point , linearRing ) { let { topLeftVertex , width , height } = getBoundingBox ( linearRing ) ; let [ minX , maxY ] = topLeftVertex ; let maxX = minX + width ; let minY = maxY - height ; let [ x , y ] = point ; if ( x < minX || x > maxX || y < minY || y > maxY ) return OUTSIDE ; for ( let i = 0 ; i < linearRing . length - 1 ; i ++ ) { if ( isPointInLine ( point , [ linearRing [ i ] , linearRing [ i + 1 ] ] ) ) { if ( getPointLineSegmentState ( point , [ linearRing [ i ] , linearRing [ i + 1 ] ] ) ) { return TANGENT ; } } } let numIntersect = 0 ; let slope = 0 ; let determinedState = false ; while ( ! determinedState ) { let state ; let intercept = roundToFiveSignificantDigits ( point [ 1 ] - slope * point [ 0 ] ) ; let point2 = [ roundToFiveSignificantDigits ( point [ 0 ] + 1 ) , roundToFiveSignificantDigits ( slope * ( point [ 0 ] + 1 ) + intercept ) ] ; for ( let i = 0 ; i < linearRing . length - 1 ; i ++ ) { state = getRayLineSegmentIntersectState ( [ point , point2 ] , [ linearRing [ i ] , linearRing [ i + 1 ] ] ) ; if ( state === TANGENT || state === OVERLAP ) { break ; } else if ( state === INTERSECT ) { numIntersect ++ ; } } if ( state === INTERSECT || state === UNINTERSECT ) { determinedState = true ; } else { numIntersect = 0 ; slope += 0.01 ; } } return numIntersect % 2 === 1 ? INSIDE : OUTSIDE ; }
Get the state of point in relationship to a linear ring

@method pointLinearRingState
@param {Number[]} point - coordinates of the point
@param {Number[][]} - linearRing - coordinates of vertexes of the linear ring
@return {String} - return the state. Can only be one of: 'outside', 'inside'
and 'tangent'
Get the state of point in relationship to a linear ring