Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function generatePointsParallelToLinePoints(
p1: Position,
p2: Position,
groundCoords: Position
): Position[] {
const lineString: LineString = {
type: 'LineString',
coordinates: [p1, p2]
};
const pt = point(groundCoords);
const ddistance = pointToLineDistance(pt, lineString);
const lineBearing = bearing(p1, p2);
// Check if current point is to the left or right of line
// Line from A=(x1,y1) to B=(x2,y2) a point P=(x,y)
// then (x−x1)(y2−y1)−(y−y1)(x2−x1)
const isPointToLeftOfLine =
(groundCoords[0] - p1[0]) * (p2[1] - p1[1]) - (groundCoords[1] - p1[1]) * (p2[0] - p1[0]);
// Bearing to draw perpendicular to the line string
const orthogonalBearing = isPointToLeftOfLine < 0 ? lineBearing - 90 : lineBearing - 270;
// Get coordinates for the point p3 and p4 which are perpendicular to the lineString
// Add the distance as the current position moves away from the lineString
const p3 = destination(p2, ddistance, orthogonalBearing);
const p4 = destination(p1, ddistance, orthogonalBearing);
type: 'Feature',
geometry: {
type: 'LineString',
coordinates: [this._clickSequence[0], groundCoords]
}
});
} else if (this._clickSequence.length === 2) {
const lineString: LineString = {
type: 'LineString',
coordinates: this._clickSequence
};
const [p1, p2] = this._clickSequence;
const pt = point(groundCoords);
const options = { units: 'miles' };
const ddistance = pointToLineDistance(pt, lineString, options);
const lineBearing = bearing(p1, p2);
// Check if current point is to the left or right of line
// Line from A=(x1,y1) to B=(x2,y2) a point P=(x,y)
// then (x−x1)(y2−y1)−(y−y1)(x2−x1)
const isPointToLeftOfLine =
(groundCoords[0] - p1[0]) * (p2[1] - p1[1]) - (groundCoords[1] - p1[1]) * (p2[0] - p1[0]);
// Bearing to draw perpendicular to the line string
const orthogonalBearing = isPointToLeftOfLine < 0 ? lineBearing - 90 : lineBearing - 270;
// Get coordinates for the point p3 and p4 which are perpendicular to the lineString
// Add the distance as the current position moves away from the lineString
const p3 = destination(p2, ddistance, orthogonalBearing, options);
const p4 = destination(p1, ddistance, orthogonalBearing, options);
stops.forEach(stop => {
// Ignore the source segment's start and end stops
if (stop.stop_id !== segment.fromStopId && stop.stop_id !== segment.toStopId) {
const stopPoint = turf.point([stop.stop_lon, stop.stop_lat])
if (pointToLineDistance(stopPoint, line) <= STOP_SEARCH_BUFFER_KM) {
const pointOnLine = nearestPointOnLine(line, stopPoint)
// Ignore points too close to start or end stops
if ((!segment.stopAtStart ||
pointOnLine.properties.location > APPROX_MIN_SPACING_KM) &&
(!segment.stopAtEnd ||
segmentLengthKm - pointOnLine.properties.location > APPROX_MIN_SPACING_KM)
) {
pointOnLine.properties.stopId = stop.stop_id
pointOnLine.properties.stopCoords = [stop.stop_lon, stop.stop_lat]
candidateStops.push(pointOnLine)
}
}
}
})
// cluster stops that are close to each other
export function generatePointsParallelToLinePoints(
p1: Position,
p2: Position,
groundCoords: Position
): Position[] {
const lineString: LineString = {
type: 'LineString',
coordinates: [p1, p2]
};
const pt = point(groundCoords);
const ddistance = pointToLineDistance(pt, lineString);
const lineBearing = bearing(p1, p2);
// Check if current point is to the left or right of line
// Line from A=(x1,y1) to B=(x2,y2) a point P=(x,y)
// then (x−x1)(y2−y1)−(y−y1)(x2−x1)
const isPointToLeftOfLine =
(groundCoords[0] - p1[0]) * (p2[1] - p1[1]) - (groundCoords[1] - p1[1]) * (p2[0] - p1[0]);
// Bearing to draw perpendicular to the line string
const orthogonalBearing = isPointToLeftOfLine < 0 ? lineBearing - 90 : lineBearing - 270;
// Get coordinates for the point p3 and p4 which are perpendicular to the lineString
// Add the distance as the current position moves away from the lineString
const p3 = destination(p2, ddistance, orthogonalBearing);
const p4 = destination(p1, ddistance, orthogonalBearing);
featureEach(pts, (point) => {
const d = pointToLineDistance(point, line, { units });
if (d < dist) {
dist = d;
pt = point;
}
});
/**