Implement zone data management and dropdown functionality in Outline component
This commit is contained in:
20
app/src/functions/isPointInsidePolygon.ts
Normal file
20
app/src/functions/isPointInsidePolygon.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
export const isPointInsidePolygon = (
|
||||
point: [number, number],
|
||||
polygon: [number, number][]
|
||||
) => {
|
||||
let inside = false;
|
||||
for (let i = 0, j = polygon.length - 1; i < polygon.length; j = i++) {
|
||||
const xi = polygon[i][0],
|
||||
zi = polygon[i][1];
|
||||
const xj = polygon[j][0],
|
||||
zj = polygon[j][1];
|
||||
|
||||
const intersect =
|
||||
// eslint-disable-next-line no-mixed-operators
|
||||
zi > point[1] !== zj > point[1] &&
|
||||
point[0] < ((xj - xi) * (point[1] - zi)) / (zj - zi + 0.000001) + xi;
|
||||
|
||||
if (intersect) inside = !inside;
|
||||
}
|
||||
return inside;
|
||||
};
|
||||
Reference in New Issue
Block a user