Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename modules/methods Turf v5.0 #1055

Merged
merged 35 commits into from
Oct 31, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
22cf57e
Rename helpers methods
DenisCarriere Oct 29, 2017
2b95981
Fix @turf/destination
DenisCarriere Oct 29, 2017
bffe391
Update @turf/bearing
DenisCarriere Oct 29, 2017
61d8fd2
Rename bearingToAzimuth
DenisCarriere Oct 29, 2017
36f387b
Drop IDW
DenisCarriere Oct 29, 2017
fb14e1a
Rename line-distance to length
DenisCarriere Oct 29, 2017
730be2e
Rename pointOnLine => nearestPointOnLine
DenisCarriere Oct 30, 2017
05ba7dc
Fix distance
DenisCarriere Oct 30, 2017
2fa4985
Update readmes
DenisCarriere Oct 30, 2017
daa01dd
Fix line-chunk
DenisCarriere Oct 30, 2017
526878c
Rename nearest => nearest-point
DenisCarriere Oct 30, 2017
e612665
Update @turf/turf package names
DenisCarriere Oct 30, 2017
d1c65f5
Merge branch 'master' into helpers-rename-methods
DenisCarriere Oct 30, 2017
3c31f6b
Place 3rd party dependencies to lib
DenisCarriere Oct 30, 2017
d427b10
Re-order import
DenisCarriere Oct 30, 2017
dbaacb3
Add @turf/length to package.json
DenisCarriere Oct 30, 2017
79d80df
Improve nearest-point testing
DenisCarriere Oct 30, 2017
8d5f8d7
Publish clone 5.x
DenisCarriere Oct 30, 2017
546f8b4
Update dependencies
DenisCarriere Oct 30, 2017
f2313f5
Merge branch 'master' into helpers-rename-methods
DenisCarriere Oct 30, 2017
5ff3e06
Update depedencies
DenisCarriere Oct 30, 2017
335f84d
Merge branch 'helpers-rename-methods' of github.com:Turfjs/turf into …
DenisCarriere Oct 30, 2017
6627ff2
Merge branch 'master' into helpers-rename-methods
DenisCarriere Oct 30, 2017
b4ba85f
Rename convertDistance => convertLength
DenisCarriere Oct 30, 2017
2018779
Fix deprecated modules/methods
DenisCarriere Oct 30, 2017
b6e0476
Rename bezier => bezier-spline
DenisCarriere Oct 30, 2017
f554a74
Remove isolines from JSDocs testing
DenisCarriere Oct 30, 2017
07b9cda
Rename @turf/within => points-within-polygon
DenisCarriere Oct 30, 2017
57bc412
Rename inside => boolean-point-in-polygon
DenisCarriere Oct 31, 2017
070d370
add inside
DenisCarriere Oct 31, 2017
53f1564
Update boolean-point-in-polygon
DenisCarriere Oct 31, 2017
26b75b1
Update more inside
DenisCarriere Oct 31, 2017
b0393b9
Update boolean-point-in-polygon
DenisCarriere Oct 31, 2017
13a6f68
Update nearest-point test fixture
DenisCarriere Oct 31, 2017
246578a
Round dist
DenisCarriere Oct 31, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 6 additions & 10 deletions packages/turf-bearing/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getCoord } from '@turf/invariant';
import { isObject } from '@turf/helpers';
import { isObject, degreesToRadians, radiansToDegrees } from '@turf/helpers';

//http://en.wikipedia.org/wiki/Haversine_formula
//http://www.movable-type.co.uk/scripts/latlong.html
Expand Down Expand Up @@ -35,22 +35,18 @@ function bearing(start, end, options) {
// Reverse calculation
if (final === true) return calculateFinalBearing(start, end);

var degrees2radians = Math.PI / 180;
var radians2degrees = 180 / Math.PI;
var coordinates1 = getCoord(start);
var coordinates2 = getCoord(end);

var lon1 = degrees2radians * coordinates1[0];
var lon2 = degrees2radians * coordinates2[0];
var lat1 = degrees2radians * coordinates1[1];
var lat2 = degrees2radians * coordinates2[1];
var lon1 = degreesToRadians(coordinates1[0]);
var lon2 = degreesToRadians(coordinates2[0]);
var lat1 = degreesToRadians(coordinates1[1]);
var lat2 = degreesToRadians(coordinates2[1]);
var a = Math.sin(lon2 - lon1) * Math.cos(lat2);
var b = Math.cos(lat1) * Math.sin(lat2) -
Math.sin(lat1) * Math.cos(lat2) * Math.cos(lon2 - lon1);

var bear = radians2degrees * Math.atan2(a, b);

return bear;
return radiansToDegrees(Math.atan2(a, b));
}

/**
Expand Down
6 changes: 3 additions & 3 deletions packages/turf-bearing/test/out/results.geojson
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
45
],
[
-66.09750711447153,
-66.09750711447151,
51.79525668362472
]
]
Expand All @@ -61,8 +61,8 @@
60
],
[
2.3783964911248785,
63.44109820672927
2.3783964911248754,
63.441098206729286
]
]
}
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Benchmark from 'benchmark';
import path from 'path';
import fs from 'fs';
import load from 'load-json-file';
import bezier from './';
import bezierSpline from './';

const directory = path.join(__dirname, 'test', 'in') + path.sep;
const fixtures = fs.readdirSync(directory).map(filename => {
Expand All @@ -19,9 +19,9 @@ const fixtures = fs.readdirSync(directory).map(filename => {
* bezierIn x 771 ops/sec ±1.31% (88 runs sampled)
* simple x 768 ops/sec ±1.20% (89 runs sampled)
*/
const suite = new Benchmark.Suite('turf-bezier');
const suite = new Benchmark.Suite('turf-bezier-spline');
for (const {name, geojson} of fixtures) {
suite.add(name, () => bezier(geojson));
suite.add(name, () => bezierSpline(geojson));
}

suite
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { LineString, Feature } from '@turf/helpers'

/**
* http://turfjs.org/docs/#bezier
* http://turfjs.org/docs/#bezierspline
*/
export default function bezier(
export default function bezierSpline(
line: Feature<LineString> | LineString,
options?: {
resolution?: number;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { lineString } from '@turf/helpers';
import { lineString, isObject, isNumber } from '@turf/helpers';
import { getGeom } from '@turf/invariant';
import Spline from './spline.js';
import Spline from './lib/spline';

/**
* Takes a {@link LineString|line} and returns a curved version
Expand All @@ -11,7 +11,7 @@ import Spline from './spline.js';
*
* @name bezier
* @param {Geometry|Feature<LineString>} line input LineString
* @param {object} [options] Optional parameters
* @param {Object} [options={}] Optional parameters
* @param {number} [options.resolution=10000] time in milliseconds between points
* @param {number} [options.sharpness=0.85] a measure of how curvy the path should be between splines
* @returns {Feature<LineString>} curved line
Expand All @@ -25,7 +25,7 @@ import Spline from './spline.js';
* [-73.157958, 20.210656]
* ]);
*
* var curved = turf.bezier(line);
* var curved = turf.bezierSpline(line);
*
* //addToMap
* var addToMap = [line, curved]
Expand All @@ -34,13 +34,14 @@ import Spline from './spline.js';
function bezier(line, options) {
// Optional params
options = options || {};
if (!isObject(options)) throw new Error('options is invalid');
var resolution = options.resolution || 10000;
var sharpness = options.sharpness || 0.85;

// validation
if (typeof options !== 'object') throw new Error('options must be an object');
if (typeof resolution !== 'number') throw new Error('resolution must be an number');
if (typeof sharpness !== 'number') throw new Error('sharpness must be an number');
if (!line) throw new Error('line is required');
if (!isNumber(resolution)) throw new Error('resolution must be an number');
if (!isNumber(sharpness)) throw new Error('sharpness must be an number');

var coords = [];
var spline = new Spline({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
{
"name": "@turf/bezier",
"version": "4.7.3",
"description": "turf bezier module",
"name": "@turf/bezier-spline",
"version": "5.0.0",
"description": "turf bezier-spline module",
"main": "main",
"module": "index",
"jsnext:main": "index",
"types": "index.d.ts",
"files": [
"index.js",
"index.d.ts",
"spline.js",
"main.js"
"main.js",
"lib"
],
"scripts": {
"pretest": "rollup -c ../../rollup.config.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import path from 'path';
import load from 'load-json-file';
import write from 'write-json-file';
import { featureCollection } from '@turf/helpers';
import bezier from '.';
import bezierSpline from '.';

const directories = {
in: path.join(__dirname, 'test', 'in') + path.sep,
Expand All @@ -19,12 +19,12 @@ const fixtures = fs.readdirSync(directories.in).map(filename => {
};
});

test('turf-bezier', t => {
test('turf-bezier-spline', t => {
fixtures.forEach(fixture => {
const filename = fixture.filename;
const name = fixture.name;
const geojson = fixture.geojson;
const spline = colorize(bezier(geojson));
const spline = colorize(bezierSpline(geojson));
const results = featureCollection([spline, geojson]);

if (process.env.REGEN) write.sync(directories.out + filename, results);
Expand Down
File renamed without changes.
10 changes: 5 additions & 5 deletions packages/turf-boolean-contains/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import inside from '@turf/inside';
import booleanPointInPolygon from '@turf/boolean-point-in-polygon';
import calcBbox from '@turf/bbox';
import isPointOnLine from '@turf/boolean-point-on-line';
import { getGeom, getCoords, getType } from '@turf/invariant';
Expand Down Expand Up @@ -59,7 +59,7 @@ function booleanContains(feature1, feature2) {
case 'Polygon':
switch (type2) {
case 'Point':
return inside(geom2, geom1, {ignoreBoundary: true});
return booleanPointInPolygon(geom2, geom1, {ignoreBoundary: true});
case 'LineString':
return isLineInPoly(geom1, geom2);
case 'Polygon':
Expand Down Expand Up @@ -121,7 +121,7 @@ function isMultiPointOnLine(lineString, multiPoint) {

function isMultiPointInPoly(polygon, multiPoint) {
for (var i = 0; i < multiPoint.coordinates.length; i++) {
if (!inside(multiPoint.coordinates[i], polygon, {ignoreBoundary: true})) {
if (!booleanPointInPolygon(multiPoint.coordinates[i], polygon, {ignoreBoundary: true})) {
return false;
}
}
Expand Down Expand Up @@ -152,7 +152,7 @@ function isLineInPoly(polygon, linestring) {
}
for (i; i < linestring.coordinates.length - 1; i++) {
var midPoint = getMidpoint(linestring.coordinates[i], linestring.coordinates[i + 1]);
if (inside({type: 'Point', coordinates: midPoint}, polygon, { ignoreBoundary: true })) {
if (booleanPointInPolygon({type: 'Point', coordinates: midPoint}, polygon, { ignoreBoundary: true })) {
output = true;
break;
}
Expand All @@ -176,7 +176,7 @@ function isPolyInPoly(feature1, feature2) {
return false;
}
for (var i = 0; i < feature2.coordinates[0].length; i++) {
if (!inside(feature2.coordinates[0][i], feature1)) {
if (!booleanPointInPolygon(feature2.coordinates[0][i], feature1)) {
return false;
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/turf-boolean-contains/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"@turf/bbox": "5.x",
"@turf/boolean-point-on-line": "^4.7.3",
"@turf/helpers": "5.x",
"@turf/inside": "5.x",
"@turf/boolean-point-in-polygon": "5.x",
"@turf/invariant": "5.x"
},
"@std/esm": {
Expand Down
43 changes: 41 additions & 2 deletions packages/turf-boolean-contains/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,47 @@


"@std/esm@*":
version "0.12.1"
resolved "https://registry.yarnpkg.com/@std/esm/-/esm-0.12.1.tgz#d07b7c5e2701beade1e7db74b95484f5d91c46bf"
version "0.12.5"
resolved "https://registry.yarnpkg.com/@std/esm/-/esm-0.12.5.tgz#b38a9bc70462df18a09b16f653141b9ab5557635"

"@turf/bbox@5.x":
version "5.0.0"
resolved "https://registry.yarnpkg.com/@turf/bbox/-/bbox-5.0.0.tgz#c179e533328120ca29b5dbd215a5f54e5c7940d3"
dependencies:
"@turf/helpers" "5.0.0"
"@turf/meta" "5.0.0"

"@turf/boolean-point-in-polygon@5.x":
version "5.0.0"
resolved "https://registry.yarnpkg.com/@turf/boolean-point-in-polygon/-/boolean-point-in-polygon-5.0.0.tgz#adc998d5f1cec116c024281d62abd85fdc2c948a"
dependencies:
"@turf/invariant" "5.x"

"@turf/boolean-point-on-line@^4.7.3":
version "4.7.3"
resolved "https://registry.yarnpkg.com/@turf/boolean-point-on-line/-/boolean-point-on-line-4.7.3.tgz#68ee97b70bc6255f67cd1e51a45658411bcb9799"
dependencies:
"@turf/invariant" "^4.7.3"

"@turf/helpers@5.0.0":
version "5.0.0"
resolved "https://registry.yarnpkg.com/@turf/helpers/-/helpers-5.0.0.tgz#732cb570e6aebca9ef7375e8e42fafa8e16e5d47"

"@turf/helpers@5.x":
version "5.0.1"
resolved "https://registry.yarnpkg.com/@turf/helpers/-/helpers-5.0.1.tgz#d950df25b10c9ed347f7811927ec14e72ccc58b2"

"@turf/invariant@5.x":
version "5.0.0"
resolved "https://registry.yarnpkg.com/@turf/invariant/-/invariant-5.0.0.tgz#da9b4d7b044cffa300d654b3e0444969fc19d850"

"@turf/invariant@^4.7.3":
version "4.7.3"
resolved "https://registry.yarnpkg.com/@turf/invariant/-/invariant-4.7.3.tgz#538f367d23c113fc849d70c9a524b8563874601d"

"@turf/meta@5.0.0":
version "5.0.0"
resolved "https://registry.yarnpkg.com/@turf/meta/-/meta-5.0.0.tgz#75b100e9854cd7b2fa63e68561e1298dac09d7b4"

balanced-match@^1.0.0:
version "1.0.0"
Expand Down
8 changes: 2 additions & 6 deletions packages/turf-boolean-crosses/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { point } from '@turf/helpers';
import inside from '@turf/inside';
import booleanPointInPolygon from '@turf/boolean-point-in-polygon';
import lineIntersect from '@turf/line-intersect';
import polyToLinestring from '@turf/polygon-to-linestring';
import { getGeom, getType } from '@turf/invariant';
Expand Down Expand Up @@ -111,17 +111,13 @@ function doLineStringAndPolygonCross(lineString, polygon) {
return false;
}

function isPointInPoly(polygon, point) {
return inside(point, polygon);
}

function doesMultiPointCrossPoly(multiPoint, polygon) {
var foundIntPoint = false;
var foundExtPoint = false;
var pointLength = multiPoint.coordinates[0].length;
var i = 0;
while (i < pointLength && foundIntPoint && foundExtPoint) {
if (isPointInPoly(polygon, point(multiPoint.coordinates[0][i]), true)) {
if (booleanPointInPolygon(point(multiPoint.coordinates[0][i]), polygon)) {
foundIntPoint = true;
} else {
foundExtPoint = true;
Expand Down
2 changes: 1 addition & 1 deletion packages/turf-boolean-crosses/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
},
"dependencies": {
"@turf/helpers": "5.x",
"@turf/inside": "5.x",
"@turf/boolean-point-in-polygon": "5.x",
"@turf/invariant": "5.x",
"@turf/line-intersect": "5.x",
"@turf/polygon-to-linestring": "5.x"
Expand Down
Loading