Publish v6 boolean modules

This commit is contained in:
Denis 2018-02-21 13:44:33 -05:00
parent 87894c1326
commit eeab93dcaa
30 changed files with 146 additions and 315 deletions

View File

@ -1,6 +1,6 @@
{
"name": "@turf/boolean-clockwise",
"version": "5.1.5",
"version": "6.0.0",
"description": "turf boolean-clockwise module",
"main": "index",
"files": [

View File

@ -1,6 +1,6 @@
{
"name": "@turf/boolean-contains",
"version": "5.1.5",
"version": "6.0.0",
"description": "turf boolean-contains module",
"main": "index",
"files": [
@ -43,9 +43,9 @@
"tape": "*"
},
"dependencies": {
"@turf/bbox": "^5.1.5",
"@turf/boolean-point-in-polygon": "^5.1.5",
"@turf/boolean-point-on-line": "^5.1.5",
"@turf/bbox": "6.x",
"@turf/boolean-point-in-polygon": "6.x",
"@turf/boolean-point-on-line": "6.x",
"@turf/helpers": "6.x",
"@turf/invariant": "6.x"
}

View File

@ -1,6 +1,6 @@
{
"name": "@turf/boolean-crosses",
"version": "5.1.5",
"version": "6.0.0",
"description": "turf boolean-crosses module",
"main": "index",
"files": [
@ -42,7 +42,7 @@
"tape": "*"
},
"dependencies": {
"@turf/boolean-point-in-polygon": "^5.1.5",
"@turf/boolean-point-in-polygon": "6.x",
"@turf/helpers": "6.x",
"@turf/invariant": "6.x",
"@turf/line-intersect": "6.x",

View File

@ -1,6 +1,6 @@
{
"name": "@turf/boolean-disjoint",
"version": "5.1.6",
"version": "6.0.0",
"description": "turf boolean-disjoint module",
"main": "index",
"files": [
@ -41,7 +41,7 @@
"tape": "*"
},
"dependencies": {
"@turf/boolean-point-in-polygon": "^5.1.5",
"@turf/boolean-point-in-polygon": "6.0.0",
"@turf/helpers": "6.x",
"@turf/line-intersect": "6.x",
"@turf/meta": "6.x",

View File

@ -1,6 +1,6 @@
{
"name": "@turf/boolean-equal",
"version": "5.1.5",
"version": "6.0.0",
"description": "turf boolean-equal module",
"main": "index",
"files": [
@ -45,7 +45,7 @@
"tape": "*"
},
"dependencies": {
"@turf/clean-coords": "^5.1.5",
"@turf/clean-coords": "6.0.0",
"@turf/helpers": "6.x",
"@turf/invariant": "6.x",
"geojson-equality": "0.1.6"

View File

@ -41,7 +41,7 @@
"tape": "*"
},
"dependencies": {
"@turf/boolean-disjoint": "^5.1.6",
"@turf/boolean-disjoint": "6.x",
"@turf/helpers": "6.x",
"@turf/meta": "6.x"
}

View File

@ -1,6 +1,6 @@
{
"name": "@turf/boolean-overlap",
"version": "5.1.5",
"version": "6.0.0",
"description": "turf boolean-overlap module",
"main": "index",
"files": [
@ -47,7 +47,7 @@
"@turf/helpers": "6.x",
"@turf/invariant": "6.x",
"@turf/line-intersect": "6.x",
"@turf/line-overlap": "^5.1.5",
"@turf/line-overlap": "6.x",
"@turf/meta": "6.x",
"geojson-equality": "0.1.6"
}

View File

@ -1,6 +1,6 @@
{
"name": "@turf/boolean-parallel",
"version": "5.1.5",
"version": "6.0.0",
"description": "turf boolean-parallel module",
"main": "index",
"files": [
@ -40,9 +40,9 @@
"write-json-file": "*"
},
"dependencies": {
"@turf/clean-coords": "^5.1.5",
"@turf/clean-coords": "6.x",
"@turf/helpers": "6.x",
"@turf/line-segment": "^5.1.5",
"@turf/rhumb-bearing": "^5.1.5"
"@turf/line-segment": "6.x",
"@turf/rhumb-bearing": "*"
}
}

View File

@ -1,7 +1,7 @@
{
"name": "@turf/boolean-point-in-polygon",
"version": "5.1.5",
"version": "6.0.0",
"description": "turf boolean-point-in-polygon module",
"main": "index",
"files": [

View File

@ -1,6 +1,6 @@
{
"name": "@turf/boolean-point-on-line",
"version": "5.1.5",
"version": "6.0.0",
"description": "turf boolean-point-on-line module",
"main": "index",
"files": [
@ -31,20 +31,15 @@
},
"homepage": "https://github.com/Turfjs/turf",
"devDependencies": {
"@std/esm": "*",
"benchmark": "*",
"glob": "*",
"load-json-file": "*",
"rollup": "*",
"typescript": "*",
"tape": "*",
"write-json-file": "*"
},
"dependencies": {
"@turf/helpers": "6.x",
"@turf/invariant": "6.x"
},
"@std/esm": {
"esm": "js",
"cjs": true
}
}

View File

@ -0,0 +1 @@
index.js

View File

@ -1,6 +1,6 @@
{
"name": "@turf/boolean-within",
"version": "5.1.5",
"version": "6.0.0",
"description": "turf boolean-within module",
"main": "index",
"files": [
@ -44,9 +44,9 @@
"tape": "*"
},
"dependencies": {
"@turf/bbox": "^5.1.5",
"@turf/boolean-point-in-polygon": "^5.1.5",
"@turf/boolean-point-on-line": "^5.1.5",
"@turf/bbox": "6.x",
"@turf/boolean-point-in-polygon": "6.x",
"@turf/boolean-point-on-line": "6.x",
"@turf/helpers": "6.x",
"@turf/invariant": "6.x"
}

View File

@ -1,8 +1,8 @@
import path from 'path';
import glob from 'glob';
import load from 'load-json-file';
import Benchmark from 'benchmark';
import cleanCoords from './';
const path = require('path');
const glob = require('glob');
const load = require('load-json-file');
const Benchmark = require('benchmark');
const cleanCoords = require('./').default;
/**
* Benchmark Results

View File

@ -1,25 +0,0 @@
import { Feature, Geometry, Properties } from '@turf/helpers'
/**
* http://turfjs.org/docs/#cleancoords
*/
export default function <G extends Geometry, P = Properties>(
feature: Feature<G, P>,
options?: {
mutate?: boolean
}
): Feature<G, P>;
export default function <G extends Geometry>(
feature: G,
options?: {
mutate?: boolean
}
): G;
export default function <G extends Geometry>(
feature: Feature<G> | G,
options?: {
mutate?: boolean
}
): Feature<G> | G;

View File

@ -1,6 +1,8 @@
import { feature } from '@turf/helpers';
import { feature, AllGeoJSON } from '@turf/helpers';
import { getCoords, getType } from '@turf/invariant';
// To-Do => Improve Typescript GeoJSON handling
/**
* Removes redundant coordinates from any GeoJSON Geometry.
*
@ -19,7 +21,9 @@ import { getCoords, getType } from '@turf/invariant';
* turf.cleanCoords(multiPoint).geometry.coordinates;
* //= [[0, 0], [2, 2]]
*/
function cleanCoords(geojson, options) {
function cleanCoords(geojson: any, options: {
mutate?: boolean,
} = {}) {
// Backwards compatible with v4.0
var mutate = (typeof options === 'object') ? options.mutate : options;
if (!geojson) throw new Error('geojson is required');
@ -39,7 +43,7 @@ function cleanCoords(geojson, options) {
});
break;
case 'MultiPolygon':
getCoords(geojson).forEach(function (polygons) {
getCoords(geojson).forEach(function (polygons: any) {
var polyPoints = [];
polygons.forEach(function (ring) {
polyPoints.push(cleanLine(ring));
@ -51,7 +55,7 @@ function cleanCoords(geojson, options) {
return geojson;
case 'MultiPoint':
var existing = {};
getCoords(geojson).forEach(function (coord) {
getCoords(geojson).forEach(function (coord: any) {
var key = coord.join('-');
if (!existing.hasOwnProperty(key)) {
newCoords.push(coord);
@ -75,7 +79,7 @@ function cleanCoords(geojson, options) {
geojson.geometry.coordinates = newCoords;
return geojson;
}
return feature({type: type, coordinates: newCoords}, geojson.properties, geojson.bbox, geojson.id);
return feature({type: type, coordinates: newCoords}, geojson.properties, {bbox: geojson.bbox, id: geojson.id});
}
}

View File

@ -1,22 +1,17 @@
{
"name": "@turf/clean-coords",
"version": "5.1.5",
"version": "6.0.0",
"description": "turf clean-coords module",
"main": "main.js",
"module": "main.es.js",
"types": "index.d.ts",
"main": "index",
"files": [
"index.js",
"index.d.ts",
"main.js",
"main.es.js"
"index.ts"
],
"scripts": {
"pretest": "rollup -c ../../rollup.config.js",
"test": "node -r @std/esm test.js",
"posttest": "node -r @std/esm ../../scripts/validate-es5-dependencies.js",
"bench": "node -r @std/esm bench.js",
"pretest": "tsc",
"test": "node test.js",
"bench": "node bench.js",
"docs": "node ../../scripts/generate-readmes"
},
"repository": {
@ -38,20 +33,15 @@
},
"homepage": "https://github.com/Turfjs/turf",
"devDependencies": {
"@std/esm": "*",
"@turf/truncate": "^5.1.5",
"@turf/truncate": "*",
"benchmark": "*",
"load-json-file": "*",
"rollup": "*",
"typescript": "*",
"tape": "*",
"write-json-file": "*"
},
"dependencies": {
"@turf/helpers": "6.x",
"@turf/invariant": "6.x"
},
"@std/esm": {
"esm": "js",
"cjs": true
}
}

View File

@ -1,17 +1,17 @@
import fs from 'fs';
import test from 'tape';
import path from 'path';
import load from 'load-json-file';
import truncate from '@turf/truncate';
import {
const fs = require('fs');
const test = require('tape');
const path = require('path');
const load = require('load-json-file');
const truncate = require('@turf/truncate').default;
const {
point,
multiPoint,
lineString,
multiPolygon,
polygon,
} from '@turf/helpers';
import write from 'write-json-file';
import cleanCoords from '.';
} = require('@turf/helpers');
const write = require('write-json-file');
const cleanCoords = require('./').default;
const directories = {
in: path.join(__dirname, 'test', 'in') + path.sep,

1
packages/turf-line-overlap/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
index.js

View File

@ -1,8 +1,8 @@
import fs from 'fs';
import path from 'path';
import load from 'load-json-file';
import Benchmark from 'benchmark';
import lineOverlap from './';
const fs = require('fs');
const path = require('path');
const load = require('load-json-file');
const Benchmark = require('benchmark');
const lineOverlap = require('./').default;
const directory = path.join(__dirname, 'test', 'in') + path.sep;
const fixtures = fs.readdirSync(directory).map(filename => {

View File

@ -1,14 +0,0 @@
import { Feature, FeatureCollection, LineString, MultiLineString, Polygon, MultiPolygon } from '@turf/helpers'
type Geoms = LineString | MultiLineString | Polygon | MultiPolygon;
/**
* http://turfjs.org/docs/#lineoverlap
*/
export default function lineOverlap(
source: Feature<Geoms> | Geoms,
target: Feature<Geoms> | Geoms,
options?: {
tolerance?: number
}
): FeatureCollection<LineString>;

View File

@ -4,8 +4,11 @@ import nearestPointOnLine from '@turf/nearest-point-on-line';
import booleanPointOnLine from '@turf/boolean-point-on-line';
import { getCoords } from '@turf/invariant';
import { featureEach, segmentEach } from '@turf/meta';
import { featureCollection, isObject } from '@turf/helpers';
import equal from './lib/deep-equal';
import {
featureCollection, isObject,
FeatureCollection, Feature, LineString, MultiLineString, Polygon, MultiPolygon,
} from '@turf/helpers';
import * as equal from 'deep-equal';
/**
* Takes any LineString or Polygon and returns the overlapping lines between both features.
@ -25,7 +28,11 @@ import equal from './lib/deep-equal';
* //addToMap
* var addToMap = [line1, line2, overlapping]
*/
function lineOverlap(line1, line2, options) {
function lineOverlap<G1 extends LineString|MultiLineString|Polygon|MultiPolygon, G2 extends LineString|MultiLineString|Polygon|MultiPolygon>(
line1: Feature<G1> | G1,
line2: Feature<G2> | G2,
options: {tolerance?: number}={}
): FeatureCollection<LineString> {
// Optional parameters
options = options || {};
if (!isObject(options)) throw new Error('options is invalid');
@ -36,7 +43,10 @@ function lineOverlap(line1, line2, options) {
// Create Spatial Index
var tree = rbush();
tree.load(lineSegment(line1));
// To-Do -- HACK way to support typescript
const line: any = lineSegment(line1);
tree.load(line);
var overlapSegment;
// Line Intersection
@ -49,7 +59,7 @@ function lineOverlap(line1, line2, options) {
featureEach(tree.search(segment), function (match) {
if (doesOverlaps === false) {
var coordsSegment = getCoords(segment).sort();
var coordsMatch = getCoords(match).sort();
var coordsMatch: any = getCoords(match).sort();
// Segment overlaps feature
if (equal(coordsSegment, coordsMatch)) {

View File

@ -1,96 +0,0 @@
var pSlice = Array.prototype.slice;
function isArguments(object) {
return Object.prototype.toString.call(object) === '[object Arguments]';
}
export default function deepEqual(actual, expected, opts) {
if (!opts) opts = {};
// 7.1. All identical values are equivalent, as determined by ===.
if (actual === expected) {
return true;
} else if (actual instanceof Date && expected instanceof Date) {
return actual.getTime() === expected.getTime();
// 7.3. Other pairs that do not both pass typeof value == 'object',
// equivalence is determined by ==.
} else if (!actual || !expected || typeof actual != 'object' && typeof expected != 'object') {
return opts.strict ? actual === expected : actual === expected;
// 7.4. For all other Object pairs, including Array objects, equivalence is
// determined by having the same number of owned properties (as verified
// with Object.prototype.hasOwnProperty.call), the same set of keys
// (although not necessarily the same order), equivalent values for every
// corresponding key, and an identical 'prototype' property. Note: this
// accounts for both named and indexed properties on Arrays.
} else {
return objEquiv(actual, expected, opts);
}
}
function isUndefinedOrNull(value) {
return value === null || value === undefined;
}
function isBuffer(x) {
if (!x || typeof x !== 'object' || typeof x.length !== 'number') return false;
if (typeof x.copy !== 'function' || typeof x.slice !== 'function') {
return false;
}
if (x.length > 0 && typeof x[0] !== 'number') return false;
return true;
}
function objEquiv(a, b, opts) {
var i, key;
if (isUndefinedOrNull(a) || isUndefinedOrNull(b))
return false;
// an identical 'prototype' property.
if (a.prototype !== b.prototype) return false;
//~~~I've managed to break Object.keys through screwy arguments passing.
// Converting to array solves the problem.
if (isArguments(a)) {
if (!isArguments(b)) {
return false;
}
a = pSlice.call(a);
b = pSlice.call(b);
return deepEqual(a, b, opts);
}
if (isBuffer(a)) {
if (!isBuffer(b)) {
return false;
}
if (a.length !== b.length) return false;
for (i = 0; i < a.length; i++) {
if (a[i] !== b[i]) return false;
}
return true;
}
try {
var ka = Object.keys(a),
kb = Object.keys(b);
} catch (e) { //happens when one is a string literal and the other isn't
return false;
}
// having the same number of owned properties (keys incorporates
// hasOwnProperty)
if (ka.length !== kb.length)
return false;
//the same set of keys (although not necessarily the same order),
ka.sort();
kb.sort();
//~~~cheap key test
for (i = ka.length - 1; i >= 0; i--) {
if (ka[i] !== kb[i])
return false;
}
//equivalent values for every corresponding key, and
//~~~possibly expensive deep test
for (i = ka.length - 1; i >= 0; i--) {
key = ka[i];
if (!deepEqual(a[key], b[key], opts)) return false;
}
return typeof a === typeof b;
}

View File

@ -1,22 +1,16 @@
{
"name": "@turf/line-overlap",
"version": "5.1.5",
"version": "6.0.0",
"description": "turf line-overlap module",
"main": "main.js",
"module": "main.es.js",
"types": "index.d.ts",
"main": "index",
"files": [
"index.js",
"index.d.ts",
"main.js",
"lib",
"main.es.js"
"index.ts"
],
"scripts": {
"pretest": "rollup -c ../../rollup.config.js",
"test": "node -r @std/esm test.js",
"posttest": "node -r @std/esm ../../scripts/validate-es5-dependencies.js",
"bench": "node -r @std/esm bench.js",
"pretest": "tsc",
"test": "node test.js",
"bench": "node bench.js",
"docs": "node ../../scripts/generate-readmes"
},
"repository": {
@ -40,24 +34,19 @@
},
"homepage": "https://github.com/Turfjs/turf",
"devDependencies": {
"@std/esm": "*",
"benchmark": "*",
"load-json-file": "*",
"rollup": "*",
"typescript": "*",
"tape": "*",
"write-json-file": "*"
},
"dependencies": {
"@turf/boolean-point-on-line": "^5.1.5",
"@turf/boolean-point-on-line": "6.x",
"@turf/helpers": "6.x",
"@turf/invariant": "6.x",
"@turf/line-segment": "^5.1.5",
"@turf/line-segment": "6.x",
"@turf/meta": "6.x",
"@turf/nearest-point-on-line": "^5.1.5",
"@turf/nearest-point-on-line": "6.x",
"geojson-rbush": "3.x"
},
"@std/esm": {
"esm": "js",
"cjs": true
}
}

View File

@ -1,11 +1,11 @@
import fs from 'fs';
import test from 'tape';
import path from 'path';
import load from 'load-json-file';
import write from 'write-json-file';
import { featureEach } from '@turf/meta';
import { featureCollection, lineString } from '@turf/helpers';
import lineOverlap from './';
const fs = require('fs');
const test = require('tape');
const path = require('path');
const load = require('load-json-file');
const write = require('write-json-file');
const { featureEach } = require('@turf/meta');
const { featureCollection, lineString } = require('@turf/helpers');
const lineOverlap = require('./').default;
const directories = {
in: path.join(__dirname, 'test', 'in') + path.sep,

View File

@ -0,0 +1 @@
index.js

View File

@ -1,8 +1,8 @@
import fs from 'fs';
import path from 'path';
import load from 'load-json-file';
import Benchmark from 'benchmark';
import nearestPointOnLine from './';
const fs = require('fs');
const path = require('path');
const load = require('load-json-file');
const Benchmark = require('benchmark');
const nearestPointOnLine = require('./').default;
const directory = path.join(__dirname, 'test', 'in') + path.sep;
const fixtures = fs.readdirSync(directory).map(filename => {

View File

@ -1,21 +0,0 @@
import { Point, Feature, Units, Coord, LineString, MultiLineString } from '@turf/helpers'
export interface NearestPointOnLine extends Feature<Point> {
properties: {
index?: number
dist?: number
location?: number
[key: string]: any
}
}
/**
* http://turfjs.org/docs/#nearestpointonline
*/
export default function nearestPointOnLine<T extends MultiLineString | LineString>(
line: Feature<T> | T,
point: Coord,
options?: {
units?: Units
}
): NearestPointOnLine;

View File

@ -3,9 +3,21 @@ import distance from '@turf/distance';
import destination from '@turf/destination';
import lineIntersects from '@turf/line-intersect';
import { flattenEach } from '@turf/meta';
import { point, lineString, isObject } from '@turf/helpers';
import {
point, lineString, isObject,
Feature, Point, LineString, MultiLineString, Coord, Units
} from '@turf/helpers';
import { getCoords } from '@turf/invariant';
export interface NearestPointOnLine extends Feature<Point> {
properties: {
index?: number
dist?: number
location?: number
[key: string]: any
}
}
/**
* Takes a {@link Point} and a {@link LineString} and calculates the closest Point on the (Multi)LineString.
*
@ -32,24 +44,18 @@ import { getCoords } from '@turf/invariant';
* var addToMap = [line, pt, snapped];
* snapped.properties['marker-color'] = '#00f';
*/
function nearestPointOnLine(lines, pt, options) {
// Optional parameters
options = options || {};
if (!isObject(options)) throw new Error('options is invalid');
// validation
var type = (lines.geometry) ? lines.geometry.type : lines.type;
if (type !== 'LineString' && type !== 'MultiLineString') {
throw new Error('lines must be LineString or MultiLineString');
}
var closestPt = point([Infinity, Infinity], {
function nearestPointOnLine<G extends LineString|MultiLineString>(
lines: Feature<G> | G,
pt: Coord,
options: {units?: Units} = {}
): NearestPointOnLine {
var closestPt: any = point([Infinity, Infinity], {
dist: Infinity
});
var length = 0.0;
flattenEach(lines, function (line) {
var coords = getCoords(line);
flattenEach(lines, function (line: any) {
var coords: any = getCoords(line);
for (var i = 0; i < coords.length - 1; i++) {
//start

View File

@ -1,21 +1,16 @@
{
"name": "@turf/nearest-point-on-line",
"version": "5.1.5",
"version": "6.0.0",
"description": "turf nearest-point-on-line module",
"main": "main.js",
"module": "main.es.js",
"types": "index.d.ts",
"main": "index",
"files": [
"index.js",
"index.d.ts",
"main.js",
"main.es.js"
"index.ts"
],
"scripts": {
"pretest": "rollup -c ../../rollup.config.js",
"test": "node -r @std/esm test.js",
"posttest": "node -r @std/esm ../../scripts/validate-es5-dependencies.js",
"bench": "node -r @std/esm bench.js",
"pretest": "tsc",
"test": "node test.js",
"bench": "node bench.js",
"docs": "node ../../scripts/generate-readmes"
},
"repository": {
@ -29,10 +24,9 @@
},
"homepage": "https://github.com/Turfjs/turf",
"devDependencies": {
"@std/esm": "*",
"@turf/along": "^5.1.5",
"@turf/length": "^5.1.5",
"@turf/truncate": "^5.1.5",
"@turf/along": "*",
"@turf/length": "*",
"@turf/truncate": "*",
"benchmark": "*",
"load-json-file": "*",
"rollup": "*",
@ -40,16 +34,12 @@
"write-json-file": "*"
},
"dependencies": {
"@turf/bearing": "^5.1.5",
"@turf/destination": "^5.1.5",
"@turf/distance": "^5.1.5",
"@turf/bearing": "*",
"@turf/destination": "*",
"@turf/distance": "*",
"@turf/helpers": "6.x",
"@turf/invariant": "6.x",
"@turf/line-intersect": "6.x",
"@turf/meta": "6.x"
},
"@std/esm": {
"esm": "js",
"cjs": true
}
}

View File

@ -1,14 +1,14 @@
import fs from 'fs';
import test from 'tape';
import path from 'path';
import load from 'load-json-file';
import write from 'write-json-file';
import along from '@turf/along';
import distance from '@turf/distance';
import truncate from '@turf/truncate';
import length from '@turf/length';
import { lineString, multiLineString, point, featureCollection, round } from '@turf/helpers';
import nearestPointOnLine from '.';
const fs = require('fs');
const test = require('tape');
const path = require('path');
const load = require('load-json-file');
const write = require('write-json-file');
const along = require('@turf/along').default;
const distance = require('@turf/distance').default;
const truncate = require('@turf/truncate').default;
const length = require('@turf/length').default;
const { lineString, multiLineString, point, featureCollection, round } = require('@turf/helpers');
const nearestPointOnLine = require('./').default;
const directories = {
in: path.join(__dirname, 'test', 'in') + path.sep,