Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function lineSplit(line, splitter) {
if (!line) throw new Error('line is required');
if (!splitter) throw new Error('splitter is required');
var lineType = getType(line);
var splitterType = getType(splitter);
if (lineType !== 'LineString') throw new Error('line must be LineString');
if (splitterType === 'FeatureCollection') throw new Error('splitter cannot be a FeatureCollection');
if (splitterType === 'GeometryCollection') throw new Error('splitter cannot be a GeometryCollection');
// remove excessive decimals from splitter
// to avoid possible approximation issues in rbush
var truncatedSplitter = truncate(splitter, {precision: 7});
switch (splitterType) {
case 'Point':
return splitLineWithPoint(line, truncatedSplitter);
case 'MultiPoint':
return splitLineWithPoints(line, truncatedSplitter);
case 'LineString':
case 'MultiLineString':
case 'Polygon':
case 'MultiPolygon':
return splitLineWithPoints(line, lineIntersect(line, truncatedSplitter));
}
}