Skip to content

Instantly share code, notes, and snippets.

@shobishani
Last active April 30, 2019 07:51
Show Gist options
  • Save shobishani/56ecea6f053c3ab3c859a94a6e87a259 to your computer and use it in GitHub Desktop.
Save shobishani/56ecea6f053c3ab3c859a94a6e87a259 to your computer and use it in GitHub Desktop.
private checkIntersection() {
const alreadyChecked: number[][] = [];
for (let i = 0; i < this._polyLines.length; i += 1) {
for (let j = 0; j < this._polyLines.length; j += 1) {
if (i === j) continue;
const isAlreadyCompared: number[] | undefined = alreadyChecked.find((item: number[]) => {
return isEqual(sortBy(item, Number), sortBy([j, i], Number));
});
if (isAlreadyCompared && isAlreadyCompared.length) continue;
alreadyChecked.push([i, j]);
const cords1: any[] = convertToCords(this._polyLines[i].getPath());
const cords2: any[] = convertToCords(this._polyLines[j].getPath());
const line1 = lineString(cords1);
const line2 = lineString(cords2);
const intersects = lineIntersect(line1, line2);
if (intersects && intersects.features && intersects.features.length) {
const item: any = intersects.features[0];
const { coordinates } = item.geometry;
if (coordinates && coordinates.length > 0) {
this._intersectionPoints.push({
lat: coordinates[0],
lng: coordinates[1],
volume: this._polyLines[i].getVolume(),
});
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment