Lots of updates
This commit is contained in:
parent
e3cfff8310
commit
39e7af6238
454 changed files with 221168 additions and 36622 deletions
12
app/bower_components/geolib/.bower.json
vendored
12
app/bower_components/geolib/.bower.json
vendored
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "Geolib",
|
||||
"main": "dist/geolib.js",
|
||||
"version": "2.0.9",
|
||||
"version": "2.0.21",
|
||||
"homepage": "https://github.com/manuelbieh/Geolib",
|
||||
"authors": [
|
||||
"Manuel Bieh <github@manuelbieh.de>"
|
||||
|
@ -20,13 +20,13 @@
|
|||
"test",
|
||||
"tests"
|
||||
],
|
||||
"_release": "2.0.9",
|
||||
"_release": "2.0.21",
|
||||
"_resolution": {
|
||||
"type": "version",
|
||||
"tag": "2.0.9",
|
||||
"commit": "c4222cde0d201e5d03f0d70ae560a5707907761c"
|
||||
"tag": "2.0.21",
|
||||
"commit": "0406fbd120cb371a89a1676e47e9de5f0e51a4a5"
|
||||
},
|
||||
"_source": "git://github.com/manuelbieh/Geolib.git",
|
||||
"_target": "~2.0.9",
|
||||
"_source": "https://github.com/manuelbieh/Geolib.git",
|
||||
"_target": "~2.0.21",
|
||||
"_originalSource": "geolib"
|
||||
}
|
40
app/bower_components/geolib/Gruntfile.js
vendored
40
app/bower_components/geolib/Gruntfile.js
vendored
|
@ -101,19 +101,30 @@ module.exports = function(grunt) {
|
|||
src: ['src/geolib.elevation.js'],
|
||||
dest: 'dist/geolib.elevation.js'
|
||||
}]
|
||||
}
|
||||
},
|
||||
pointInside: {
|
||||
files: [{
|
||||
src: ['src/geolib.isPointInsideRobust.js'],
|
||||
dest: 'dist/geolib.isPointInsideRobust.js'
|
||||
}]
|
||||
},
|
||||
},
|
||||
replace: {
|
||||
version: {
|
||||
src: ['dist/*.js', 'bower.json'],
|
||||
src: ['dist/*.js', 'bower.json', 'README.md'],
|
||||
overwrite: true,
|
||||
replacements: [{
|
||||
from: '$version$',
|
||||
to: '<%= pkg.version %>'
|
||||
}, {
|
||||
from: /"version": "([0-9a-zA-Z\-\.\+]*)",/,
|
||||
to: '"version": "<%= pkg.version %>",'
|
||||
}]
|
||||
replacements: [
|
||||
{
|
||||
from: '$version$',
|
||||
to: '<%= pkg.version %>'
|
||||
}, {
|
||||
from: /"version": "([0-9a-zA-Z\-\.\+]*)",/,
|
||||
to: '"version": "<%= pkg.version %>",'
|
||||
}, {
|
||||
from: /v[0-9]+\.[0-9]{1,2}\.[0-9]{1,}/,
|
||||
to: 'v<%= pkg.version %>'
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
uglify: {
|
||||
|
@ -129,7 +140,12 @@ module.exports = function(grunt) {
|
|||
files: {
|
||||
'dist/geolib.elevation.min.js': ['dist/geolib.elevation.js']
|
||||
}
|
||||
}
|
||||
},
|
||||
pointInside: {
|
||||
files: {
|
||||
'dist/geolib.isPointInsideRobust.min.js': ['dist/geolib.isPointInsideRobust.js']
|
||||
}
|
||||
},
|
||||
},
|
||||
watch: {
|
||||
all: {
|
||||
|
@ -140,7 +156,8 @@ module.exports = function(grunt) {
|
|||
jshint: {
|
||||
all: [
|
||||
'src/geolib.js',
|
||||
'src/geolib.elevation.js'
|
||||
'src/geolib.elevation.js',
|
||||
'src/geolib.isPointInsideRobust.js',
|
||||
],
|
||||
options: {
|
||||
curly: true,
|
||||
|
@ -151,6 +168,7 @@ module.exports = function(grunt) {
|
|||
noarg: true,
|
||||
sub: true,
|
||||
undef: true,
|
||||
evil: true,
|
||||
boss: true,
|
||||
eqnull: true,
|
||||
globals: {
|
||||
|
|
189
app/bower_components/geolib/README.md
vendored
189
app/bower_components/geolib/README.md
vendored
|
@ -1,4 +1,4 @@
|
|||
# Geolib v2.0.9
|
||||
# Geolib v2.0.21
|
||||
[](http://travis-ci.org/manuelbieh/Geolib)
|
||||
|
||||
Library to provide basic geospatial operations like distance calculation, conversion of decimal coordinates to sexagesimal and vice versa, etc.
|
||||
|
@ -7,39 +7,39 @@ Library to provide basic geospatial operations like distance calculation, conver
|
|||
|
||||
<h2>Methods</h2>
|
||||
|
||||
<h3>geolib.getDistance(object start, object end[, int accuracy])</h3>
|
||||
<h3>geolib.getDistance(object start, object end[, int accuracy, int precision])</h3>
|
||||
|
||||
Calculates the distance between two geo coordinates
|
||||
|
||||
Takes 2 or 3 arguments. First 2 arguments must be an object with latitude and a longitude properties (e.g. `{latitude: 52.518611, longitude: 13.408056}`). Coordinates can be in sexagesimal or decimal format. 3rd argument is accuracy (in meters). So a calculated distance of 1248 meters with an accuracy of 100 is returned as `1200` (accuracy 10 = `1250` etc.).
|
||||
Takes 2 or 4 arguments. First 2 arguments must be objects that each have latitude and longitude properties (e.g. `{latitude: 52.518611, longitude: 13.408056}`)Works with:. Coordinates can be in sexagesimal or decimal format. 3rd argument is accuracy (in meters). So a calculated distaWorks with:nce of 1248 meters with an accuracy of 100 is returned as `1200` (accuracy 10 = `1250` etc.). 4th argument is precision in sub-meters (1 is meter presicion, 2 is decimeters, 3 is centimeters, etc).
|
||||
|
||||
Return value is always an integer and represents the distance in meters.
|
||||
Return value is always an float and represents the distance in meters.
|
||||
|
||||
<h4>Examples</h4>
|
||||
|
||||
<pre>geolib.getDistance(
|
||||
{latitude: 51.5103, longitude: 7.49347},
|
||||
{latitude: "51° 31' N", longitude: "7° 28' E"}
|
||||
{latitude: 51.5103, longitude: 7.49347},
|
||||
{latitude: "51° 31' N", longitude: "7° 28' E"}
|
||||
);
|
||||
geolib.getDistance(
|
||||
{latitude: 51.5103, longitude: 7.49347},
|
||||
{latitude: "51° 31' N", longitude: "7° 28' E"}
|
||||
{latitude: 51.5103, longitude: 7.49347},
|
||||
{latitude: "51° 31' N", longitude: "7° 28' E"}
|
||||
);
|
||||
|
||||
// Working with W3C Geolocation API
|
||||
navigator.geolocation.getCurrentPosition(
|
||||
function(position) {
|
||||
alert('You are ' + geolib.getDistance(position.coords, {
|
||||
latitude: 51.525,
|
||||
longitude: 7.4575
|
||||
}) + ' meters away from 51.525, 7.4575');
|
||||
},
|
||||
function() {
|
||||
alert('Position could not be determined.')
|
||||
},
|
||||
{
|
||||
enableHighAccuracy: true
|
||||
}
|
||||
function(position) {
|
||||
alert('You are ' + geolib.getDistance(position.coords, {
|
||||
latitude: 51.525,
|
||||
longitude: 7.4575
|
||||
}) + ' meters away from 51.525, 7.4575');
|
||||
},
|
||||
function() {
|
||||
alert('Position could not be determined.')
|
||||
},
|
||||
{
|
||||
enableHighAccuracy: true
|
||||
}
|
||||
);
|
||||
</pre>
|
||||
|
||||
|
@ -49,32 +49,48 @@ Calculates the geographical center of all points in a collection of geo coordina
|
|||
|
||||
Takes an object or array of coordinates and calculates the center of it.
|
||||
|
||||
Returns an object: `{"latitude": centerLat, "longitude": centerLng, "distance": diagonalDistance}`
|
||||
Returns an object: `{"latitude": centerLat, "longitude": centerLng}`
|
||||
|
||||
<h4>Examples</h4>
|
||||
|
||||
<pre>var spots = {
|
||||
"Brandenburg Gate, Berlin": {latitude: 52.516272, longitude: 13.377722},
|
||||
"Dortmund U-Tower": {latitude: 51.515, longitude: 7.453619},
|
||||
"London Eye": {latitude: 51.503333, longitude: -0.119722},
|
||||
"Kremlin, Moscow": {latitude: 55.751667, longitude: 37.617778},
|
||||
"Eiffel Tower, Paris": {latitude: 48.8583, longitude: 2.2945},
|
||||
"Riksdag building, Stockholm": {latitude: 59.3275, longitude: 18.0675},
|
||||
"Royal Palace, Oslo": {latitude: 59.916911, longitude: 10.727567}
|
||||
"Brandenburg Gate, Berlin": {latitude: 52.516272, longitude: 13.377722},
|
||||
"Dortmund U-Tower": {latitude: 51.515, longitude: 7.453619},
|
||||
"London Eye": {latitude: 51.503333, longitude: -0.119722},
|
||||
"Kremlin, Moscow": {latitude: 55.751667, longitude: 37.617778},
|
||||
"Eiffel Tower, Paris": {latitude: 48.8583, longitude: 2.2945},
|
||||
"Riksdag building, Stockholm": {latitude: 59.3275, longitude: 18.0675},
|
||||
"Royal Palace, Oslo": {latitude: 59.916911, longitude: 10.727567}
|
||||
}
|
||||
|
||||
geolib.getCenter(spots);
|
||||
|
||||
geolib.getCenter([
|
||||
{latitude: 52.516272, longitude: 13.377722},
|
||||
{latitude: 51.515, longitude: 7.453619},
|
||||
{latitude: 51.503333, longitude: -0.119722}
|
||||
{latitude: 52.516272, longitude: 13.377722},
|
||||
{latitude: 51.515, longitude: 7.453619},
|
||||
{latitude: 51.503333, longitude: -0.119722}
|
||||
]);
|
||||
</pre>
|
||||
|
||||
<h3>geolib.isPointInside(object latlng, array coords)</h3>
|
||||
<h3>geolib.getCenterOfBounds(array coords)</h3>
|
||||
|
||||
Checks whether a point is inside of a polygon or not.
|
||||
Calculates the center of the bounds of geo coordinates.
|
||||
|
||||
Takes an array of coordinates, calculate the border of those, and gives back
|
||||
the center of that rectangle.
|
||||
|
||||
On polygons like political borders (eg. states), this may gives a closer
|
||||
result to human expectation, than `getCenter`, because that function can be
|
||||
disturbed by uneven distribution of point in different sides.
|
||||
|
||||
Imagine the US state Oklahoma: `getCenter` on that gives a southern
|
||||
point, because the southern border contains a lot more nodes, than the others.
|
||||
|
||||
Returns an object: `{"latitude": centerLat, "longitude": centerLng}`
|
||||
|
||||
<h3>geolib.isPointInside(object latlng, array polygon)</h3>
|
||||
|
||||
Checks whether a point is inside of a polygon or not.
|
||||
Note: the polygon coords must be in correct order!
|
||||
|
||||
Returns true or false
|
||||
|
@ -83,18 +99,18 @@ Returns true or false
|
|||
|
||||
<pre>
|
||||
geolib.isPointInside(
|
||||
{latitude: 51.5125, longitude: 7.485},
|
||||
[
|
||||
{latitude: 51.50, longitude: 7.40},
|
||||
{latitude: 51.555, longitude: 7.40},
|
||||
{latitude: 51.555, longitude: 7.625},
|
||||
{latitude: 51.5125, longitude: 7.625}
|
||||
]
|
||||
{latitude: 51.5125, longitude: 7.485},
|
||||
[
|
||||
{latitude: 51.50, longitude: 7.40},
|
||||
{latitude: 51.555, longitude: 7.40},
|
||||
{latitude: 51.555, longitude: 7.625},
|
||||
{latitude: 51.5125, longitude: 7.625}
|
||||
]
|
||||
); // -> true</pre>
|
||||
|
||||
<h3>geolib.isPointInCircle(object latlng, object center, integer radius)</h3>
|
||||
|
||||
Similar to is point inside: checks whether a point is inside of a circle or not.
|
||||
Similar to is point inside: checks whether a point is inside of a circle or not.
|
||||
|
||||
Returns true or false
|
||||
|
||||
|
@ -102,9 +118,9 @@ Returns true or false
|
|||
|
||||
<pre>// checks if 51.525, 7.4575 is within a radius of 5km from 51.5175, 7.4678
|
||||
geolib.isPointInCircle(
|
||||
{latitude: 51.525, longitude: 7.4575},
|
||||
{latitude: 51.5175, longitude: 7.4678},
|
||||
5000
|
||||
{latitude: 51.525, longitude: 7.4575},
|
||||
{latitude: 51.5175, longitude: 7.4678},
|
||||
5000
|
||||
);</pre>
|
||||
|
||||
<h3>geolib.orderByDistance(object latlng, mixed coords)</h3>
|
||||
|
@ -118,16 +134,16 @@ Returns a sorted array [{latitude: x, longitude: y, distance: z, key: property}]
|
|||
<pre>
|
||||
// coords array
|
||||
geolib.orderByDistance({latitude: 51.515, longitude: 7.453619}, [
|
||||
{latitude: 52.516272, longitude: 13.377722},
|
||||
{latitude: 51.518, longitude: 7.45425},
|
||||
{latitude: 51.503333, longitude: -0.119722}
|
||||
{latitude: 52.516272, longitude: 13.377722},
|
||||
{latitude: 51.518, longitude: 7.45425},
|
||||
{latitude: 51.503333, longitude: -0.119722}
|
||||
]);
|
||||
|
||||
// coords object
|
||||
geolib.orderByDistance({latitude: 51.515, longitude: 7.453619}, {
|
||||
a: {latitude: 52.516272, longitude: 13.377722},
|
||||
b: {latitude: 51.518, longitude: 7.45425},
|
||||
c: {latitude: 51.503333, longitude: -0.119722}
|
||||
a: {latitude: 52.516272, longitude: 13.377722},
|
||||
b: {latitude: 51.518, longitude: 7.45425},
|
||||
c: {latitude: 51.503333, longitude: -0.119722}
|
||||
});
|
||||
</pre>
|
||||
|
||||
|
@ -138,17 +154,17 @@ Finds the nearest coordinate to a reference coordinate.
|
|||
<h4>Examples</h4>
|
||||
|
||||
<pre>var spots = {
|
||||
"Brandenburg Gate, Berlin": {latitude: 52.516272, longitude: 13.377722},
|
||||
"Dortmund U-Tower": {latitude: 51.515, longitude: 7.453619},
|
||||
"London Eye": {latitude: 51.503333, longitude: -0.119722},
|
||||
"Kremlin, Moscow": {latitude: 55.751667, longitude: 37.617778},
|
||||
"Eiffel Tower, Paris": {latitude: 48.8583, longitude: 2.2945},
|
||||
"Riksdag building, Stockholm": {latitude: 59.3275, longitude: 18.0675},
|
||||
"Royal Palace, Oslo": {latitude: 59.916911, longitude: 10.727567}
|
||||
"Brandenburg Gate, Berlin": {latitude: 52.516272, longitude: 13.377722},
|
||||
"Dortmund U-Tower": {latitude: 51.515, longitude: 7.453619},
|
||||
"London Eye": {latitude: 51.503333, longitude: -0.119722},
|
||||
"Kremlin, Moscow": {latitude: 55.751667, longitude: 37.617778},
|
||||
"Eiffel Tower, Paris": {latitude: 48.8583, longitude: 2.2945},
|
||||
"Riksdag building, Stockholm": {latitude: 59.3275, longitude: 18.0675},
|
||||
"Royal Palace, Oslo": {latitude: 59.916911, longitude: 10.727567}
|
||||
}
|
||||
|
||||
// in this case set offset to 1 otherwise the nearest point will always be your reference point
|
||||
geolib.findNearest(spots['Dortmund U-Tower'], spots, 1)
|
||||
geolib.findNearest(spots['Dortmund U-Tower'], spots, 1)
|
||||
</pre>
|
||||
|
||||
<h3>geolib.getPathLength(mixed coords)</h3>
|
||||
|
@ -162,9 +178,9 @@ Returns the length of the path in meters
|
|||
<pre>
|
||||
// Calculate distance from Berlin via Dortmund to London
|
||||
geolib.getPathLength([
|
||||
{latitude: 52.516272, longitude: 13.377722}, // Berlin
|
||||
{latitude: 51.515, longitude: 7.453619}, // Dortmund
|
||||
{latitude: 51.503333, longitude: -0.119722} // London
|
||||
{latitude: 52.516272, longitude: 13.377722}, // Berlin
|
||||
{latitude: 51.515, longitude: 7.453619}, // Dortmund
|
||||
{latitude: 51.503333, longitude: -0.119722} // London
|
||||
]); // -> 945235</pre>
|
||||
|
||||
<h3>geolib.getSpeed(coords, coords[, options])</h3>
|
||||
|
@ -177,11 +193,30 @@ Returns the speed in <em>options.unit</em> (default is km/h).
|
|||
|
||||
<pre>
|
||||
geolib.getSpeed(
|
||||
{lat: 51.567294, lng: 7.38896, time: 1360231200880},
|
||||
{lat: 52.54944, lng: 13.468509, time: 1360245600880},
|
||||
{unit: 'mph'}
|
||||
{lat: 51.567294, lng: 7.38896, time: 1360231200880},
|
||||
{lat: 52.54944, lng: 13.468509, time: 1360245600880},
|
||||
{unit: 'mph'}
|
||||
); // -> 66.9408 (mph)</pre>
|
||||
|
||||
<h3>geolib.isPointInLine(object point, object start, object end</h3>
|
||||
|
||||
Calculates if given point lies in a line formed by start and end.
|
||||
|
||||
Returns true or false
|
||||
|
||||
<h4>Examples</h4>
|
||||
|
||||
<pre>var point1 = {latitude: 0.5, longitude: 0};
|
||||
var point2 = {latitude: 0, longitude: 10};
|
||||
var point3 = {latitude: 0, longitude: 15.5};
|
||||
var start = {latitude: 0, longitude: 0};
|
||||
var end = {latitude: 0, longitude: 15};
|
||||
|
||||
var isInLine1 = geolib.isPointInLine(point1, start, end) //-> false;
|
||||
var isInLine2 = geolib.isPointInLine(point2, start, end) //-> true;
|
||||
var isInLine3 = geolib.isPointInLine(point3, start, end) //-> false;
|
||||
</pre>
|
||||
|
||||
<h3>geolib.convertUnit(string unit, float distance[, int round])</h3>
|
||||
|
||||
Converts a given distance (in meters) to another unit.
|
||||
|
@ -231,8 +266,8 @@ Converts a decimal coordinate to sexagesimal format
|
|||
Returns the latitude/longitude/elevation for a given point and converts it to decimal.
|
||||
|
||||
Works with:
|
||||
- latitude: `latitude`, `lat`, 0 (GeoJSON array)
|
||||
- longitude: `longitude`, `lng`, `lon`, 1 (GeoJSON array)
|
||||
- longitude: `longitude`, `lng`, `lon`, 0 (GeoJSON array)
|
||||
- latitude: `latitude`, `lat`, 1 (GeoJSON array)
|
||||
- elevation: `elevation`, `elev`, `alt`, `altitude`, 2 (GeoJSON array)
|
||||
|
||||
<h4>Examples</h4>
|
||||
|
@ -249,6 +284,26 @@ Checks if a coordinate is already in decimal format and, if not, converts it to
|
|||
<pre>geolib.useDecimal("51° 29' 46\" N"); // -> 51.59611111
|
||||
geolib.useDecimal(51.59611111) // -> 51.59611111</pre>
|
||||
|
||||
<h3>geolib.computeDestinationPoint(start, distance, bearing, radius(optional))</h3>
|
||||
|
||||
Computes the destination point given an initial point, a distance and a bearing
|
||||
|
||||
If no radius is given it defaults to the mean earth radius of 6371000 meter.
|
||||
|
||||
Returns an object: `{"latitude": destLat, "longitude": destLng}`
|
||||
|
||||
(Attention: this formula is not *100%* accurate (but very close though))
|
||||
|
||||
<h4>Example</h4>
|
||||
|
||||
<pre>var initialPoint = {lat: 51.516272, lon: 0.45425}
|
||||
var dist = 1234;
|
||||
var bearing = 45;
|
||||
|
||||
geolib.computeDestinationPoint(initialPoint.lat, initialPoint.lon, dist, bearing);
|
||||
// -> {"latitude":51.52411853234181,"longitude":0.4668623365950795}
|
||||
</pre>
|
||||
|
||||
<h2>Changelog</h2>
|
||||
<h3>v2.0.0+beta1</h3>
|
||||
- Dropped support for IE6, IE7, IE8
|
||||
|
@ -259,4 +314,4 @@ geolib.useDecimal(51.59611111) // -> 51.59611111</pre>
|
|||
- Moved `geolib.elevation` to an optional module (`geolib.elevation.js`)
|
||||
- Using `Object.create(Geolib.prototype)` instead of object literal `{}`
|
||||
- New folder structure: compiled `geolib.js` can now be found in `dist/` instead of root dir
|
||||
- Improved Grunt build task
|
||||
- Improved Grunt build task
|
||||
|
|
2
app/bower_components/geolib/bower.json
vendored
2
app/bower_components/geolib/bower.json
vendored
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "Geolib",
|
||||
"main": "dist/geolib.js",
|
||||
"version": "2.0.9",
|
||||
"version": "2.0.21",
|
||||
"homepage": "https://github.com/manuelbieh/Geolib",
|
||||
"authors": [
|
||||
"Manuel Bieh <github@manuelbieh.de>"
|
||||
|
|
11
app/bower_components/geolib/component.json
vendored
11
app/bower_components/geolib/component.json
vendored
|
@ -19,7 +19,7 @@
|
|||
"grunt-contrib-qunit": "~0.2.0",
|
||||
"grunt-text-replace": "~0.3.6",
|
||||
"grunt-contrib-jshint": "~0.6.2",
|
||||
"phantomjs": "~1.8.0",
|
||||
"phantomjs": ">=1.8.0",
|
||||
"grunt-jslint": "~1.0.0",
|
||||
"time-grunt": "~0.3.1",
|
||||
"load-grunt-tasks": "~0.4.0"
|
||||
|
@ -31,7 +31,8 @@
|
|||
}
|
||||
],
|
||||
"files": [
|
||||
"geolib.js"
|
||||
"dist/geolib.js",
|
||||
"dist/geolib.elevation.js"
|
||||
],
|
||||
"description": "Library to perform geo specific tasks",
|
||||
"keywords": [
|
||||
|
@ -46,6 +47,6 @@
|
|||
"scripts": {
|
||||
"test": "grunt travis --verbose"
|
||||
},
|
||||
"version": "2.0.9",
|
||||
"main": "./geolib"
|
||||
}
|
||||
"version": "2.0.21",
|
||||
"main": "dist/geolib.js"
|
||||
}
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
/*! geolib.elevation 2.0.9 by Manuel Bieh
|
||||
/*! geolib.elevation 2.0.21 by Manuel Bieh
|
||||
*
|
||||
* Elevation Addon for Geolib.js
|
||||
*
|
||||
* @author Manuel Bieh
|
||||
* @url http://www.manuelbieh.com/
|
||||
* @version 2.0.9
|
||||
* @version 2.0.21
|
||||
* @license MIT
|
||||
*/
|
||||
;(function(global, geolib, undefined) {
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
/*! geolib.elevation 2.0.9 by Manuel Bieh
|
||||
/*! geolib.elevation 2.0.21 by Manuel Bieh
|
||||
*
|
||||
* Elevation Addon for Geolib.js
|
||||
*
|
||||
* @author Manuel Bieh
|
||||
* @url http://www.manuelbieh.com/
|
||||
* @version 2.0.9
|
||||
* @version 2.0.21
|
||||
* @license MIT
|
||||
*/
|
||||
!function(a,b){var c={getElevation:function(){"undefined"!=typeof a.navigator?this.getElevationClient.apply(this,arguments):this.getElevationServer.apply(this,arguments)},getElevationClient:function(b,c){if(!a.google)throw new Error("Google maps api not loaded");if(0===b.length)return c(null,null);if(1===b.length)return c(new Error("getElevation requires at least 2 points."));for(var d=[],e=0;e<b.length;e++)d.push(new google.maps.LatLng(this.latitude(b[e]),this.longitude(b[e])));var f={path:d,samples:d.length},g=new google.maps.ElevationService,h=this;g.getElevationAlongPath(f,function(a,d){h.elevationHandler(a,d,b,c)})},getElevationServer:function(a,b){if(0===a.length)return b(null,null);if(1===a.length)return b(new Error("getElevation requires at least 2 points."));for(var c=require("googlemaps"),d=[],e=0;e<a.length;e++)d.push(this.latitude(a[e])+","+this.longitude(a[e]));var f=this;c.elevationFromPath(d.join("|"),d.length,function(c,d){f.elevationHandler(d.results,d.status,a,b)})},elevationHandler:function(a,b,c,d){var e=[];if("OK"==b){for(var f=0;f<a.length;f++)e.push({lat:this.latitude(c[f]),lng:this.longitude(c[f]),elev:a[f].elevation});d(null,e)}else d(new Error("Could not get elevation using Google's API"),elevationResult.status)},getGrade:function(a){var b=Math.abs(this.elevation(a[a.length-1])-this.elevation(a[0])),c=this.getPathLength(a);return Math.floor(b/c*100)},getTotalElevationGainAndLoss:function(a){for(var b=0,c=0,d=0;d<a.length-1;d++){var e=this.elevation(a[d])-this.elevation(a[d+1]);e>0?c+=e:b+=Math.abs(e)}return{gain:b,loss:c}}};"undefined"!=typeof module&&"undefined"!=typeof module.exports?(b=require("geolib"),b.extend(c)):"function"==typeof define&&define.amd?define(["geolib"],function(a){return a.extend(c),a}):b.extend(c)}(this,this.geolib);
|
||||
!function(a,b,c){var d={getElevation:function(){"undefined"!=typeof a.navigator?this.getElevationClient.apply(this,arguments):this.getElevationServer.apply(this,arguments)},getElevationClient:function(b,c){if(!a.google)throw new Error("Google maps api not loaded");if(0===b.length)return c(null,null);if(1===b.length)return c(new Error("getElevation requires at least 2 points."));for(var d=[],e=0;e<b.length;e++)d.push(new google.maps.LatLng(this.latitude(b[e]),this.longitude(b[e])));var f={path:d,samples:d.length},g=new google.maps.ElevationService,h=this;g.getElevationAlongPath(f,function(a,d){h.elevationHandler(a,d,b,c)})},getElevationServer:function(a,b){if(0===a.length)return b(null,null);if(1===a.length)return b(new Error("getElevation requires at least 2 points."));for(var c=require("googlemaps"),d=[],e=0;e<a.length;e++)d.push(this.latitude(a[e])+","+this.longitude(a[e]));var f=this;c.elevationFromPath(d.join("|"),d.length,function(c,d){f.elevationHandler(d.results,d.status,a,b)})},elevationHandler:function(a,b,c,d){var e=[];if("OK"==b){for(var f=0;f<a.length;f++)e.push({lat:this.latitude(c[f]),lng:this.longitude(c[f]),elev:a[f].elevation});d(null,e)}else d(new Error("Could not get elevation using Google's API"),elevationResult.status)},getGrade:function(a){var b=Math.abs(this.elevation(a[a.length-1])-this.elevation(a[0])),c=this.getPathLength(a);return Math.floor(b/c*100)},getTotalElevationGainAndLoss:function(a){for(var b=0,c=0,d=0;d<a.length-1;d++){var e=this.elevation(a[d])-this.elevation(a[d+1]);e>0?c+=e:b+=Math.abs(e)}return{gain:b,loss:c}}};"undefined"!=typeof module&&"undefined"!=typeof module.exports?(b=require("geolib"),b.extend(d)):"function"==typeof define&&define.amd?define(["geolib"],function(a){return a.extend(d),a}):b.extend(d)}(this,this.geolib);
|
744
app/bower_components/geolib/dist/geolib.isPointInsideRobust.js
vendored
Normal file
744
app/bower_components/geolib/dist/geolib.isPointInsideRobust.js
vendored
Normal file
|
@ -0,0 +1,744 @@
|
|||
/*! geolib.isPointInsideRobust 2.0.21
|
||||
* !!EXPERIMENTAL!!
|
||||
*
|
||||
* Robust version of isPointInside for Geolib.js
|
||||
*
|
||||
* Based on https://github.com/mikolalysenko/robust-point-in-polygon
|
||||
* by Mikola Lysenko, licensed under MIT
|
||||
*
|
||||
* @author Manuel Bieh
|
||||
* @url http://www.manuelbieh.com/
|
||||
* @version 2.0.21
|
||||
* @license MIT
|
||||
*
|
||||
*/
|
||||
;(function(global, geolib, undefined) {
|
||||
|
||||
var addOn = function(geolib) {
|
||||
|
||||
var SPLITTER = +(Math.pow(2, 27) + 1.0);
|
||||
|
||||
var NUM_EXPAND = 5;
|
||||
var EPSILON = 1.1102230246251565e-16;
|
||||
var ERRBOUND3 = (3.0 + 16.0 * EPSILON) * EPSILON;
|
||||
var ERRBOUND4 = (7.0 + 56.0 * EPSILON) * EPSILON;
|
||||
|
||||
var twoProduct = function(a, b, result) {
|
||||
var x = a * b;
|
||||
var c = SPLITTER * a;
|
||||
var abig = c - a;
|
||||
var ahi = c - abig;
|
||||
var alo = a - ahi;
|
||||
var d = SPLITTER * b;
|
||||
var bbig = d - b;
|
||||
var bhi = d - bbig;
|
||||
var blo = b - bhi;
|
||||
var err1 = x - (ahi * bhi);
|
||||
var err2 = err1 - (alo * bhi);
|
||||
var err3 = err2 - (ahi * blo);
|
||||
var y = alo * blo - err3;
|
||||
if(result) {
|
||||
result[0] = y;
|
||||
result[1] = x;
|
||||
return result;
|
||||
}
|
||||
return [ y, x ];
|
||||
};
|
||||
|
||||
var fastTwoSum = function(a, b, result) {
|
||||
var x = a + b;
|
||||
var bv = x - a;
|
||||
var av = x - bv;
|
||||
var br = b - bv;
|
||||
var ar = a - av;
|
||||
if(result) {
|
||||
result[0] = ar + br;
|
||||
result[1] = x;
|
||||
return result;
|
||||
}
|
||||
return [ar+br, x];
|
||||
};
|
||||
|
||||
var twoSum = fastTwoSum;
|
||||
|
||||
var linearExpansionSum = function(e, f) {
|
||||
var ne = e.length|0;
|
||||
var nf = f.length|0;
|
||||
if(ne === 1 && nf === 1) {
|
||||
return scalarScalar(e[0], f[0]);
|
||||
}
|
||||
var n = ne + nf;
|
||||
var g = new Array(n);
|
||||
var count = 0;
|
||||
var eptr = 0;
|
||||
var fptr = 0;
|
||||
var abs = Math.abs;
|
||||
var ei = e[eptr];
|
||||
var ea = abs(ei);
|
||||
var fi = f[fptr];
|
||||
var fa = abs(fi);
|
||||
var a, b;
|
||||
if(ea < fa) {
|
||||
b = ei;
|
||||
eptr += 1;
|
||||
if(eptr < ne) {
|
||||
ei = e[eptr];
|
||||
ea = abs(ei);
|
||||
}
|
||||
} else {
|
||||
b = fi;
|
||||
fptr += 1;
|
||||
if(fptr < nf) {
|
||||
fi = f[fptr];
|
||||
fa = abs(fi);
|
||||
}
|
||||
}
|
||||
if((eptr < ne && ea < fa) || (fptr >= nf)) {
|
||||
a = ei;
|
||||
eptr += 1;
|
||||
if(eptr < ne) {
|
||||
ei = e[eptr];
|
||||
ea = abs(ei);
|
||||
}
|
||||
} else {
|
||||
a = fi;
|
||||
fptr += 1;
|
||||
if(fptr < nf) {
|
||||
fi = f[fptr];
|
||||
fa = abs(fi);
|
||||
}
|
||||
}
|
||||
var x = a + b;
|
||||
var bv = x - a;
|
||||
var y = b - bv;
|
||||
var q0 = y;
|
||||
var q1 = x;
|
||||
var _x, _bv, _av, _br, _ar;
|
||||
while(eptr < ne && fptr < nf) {
|
||||
if(ea < fa) {
|
||||
a = ei;
|
||||
eptr += 1;
|
||||
if(eptr < ne) {
|
||||
ei = e[eptr];
|
||||
ea = abs(ei);
|
||||
}
|
||||
} else {
|
||||
a = fi;
|
||||
fptr += 1;
|
||||
if(fptr < nf) {
|
||||
fi = f[fptr];
|
||||
fa = abs(fi);
|
||||
}
|
||||
}
|
||||
b = q0;
|
||||
x = a + b;
|
||||
bv = x - a;
|
||||
y = b - bv;
|
||||
if(y) {
|
||||
g[count++] = y;
|
||||
}
|
||||
_x = q1 + x;
|
||||
_bv = _x - q1;
|
||||
_av = _x - _bv;
|
||||
_br = x - _bv;
|
||||
_ar = q1 - _av;
|
||||
q0 = _ar + _br;
|
||||
q1 = _x;
|
||||
}
|
||||
while(eptr < ne) {
|
||||
a = ei;
|
||||
b = q0;
|
||||
x = a + b;
|
||||
bv = x - a;
|
||||
y = b - bv;
|
||||
if(y) {
|
||||
g[count++] = y;
|
||||
}
|
||||
_x = q1 + x;
|
||||
_bv = _x - q1;
|
||||
_av = _x - _bv;
|
||||
_br = x - _bv;
|
||||
_ar = q1 - _av;
|
||||
q0 = _ar + _br;
|
||||
q1 = _x;
|
||||
eptr += 1;
|
||||
if(eptr < ne) {
|
||||
ei = e[eptr];
|
||||
}
|
||||
}
|
||||
while(fptr < nf) {
|
||||
a = fi;
|
||||
b = q0;
|
||||
x = a + b;
|
||||
bv = x - a;
|
||||
y = b - bv;
|
||||
if(y) {
|
||||
g[count++] = y;
|
||||
}
|
||||
_x = q1 + x;
|
||||
_bv = _x - q1;
|
||||
_av = _x - _bv;
|
||||
_br = x - _bv;
|
||||
_ar = q1 - _av;
|
||||
q0 = _ar + _br;
|
||||
q1 = _x;
|
||||
fptr += 1;
|
||||
if(fptr < nf) {
|
||||
fi = f[fptr];
|
||||
}
|
||||
}
|
||||
if(q0) {
|
||||
g[count++] = q0;
|
||||
}
|
||||
if(q1) {
|
||||
g[count++] = q1;
|
||||
}
|
||||
if(!count) {
|
||||
g[count++] = 0.0;
|
||||
}
|
||||
g.length = count;
|
||||
return g;
|
||||
};
|
||||
|
||||
var robustSum = linearExpansionSum;
|
||||
|
||||
var scaleLinearExpansion = function(e, scale) {
|
||||
var n = e.length;
|
||||
if(n === 1) {
|
||||
var ts = twoProduct(e[0], scale);
|
||||
if(ts[0]) {
|
||||
return ts;
|
||||
}
|
||||
return [ ts[1] ];
|
||||
}
|
||||
var g = new Array(2 * n);
|
||||
var q = [0.1, 0.1];
|
||||
var t = [0.1, 0.1];
|
||||
var count = 0;
|
||||
twoProduct(e[0], scale, q);
|
||||
if(q[0]) {
|
||||
g[count++] = q[0];
|
||||
}
|
||||
for(var i=1; i<n; ++i) {
|
||||
twoProduct(e[i], scale, t);
|
||||
var pq = q[1];
|
||||
twoSum(pq, t[0], q);
|
||||
if(q[0]) {
|
||||
g[count++] = q[0];
|
||||
}
|
||||
var a = t[1];
|
||||
var b = q[1];
|
||||
var x = a + b;
|
||||
var bv = x - a;
|
||||
var y = b - bv;
|
||||
q[1] = x;
|
||||
if(y) {
|
||||
g[count++] = y;
|
||||
}
|
||||
}
|
||||
if(q[1]) {
|
||||
g[count++] = q[1];
|
||||
}
|
||||
if(count === 0) {
|
||||
g[count++] = 0.0;
|
||||
}
|
||||
g.length = count;
|
||||
return g;
|
||||
};
|
||||
|
||||
var robustScale = scaleLinearExpansion;
|
||||
|
||||
var scalarScalar = function(a, b) {
|
||||
var x = a + b;
|
||||
var bv = x - a;
|
||||
var av = x - bv;
|
||||
var br = b - bv;
|
||||
var ar = a - av;
|
||||
var y = ar + br;
|
||||
if(y) {
|
||||
return [y, x];
|
||||
}
|
||||
return [x];
|
||||
};
|
||||
|
||||
var robustSubtract = function(e, f) {
|
||||
var ne = e.length|0;
|
||||
var nf = f.length|0;
|
||||
if(ne === 1 && nf === 1) {
|
||||
return scalarScalar(e[0], -f[0]);
|
||||
}
|
||||
var n = ne + nf;
|
||||
var g = new Array(n);
|
||||
var count = 0;
|
||||
var eptr = 0;
|
||||
var fptr = 0;
|
||||
var abs = Math.abs;
|
||||
var ei = e[eptr];
|
||||
var ea = abs(ei);
|
||||
var fi = -f[fptr];
|
||||
var fa = abs(fi);
|
||||
var a, b;
|
||||
if(ea < fa) {
|
||||
b = ei;
|
||||
eptr += 1;
|
||||
if(eptr < ne) {
|
||||
ei = e[eptr];
|
||||
ea = abs(ei);
|
||||
}
|
||||
} else {
|
||||
b = fi;
|
||||
fptr += 1;
|
||||
if(fptr < nf) {
|
||||
fi = -f[fptr];
|
||||
fa = abs(fi);
|
||||
}
|
||||
}
|
||||
if((eptr < ne && ea < fa) || (fptr >= nf)) {
|
||||
a = ei;
|
||||
eptr += 1;
|
||||
if(eptr < ne) {
|
||||
ei = e[eptr];
|
||||
ea = abs(ei);
|
||||
}
|
||||
} else {
|
||||
a = fi;
|
||||
fptr += 1;
|
||||
if(fptr < nf) {
|
||||
fi = -f[fptr];
|
||||
fa = abs(fi);
|
||||
}
|
||||
}
|
||||
var x = a + b;
|
||||
var bv = x - a;
|
||||
var y = b - bv;
|
||||
var q0 = y;
|
||||
var q1 = x;
|
||||
var _x, _bv, _av, _br, _ar;
|
||||
while(eptr < ne && fptr < nf) {
|
||||
if(ea < fa) {
|
||||
a = ei;
|
||||
eptr += 1;
|
||||
if(eptr < ne) {
|
||||
ei = e[eptr];
|
||||
ea = abs(ei);
|
||||
}
|
||||
} else {
|
||||
a = fi;
|
||||
fptr += 1;
|
||||
if(fptr < nf) {
|
||||
fi = -f[fptr];
|
||||
fa = abs(fi);
|
||||
}
|
||||
}
|
||||
b = q0;
|
||||
x = a + b;
|
||||
bv = x - a;
|
||||
y = b - bv;
|
||||
if(y) {
|
||||
g[count++] = y;
|
||||
}
|
||||
_x = q1 + x;
|
||||
_bv = _x - q1;
|
||||
_av = _x - _bv;
|
||||
_br = x - _bv;
|
||||
_ar = q1 - _av;
|
||||
q0 = _ar + _br;
|
||||
q1 = _x;
|
||||
}
|
||||
while(eptr < ne) {
|
||||
a = ei;
|
||||
b = q0;
|
||||
x = a + b;
|
||||
bv = x - a;
|
||||
y = b - bv;
|
||||
if(y) {
|
||||
g[count++] = y;
|
||||
}
|
||||
_x = q1 + x;
|
||||
_bv = _x - q1;
|
||||
_av = _x - _bv;
|
||||
_br = x - _bv;
|
||||
_ar = q1 - _av;
|
||||
q0 = _ar + _br;
|
||||
q1 = _x;
|
||||
eptr += 1;
|
||||
if(eptr < ne) {
|
||||
ei = e[eptr];
|
||||
}
|
||||
}
|
||||
while(fptr < nf) {
|
||||
a = fi;
|
||||
b = q0;
|
||||
x = a + b;
|
||||
bv = x - a;
|
||||
y = b - bv;
|
||||
if(y) {
|
||||
g[count++] = y;
|
||||
}
|
||||
_x = q1 + x;
|
||||
_bv = _x - q1;
|
||||
_av = _x - _bv;
|
||||
_br = x - _bv;
|
||||
_ar = q1 - _av;
|
||||
q0 = _ar + _br;
|
||||
q1 = _x;
|
||||
fptr += 1;
|
||||
if(fptr < nf) {
|
||||
fi = -f[fptr];
|
||||
}
|
||||
}
|
||||
if(q0) {
|
||||
g[count++] = q0;
|
||||
}
|
||||
if(q1) {
|
||||
g[count++] = q1;
|
||||
}
|
||||
if(!count) {
|
||||
g[count++] = 0.0;
|
||||
}
|
||||
g.length = count;
|
||||
return g;
|
||||
};
|
||||
|
||||
var cofactor = function(m, c) {
|
||||
var result = new Array(m.length-1);
|
||||
for(var i=1; i<m.length; ++i) {
|
||||
var r = result[i-1] = new Array(m.length-1);
|
||||
for(var j=0,k=0; j<m.length; ++j) {
|
||||
if(j === c) {
|
||||
continue;
|
||||
}
|
||||
r[k++] = m[i][j];
|
||||
}
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
var matrix = function(n) {
|
||||
var result = new Array(n);
|
||||
for(var i=0; i<n; ++i) {
|
||||
result[i] = new Array(n);
|
||||
for(var j=0; j<n; ++j) {
|
||||
result[i][j] = ["m", j, "[", (n-i-1), "]"].join("");
|
||||
}
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
var sign = function(n) {
|
||||
if(n & 1) {
|
||||
return "-";
|
||||
}
|
||||
return "";
|
||||
};
|
||||
|
||||
var generateSum = function(expr) {
|
||||
if(expr.length === 1) {
|
||||
return expr[0];
|
||||
} else if(expr.length === 2) {
|
||||
return ["sum(", expr[0], ",", expr[1], ")"].join("");
|
||||
} else {
|
||||
var m = expr.length>>1;
|
||||
return ["sum(", generateSum(expr.slice(0, m)), ",", generateSum(expr.slice(m)), ")"].join("");
|
||||
}
|
||||
};
|
||||
|
||||
var determinant = function(m) {
|
||||
if(m.length === 2) {
|
||||
return [["sum(prod(", m[0][0], ",", m[1][1], "),prod(-", m[0][1], ",", m[1][0], "))"].join("")];
|
||||
} else {
|
||||
var expr = [];
|
||||
for(var i=0; i<m.length; ++i) {
|
||||
expr.push(["scale(", generateSum(determinant(cofactor(m, i))), ",", sign(i), m[0][i], ")"].join(""));
|
||||
}
|
||||
return expr;
|
||||
}
|
||||
};
|
||||
|
||||
var orientation = function(n) {
|
||||
var pos = [];
|
||||
var neg = [];
|
||||
var m = matrix(n);
|
||||
var args = [];
|
||||
for(var i=0; i<n; ++i) {
|
||||
if((i&1)===0) {
|
||||
pos.push.apply(pos, determinant(cofactor(m, i)));
|
||||
} else {
|
||||
neg.push.apply(neg, determinant(cofactor(m, i)));
|
||||
}
|
||||
args.push("m" + i);
|
||||
}
|
||||
var posExpr = generateSum(pos);
|
||||
var negExpr = generateSum(neg);
|
||||
var funcName = "orientation" + n + "Exact";
|
||||
var code = [
|
||||
"function ",
|
||||
funcName,
|
||||
"(", args.join(), "){var p=",
|
||||
posExpr,
|
||||
",n=",
|
||||
negExpr,
|
||||
",d=sub(p,n);return d[d.length-1];};return ",
|
||||
funcName
|
||||
].join("");
|
||||
var proc = new Function("sum", "prod", "scale", "sub", code);
|
||||
return proc(robustSum, twoProduct, robustScale, robustSubtract);
|
||||
};
|
||||
|
||||
var orient;
|
||||
var orientation3Exact = orientation(3);
|
||||
var orientation4Exact = orientation(4);
|
||||
|
||||
var CACHED = [
|
||||
function orientation0() { return 0; },
|
||||
function orientation1() { return 0; },
|
||||
function orientation2(a, b) {
|
||||
return b[0] - a[0];
|
||||
},
|
||||
function orientation3(a, b, c) {
|
||||
var l = (a[1] - c[1]) * (b[0] - c[0]);
|
||||
var r = (a[0] - c[0]) * (b[1] - c[1]);
|
||||
var det = l - r;
|
||||
var s;
|
||||
if(l > 0) {
|
||||
if(r <= 0) {
|
||||
return det;
|
||||
} else {
|
||||
s = l + r;
|
||||
}
|
||||
} else if(l < 0) {
|
||||
if(r >= 0) {
|
||||
return det;
|
||||
} else {
|
||||
s = -(l + r);
|
||||
}
|
||||
} else {
|
||||
return det;
|
||||
}
|
||||
var tol = ERRBOUND3 * s;
|
||||
if(det >= tol || det <= -tol) {
|
||||
return det;
|
||||
}
|
||||
return orientation3Exact(a, b, c);
|
||||
},
|
||||
function orientation4(a,b,c,d) {
|
||||
var adx = a[0] - d[0];
|
||||
var bdx = b[0] - d[0];
|
||||
var cdx = c[0] - d[0];
|
||||
var ady = a[1] - d[1];
|
||||
var bdy = b[1] - d[1];
|
||||
var cdy = c[1] - d[1];
|
||||
var adz = a[2] - d[2];
|
||||
var bdz = b[2] - d[2];
|
||||
var cdz = c[2] - d[2];
|
||||
var bdxcdy = bdx * cdy;
|
||||
var cdxbdy = cdx * bdy;
|
||||
var cdxady = cdx * ady;
|
||||
var adxcdy = adx * cdy;
|
||||
var adxbdy = adx * bdy;
|
||||
var bdxady = bdx * ady;
|
||||
var det = adz * (bdxcdy - cdxbdy) +
|
||||
bdz * (cdxady - adxcdy) +
|
||||
cdz * (adxbdy - bdxady);
|
||||
var permanent = (Math.abs(bdxcdy) + Math.abs(cdxbdy)) * Math.abs(adz) +
|
||||
(Math.abs(cdxady) + Math.abs(adxcdy)) * Math.abs(bdz) +
|
||||
(Math.abs(adxbdy) + Math.abs(bdxady)) * Math.abs(cdz);
|
||||
var tol = ERRBOUND4 * permanent;
|
||||
if ((det > tol) || (-det > tol)) {
|
||||
return det;
|
||||
}
|
||||
return orientation4Exact(a,b,c,d);
|
||||
}
|
||||
];
|
||||
|
||||
var slowOrient = function(args) {
|
||||
var proc = CACHED[args.length];
|
||||
if(!proc) {
|
||||
proc = CACHED[args.length] = orientation(args.length);
|
||||
}
|
||||
return proc.apply(undefined, args);
|
||||
};
|
||||
|
||||
var generateOrientationProc = function() {
|
||||
while(CACHED.length <= NUM_EXPAND) {
|
||||
CACHED.push(orientation(CACHED.length));
|
||||
}
|
||||
var args = [];
|
||||
var procArgs = ["slow"];
|
||||
for(var i=0; i<=NUM_EXPAND; ++i) {
|
||||
args.push("a" + i);
|
||||
procArgs.push("o" + i);
|
||||
}
|
||||
var code = [
|
||||
"function getOrientation(",
|
||||
args.join(),
|
||||
"){switch(arguments.length){case 0:case 1:return 0;"
|
||||
];
|
||||
for(i=2; i<=NUM_EXPAND; ++i) {
|
||||
code.push("case ", i, ":return o", i, "(", args.slice(0, i).join(), ");");
|
||||
}
|
||||
code.push("}var s=new Array(arguments.length);for(var i=0;i<arguments.length;++i){s[i]=arguments[i]};return slow(s);}return getOrientation");
|
||||
procArgs.push(code.join(""));
|
||||
|
||||
var proc = Function.apply(undefined, procArgs);
|
||||
orient = proc.apply(undefined, [slowOrient].concat(CACHED));
|
||||
for(i=0; i<=NUM_EXPAND; ++i) {
|
||||
orient[i] = CACHED[i];
|
||||
}
|
||||
};
|
||||
|
||||
generateOrientationProc();
|
||||
|
||||
var robustPointInPolygon = function(vs, point) {
|
||||
// transform from geolib format to array syntax
|
||||
var x = geolib.longitude(point);
|
||||
var y = geolib.latitude(point);
|
||||
var coords = vs.map(function(coords) {
|
||||
return [geolib.longitude(coords), geolib.latitude(coords)];
|
||||
});
|
||||
|
||||
vs = coords;
|
||||
point = [x,y];
|
||||
|
||||
var n = vs.length;
|
||||
var inside = 1;
|
||||
var lim = n;
|
||||
|
||||
var s, c, yk, px, p;
|
||||
|
||||
for(var i = 0, j = n-1; i<lim; j=i++) {
|
||||
var a = vs[i];
|
||||
var b = vs[j];
|
||||
var yi = a[1];
|
||||
var yj = b[1];
|
||||
if(yj < yi) {
|
||||
if(yj < y && y < yi) {
|
||||
s = orient(a, b, point);
|
||||
if(s === 0) {
|
||||
return 0;
|
||||
} else {
|
||||
inside ^= (0 < s)|0;
|
||||
}
|
||||
} else if(y === yi) {
|
||||
c = vs[(i+1)%n];
|
||||
yk = c[1];
|
||||
if(yi < yk) {
|
||||
s = orient(a, b, point);
|
||||
if(s === 0) {
|
||||
return 0;
|
||||
} else {
|
||||
inside ^= (0 < s)|0;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if(yi < yj) {
|
||||
if(yi < y && y < yj) {
|
||||
s = orient(a, b, point);
|
||||
if(s === 0) {
|
||||
return 0;
|
||||
} else {
|
||||
inside ^= (s < 0)|0;
|
||||
}
|
||||
} else if(y === yi) {
|
||||
c = vs[(i+1)%n];
|
||||
yk = c[1];
|
||||
if(yk < yi) {
|
||||
s = orient(a, b, point);
|
||||
if(s === 0) {
|
||||
return 0;
|
||||
} else {
|
||||
inside ^= (s < 0)|0;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if(y === yi) {
|
||||
var x0 = Math.min(a[0], b[0]);
|
||||
var x1 = Math.max(a[0], b[0]);
|
||||
if(i === 0) {
|
||||
while(j>0) {
|
||||
var k = (j+n-1)%n;
|
||||
p = vs[k];
|
||||
if(p[1] !== y) {
|
||||
break;
|
||||
}
|
||||
px = p[0];
|
||||
x0 = Math.min(x0, px);
|
||||
x1 = Math.max(x1, px);
|
||||
j = k;
|
||||
}
|
||||
if(j === 0) {
|
||||
if(x0 <= x && x <= x1) {
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
lim = j+1;
|
||||
}
|
||||
var y0 = vs[(j+n-1)%n][1];
|
||||
while(i+1<lim) {
|
||||
p = vs[i+1];
|
||||
if(p[1] !== y) {
|
||||
break;
|
||||
}
|
||||
px = p[0];
|
||||
x0 = Math.min(x0, px);
|
||||
x1 = Math.max(x1, px);
|
||||
i += 1;
|
||||
}
|
||||
if(x0 <= x && x <= x1) {
|
||||
return 0;
|
||||
}
|
||||
var y1 = vs[(i+1)%n][1];
|
||||
if(x < x0 && (y0 < y !== y1 < y)) {
|
||||
inside ^= 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 2 * inside - 1;
|
||||
};
|
||||
|
||||
return {
|
||||
|
||||
/**
|
||||
* @param object coordinate to check e.g. {latitude: 51.5023, longitude: 7.3815}
|
||||
* @param array array with coords e.g. [{latitude: 51.5143, longitude: 7.4138}, {latitude: 123, longitude: 123}, ...]
|
||||
* @return integer -1 if point is inside, 0 if point is on boundaries, 1 if point is outside
|
||||
*/
|
||||
isPointInsideRobust: function(latlng, coords) {
|
||||
return robustPointInPolygon(coords, latlng);
|
||||
},
|
||||
|
||||
isInside: function() {
|
||||
return this.isPointInsideRobust.apply(this, arguments);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
|
||||
// Node module
|
||||
if (typeof module !== 'undefined' &&
|
||||
typeof module.exports !== 'undefined') {
|
||||
|
||||
module.exports = function(geolib) {
|
||||
geolib.extend(addOn(geolib), true);
|
||||
return geolib;
|
||||
};
|
||||
|
||||
// AMD module
|
||||
} else if (typeof define === "function" && define.amd) {
|
||||
|
||||
define(["geolib"], function (geolib) {
|
||||
geolib.extend(addOn(geolib), true);
|
||||
return geolib;
|
||||
});
|
||||
|
||||
// we're in a browser
|
||||
} else {
|
||||
|
||||
geolib.extend(addOn(geolib), true);
|
||||
|
||||
}
|
||||
|
||||
}(this, this.geolib));
|
15
app/bower_components/geolib/dist/geolib.isPointInsideRobust.min.js
vendored
Normal file
15
app/bower_components/geolib/dist/geolib.isPointInsideRobust.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
2332
app/bower_components/geolib/dist/geolib.js
vendored
2332
app/bower_components/geolib/dist/geolib.js
vendored
File diff suppressed because it is too large
Load diff
File diff suppressed because one or more lines are too long
1
app/bower_components/geolib/index.html
vendored
1
app/bower_components/geolib/index.html
vendored
|
@ -14,6 +14,7 @@ if(typeof $ == 'undefined') {
|
|||
<meta charset="utf-8" />
|
||||
|
||||
<script src="dist/geolib.js"></script>
|
||||
<script src="dist/geolib.isPointInsideRobust.js"></script>
|
||||
|
||||
<script>
|
||||
$(function() {
|
||||
|
|
25
app/bower_components/geolib/meteor/README.md
vendored
Normal file
25
app/bower_components/geolib/meteor/README.md
vendored
Normal file
|
@ -0,0 +1,25 @@
|
|||
Packaging [Geolib](http://github.com/manuelbieh/Geolib) for [Meteor.js](http://meteor.com).
|
||||
|
||||
|
||||
# Meteor
|
||||
|
||||
If you're new to Meteor, here's what the excitement is all about -
|
||||
[watch the first two minutes](https://www.youtube.com/watch?v=fsi0aJ9yr2o); you'll be hooked by 1:28.
|
||||
|
||||
That screencast is from 2012. In the meantime, Meteor has become a mature JavaScript-everywhere web
|
||||
development framework. Read more at [Why Meteor](http://www.meteorpedia.com/read/Why_Meteor).
|
||||
|
||||
|
||||
# Issues
|
||||
|
||||
If you encounter an issue while using this package, please CC @dandv when you file it in this repo.
|
||||
|
||||
|
||||
# DONE
|
||||
|
||||
* Simple test. Should be enough.
|
||||
|
||||
|
||||
# TODO
|
||||
|
||||
* Add other tests; however, that is overkill, and the responsibiity of Moment, not of the Meteor integration.
|
3
app/bower_components/geolib/meteor/export.js
vendored
Normal file
3
app/bower_components/geolib/meteor/export.js
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
// Geolib makes `geolib` global on the window (or global) object, while Meteor expects a file-scoped global variable
|
||||
geolib = this.geolib;
|
||||
delete this.geolib;
|
30
app/bower_components/geolib/meteor/package.js
vendored
Normal file
30
app/bower_components/geolib/meteor/package.js
vendored
Normal file
|
@ -0,0 +1,30 @@
|
|||
// package metadata file for Meteor.js
|
||||
'use strict';
|
||||
|
||||
var packageName = 'outatime:geolib'; // https://atmospherejs.com/outatime/geolib
|
||||
|
||||
var packageJson = JSON.parse(Npm.require("fs").readFileSync('package.json'));
|
||||
|
||||
Package.describe({
|
||||
name: packageName,
|
||||
summary: 'Geolib - Library to perform geo specific tasks',
|
||||
version: packageJson.version,
|
||||
documentation: 'meteor/README.md',
|
||||
git: 'https://github.com/manuelbieh/geolib.git'
|
||||
});
|
||||
|
||||
Package.onUse(function (api) {
|
||||
api.versionsFrom(['METEOR@0.9.0', 'METEOR@1.0']);
|
||||
api.export('geolib');
|
||||
api.addFiles([
|
||||
'dist/geolib.js',
|
||||
'meteor/export.js'
|
||||
]);
|
||||
});
|
||||
|
||||
Package.onTest(function (api) {
|
||||
api.use(packageName);
|
||||
api.use('tinytest');
|
||||
|
||||
api.addFiles('meteor/test.js');
|
||||
});
|
5
app/bower_components/geolib/meteor/test.js
vendored
Normal file
5
app/bower_components/geolib/meteor/test.js
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
'use strict';
|
||||
|
||||
Tinytest.add('Geolib.is', function (test) {
|
||||
test.equal(geolib.radius, 6378137, {message: 'simple geolib object'});
|
||||
});
|
11
app/bower_components/geolib/package.json
vendored
11
app/bower_components/geolib/package.json
vendored
|
@ -19,7 +19,7 @@
|
|||
"grunt-contrib-qunit": "~0.2.0",
|
||||
"grunt-text-replace": "~0.3.6",
|
||||
"grunt-contrib-jshint": "~0.6.2",
|
||||
"phantomjs": "~1.8.0",
|
||||
"phantomjs": ">=1.8.0",
|
||||
"grunt-jslint": "~1.0.0",
|
||||
"time-grunt": "~0.3.1",
|
||||
"load-grunt-tasks": "~0.4.0"
|
||||
|
@ -31,7 +31,8 @@
|
|||
}
|
||||
],
|
||||
"files": [
|
||||
"geolib.js"
|
||||
"dist/geolib.js",
|
||||
"dist/geolib.elevation.js"
|
||||
],
|
||||
"description": "Library to perform geo specific tasks",
|
||||
"keywords": [
|
||||
|
@ -46,6 +47,6 @@
|
|||
"scripts": {
|
||||
"test": "grunt travis --verbose"
|
||||
},
|
||||
"version": "2.0.9",
|
||||
"main": "./geolib"
|
||||
}
|
||||
"version": "2.0.21",
|
||||
"main": "dist/geolib.js"
|
||||
}
|
||||
|
|
744
app/bower_components/geolib/src/geolib.isPointInsideRobust.js
vendored
Normal file
744
app/bower_components/geolib/src/geolib.isPointInsideRobust.js
vendored
Normal file
|
@ -0,0 +1,744 @@
|
|||
/*! geolib.isPointInsideRobust $version$
|
||||
* !!EXPERIMENTAL!!
|
||||
*
|
||||
* Robust version of isPointInside for Geolib.js
|
||||
*
|
||||
* Based on https://github.com/mikolalysenko/robust-point-in-polygon
|
||||
* by Mikola Lysenko, licensed under MIT
|
||||
*
|
||||
* @author Manuel Bieh
|
||||
* @url http://www.manuelbieh.com/
|
||||
* @version $version$
|
||||
* @license MIT
|
||||
*
|
||||
*/
|
||||
;(function(global, geolib, undefined) {
|
||||
|
||||
var addOn = function(geolib) {
|
||||
|
||||
var SPLITTER = +(Math.pow(2, 27) + 1.0);
|
||||
|
||||
var NUM_EXPAND = 5;
|
||||
var EPSILON = 1.1102230246251565e-16;
|
||||
var ERRBOUND3 = (3.0 + 16.0 * EPSILON) * EPSILON;
|
||||
var ERRBOUND4 = (7.0 + 56.0 * EPSILON) * EPSILON;
|
||||
|
||||
var twoProduct = function(a, b, result) {
|
||||
var x = a * b;
|
||||
var c = SPLITTER * a;
|
||||
var abig = c - a;
|
||||
var ahi = c - abig;
|
||||
var alo = a - ahi;
|
||||
var d = SPLITTER * b;
|
||||
var bbig = d - b;
|
||||
var bhi = d - bbig;
|
||||
var blo = b - bhi;
|
||||
var err1 = x - (ahi * bhi);
|
||||
var err2 = err1 - (alo * bhi);
|
||||
var err3 = err2 - (ahi * blo);
|
||||
var y = alo * blo - err3;
|
||||
if(result) {
|
||||
result[0] = y;
|
||||
result[1] = x;
|
||||
return result;
|
||||
}
|
||||
return [ y, x ];
|
||||
};
|
||||
|
||||
var fastTwoSum = function(a, b, result) {
|
||||
var x = a + b;
|
||||
var bv = x - a;
|
||||
var av = x - bv;
|
||||
var br = b - bv;
|
||||
var ar = a - av;
|
||||
if(result) {
|
||||
result[0] = ar + br;
|
||||
result[1] = x;
|
||||
return result;
|
||||
}
|
||||
return [ar+br, x];
|
||||
};
|
||||
|
||||
var twoSum = fastTwoSum;
|
||||
|
||||
var linearExpansionSum = function(e, f) {
|
||||
var ne = e.length|0;
|
||||
var nf = f.length|0;
|
||||
if(ne === 1 && nf === 1) {
|
||||
return scalarScalar(e[0], f[0]);
|
||||
}
|
||||
var n = ne + nf;
|
||||
var g = new Array(n);
|
||||
var count = 0;
|
||||
var eptr = 0;
|
||||
var fptr = 0;
|
||||
var abs = Math.abs;
|
||||
var ei = e[eptr];
|
||||
var ea = abs(ei);
|
||||
var fi = f[fptr];
|
||||
var fa = abs(fi);
|
||||
var a, b;
|
||||
if(ea < fa) {
|
||||
b = ei;
|
||||
eptr += 1;
|
||||
if(eptr < ne) {
|
||||
ei = e[eptr];
|
||||
ea = abs(ei);
|
||||
}
|
||||
} else {
|
||||
b = fi;
|
||||
fptr += 1;
|
||||
if(fptr < nf) {
|
||||
fi = f[fptr];
|
||||
fa = abs(fi);
|
||||
}
|
||||
}
|
||||
if((eptr < ne && ea < fa) || (fptr >= nf)) {
|
||||
a = ei;
|
||||
eptr += 1;
|
||||
if(eptr < ne) {
|
||||
ei = e[eptr];
|
||||
ea = abs(ei);
|
||||
}
|
||||
} else {
|
||||
a = fi;
|
||||
fptr += 1;
|
||||
if(fptr < nf) {
|
||||
fi = f[fptr];
|
||||
fa = abs(fi);
|
||||
}
|
||||
}
|
||||
var x = a + b;
|
||||
var bv = x - a;
|
||||
var y = b - bv;
|
||||
var q0 = y;
|
||||
var q1 = x;
|
||||
var _x, _bv, _av, _br, _ar;
|
||||
while(eptr < ne && fptr < nf) {
|
||||
if(ea < fa) {
|
||||
a = ei;
|
||||
eptr += 1;
|
||||
if(eptr < ne) {
|
||||
ei = e[eptr];
|
||||
ea = abs(ei);
|
||||
}
|
||||
} else {
|
||||
a = fi;
|
||||
fptr += 1;
|
||||
if(fptr < nf) {
|
||||
fi = f[fptr];
|
||||
fa = abs(fi);
|
||||
}
|
||||
}
|
||||
b = q0;
|
||||
x = a + b;
|
||||
bv = x - a;
|
||||
y = b - bv;
|
||||
if(y) {
|
||||
g[count++] = y;
|
||||
}
|
||||
_x = q1 + x;
|
||||
_bv = _x - q1;
|
||||
_av = _x - _bv;
|
||||
_br = x - _bv;
|
||||
_ar = q1 - _av;
|
||||
q0 = _ar + _br;
|
||||
q1 = _x;
|
||||
}
|
||||
while(eptr < ne) {
|
||||
a = ei;
|
||||
b = q0;
|
||||
x = a + b;
|
||||
bv = x - a;
|
||||
y = b - bv;
|
||||
if(y) {
|
||||
g[count++] = y;
|
||||
}
|
||||
_x = q1 + x;
|
||||
_bv = _x - q1;
|
||||
_av = _x - _bv;
|
||||
_br = x - _bv;
|
||||
_ar = q1 - _av;
|
||||
q0 = _ar + _br;
|
||||
q1 = _x;
|
||||
eptr += 1;
|
||||
if(eptr < ne) {
|
||||
ei = e[eptr];
|
||||
}
|
||||
}
|
||||
while(fptr < nf) {
|
||||
a = fi;
|
||||
b = q0;
|
||||
x = a + b;
|
||||
bv = x - a;
|
||||
y = b - bv;
|
||||
if(y) {
|
||||
g[count++] = y;
|
||||
}
|
||||
_x = q1 + x;
|
||||
_bv = _x - q1;
|
||||
_av = _x - _bv;
|
||||
_br = x - _bv;
|
||||
_ar = q1 - _av;
|
||||
q0 = _ar + _br;
|
||||
q1 = _x;
|
||||
fptr += 1;
|
||||
if(fptr < nf) {
|
||||
fi = f[fptr];
|
||||
}
|
||||
}
|
||||
if(q0) {
|
||||
g[count++] = q0;
|
||||
}
|
||||
if(q1) {
|
||||
g[count++] = q1;
|
||||
}
|
||||
if(!count) {
|
||||
g[count++] = 0.0;
|
||||
}
|
||||
g.length = count;
|
||||
return g;
|
||||
};
|
||||
|
||||
var robustSum = linearExpansionSum;
|
||||
|
||||
var scaleLinearExpansion = function(e, scale) {
|
||||
var n = e.length;
|
||||
if(n === 1) {
|
||||
var ts = twoProduct(e[0], scale);
|
||||
if(ts[0]) {
|
||||
return ts;
|
||||
}
|
||||
return [ ts[1] ];
|
||||
}
|
||||
var g = new Array(2 * n);
|
||||
var q = [0.1, 0.1];
|
||||
var t = [0.1, 0.1];
|
||||
var count = 0;
|
||||
twoProduct(e[0], scale, q);
|
||||
if(q[0]) {
|
||||
g[count++] = q[0];
|
||||
}
|
||||
for(var i=1; i<n; ++i) {
|
||||
twoProduct(e[i], scale, t);
|
||||
var pq = q[1];
|
||||
twoSum(pq, t[0], q);
|
||||
if(q[0]) {
|
||||
g[count++] = q[0];
|
||||
}
|
||||
var a = t[1];
|
||||
var b = q[1];
|
||||
var x = a + b;
|
||||
var bv = x - a;
|
||||
var y = b - bv;
|
||||
q[1] = x;
|
||||
if(y) {
|
||||
g[count++] = y;
|
||||
}
|
||||
}
|
||||
if(q[1]) {
|
||||
g[count++] = q[1];
|
||||
}
|
||||
if(count === 0) {
|
||||
g[count++] = 0.0;
|
||||
}
|
||||
g.length = count;
|
||||
return g;
|
||||
};
|
||||
|
||||
var robustScale = scaleLinearExpansion;
|
||||
|
||||
var scalarScalar = function(a, b) {
|
||||
var x = a + b;
|
||||
var bv = x - a;
|
||||
var av = x - bv;
|
||||
var br = b - bv;
|
||||
var ar = a - av;
|
||||
var y = ar + br;
|
||||
if(y) {
|
||||
return [y, x];
|
||||
}
|
||||
return [x];
|
||||
};
|
||||
|
||||
var robustSubtract = function(e, f) {
|
||||
var ne = e.length|0;
|
||||
var nf = f.length|0;
|
||||
if(ne === 1 && nf === 1) {
|
||||
return scalarScalar(e[0], -f[0]);
|
||||
}
|
||||
var n = ne + nf;
|
||||
var g = new Array(n);
|
||||
var count = 0;
|
||||
var eptr = 0;
|
||||
var fptr = 0;
|
||||
var abs = Math.abs;
|
||||
var ei = e[eptr];
|
||||
var ea = abs(ei);
|
||||
var fi = -f[fptr];
|
||||
var fa = abs(fi);
|
||||
var a, b;
|
||||
if(ea < fa) {
|
||||
b = ei;
|
||||
eptr += 1;
|
||||
if(eptr < ne) {
|
||||
ei = e[eptr];
|
||||
ea = abs(ei);
|
||||
}
|
||||
} else {
|
||||
b = fi;
|
||||
fptr += 1;
|
||||
if(fptr < nf) {
|
||||
fi = -f[fptr];
|
||||
fa = abs(fi);
|
||||
}
|
||||
}
|
||||
if((eptr < ne && ea < fa) || (fptr >= nf)) {
|
||||
a = ei;
|
||||
eptr += 1;
|
||||
if(eptr < ne) {
|
||||
ei = e[eptr];
|
||||
ea = abs(ei);
|
||||
}
|
||||
} else {
|
||||
a = fi;
|
||||
fptr += 1;
|
||||
if(fptr < nf) {
|
||||
fi = -f[fptr];
|
||||
fa = abs(fi);
|
||||
}
|
||||
}
|
||||
var x = a + b;
|
||||
var bv = x - a;
|
||||
var y = b - bv;
|
||||
var q0 = y;
|
||||
var q1 = x;
|
||||
var _x, _bv, _av, _br, _ar;
|
||||
while(eptr < ne && fptr < nf) {
|
||||
if(ea < fa) {
|
||||
a = ei;
|
||||
eptr += 1;
|
||||
if(eptr < ne) {
|
||||
ei = e[eptr];
|
||||
ea = abs(ei);
|
||||
}
|
||||
} else {
|
||||
a = fi;
|
||||
fptr += 1;
|
||||
if(fptr < nf) {
|
||||
fi = -f[fptr];
|
||||
fa = abs(fi);
|
||||
}
|
||||
}
|
||||
b = q0;
|
||||
x = a + b;
|
||||
bv = x - a;
|
||||
y = b - bv;
|
||||
if(y) {
|
||||
g[count++] = y;
|
||||
}
|
||||
_x = q1 + x;
|
||||
_bv = _x - q1;
|
||||
_av = _x - _bv;
|
||||
_br = x - _bv;
|
||||
_ar = q1 - _av;
|
||||
q0 = _ar + _br;
|
||||
q1 = _x;
|
||||
}
|
||||
while(eptr < ne) {
|
||||
a = ei;
|
||||
b = q0;
|
||||
x = a + b;
|
||||
bv = x - a;
|
||||
y = b - bv;
|
||||
if(y) {
|
||||
g[count++] = y;
|
||||
}
|
||||
_x = q1 + x;
|
||||
_bv = _x - q1;
|
||||
_av = _x - _bv;
|
||||
_br = x - _bv;
|
||||
_ar = q1 - _av;
|
||||
q0 = _ar + _br;
|
||||
q1 = _x;
|
||||
eptr += 1;
|
||||
if(eptr < ne) {
|
||||
ei = e[eptr];
|
||||
}
|
||||
}
|
||||
while(fptr < nf) {
|
||||
a = fi;
|
||||
b = q0;
|
||||
x = a + b;
|
||||
bv = x - a;
|
||||
y = b - bv;
|
||||
if(y) {
|
||||
g[count++] = y;
|
||||
}
|
||||
_x = q1 + x;
|
||||
_bv = _x - q1;
|
||||
_av = _x - _bv;
|
||||
_br = x - _bv;
|
||||
_ar = q1 - _av;
|
||||
q0 = _ar + _br;
|
||||
q1 = _x;
|
||||
fptr += 1;
|
||||
if(fptr < nf) {
|
||||
fi = -f[fptr];
|
||||
}
|
||||
}
|
||||
if(q0) {
|
||||
g[count++] = q0;
|
||||
}
|
||||
if(q1) {
|
||||
g[count++] = q1;
|
||||
}
|
||||
if(!count) {
|
||||
g[count++] = 0.0;
|
||||
}
|
||||
g.length = count;
|
||||
return g;
|
||||
};
|
||||
|
||||
var cofactor = function(m, c) {
|
||||
var result = new Array(m.length-1);
|
||||
for(var i=1; i<m.length; ++i) {
|
||||
var r = result[i-1] = new Array(m.length-1);
|
||||
for(var j=0,k=0; j<m.length; ++j) {
|
||||
if(j === c) {
|
||||
continue;
|
||||
}
|
||||
r[k++] = m[i][j];
|
||||
}
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
var matrix = function(n) {
|
||||
var result = new Array(n);
|
||||
for(var i=0; i<n; ++i) {
|
||||
result[i] = new Array(n);
|
||||
for(var j=0; j<n; ++j) {
|
||||
result[i][j] = ["m", j, "[", (n-i-1), "]"].join("");
|
||||
}
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
var sign = function(n) {
|
||||
if(n & 1) {
|
||||
return "-";
|
||||
}
|
||||
return "";
|
||||
};
|
||||
|
||||
var generateSum = function(expr) {
|
||||
if(expr.length === 1) {
|
||||
return expr[0];
|
||||
} else if(expr.length === 2) {
|
||||
return ["sum(", expr[0], ",", expr[1], ")"].join("");
|
||||
} else {
|
||||
var m = expr.length>>1;
|
||||
return ["sum(", generateSum(expr.slice(0, m)), ",", generateSum(expr.slice(m)), ")"].join("");
|
||||
}
|
||||
};
|
||||
|
||||
var determinant = function(m) {
|
||||
if(m.length === 2) {
|
||||
return [["sum(prod(", m[0][0], ",", m[1][1], "),prod(-", m[0][1], ",", m[1][0], "))"].join("")];
|
||||
} else {
|
||||
var expr = [];
|
||||
for(var i=0; i<m.length; ++i) {
|
||||
expr.push(["scale(", generateSum(determinant(cofactor(m, i))), ",", sign(i), m[0][i], ")"].join(""));
|
||||
}
|
||||
return expr;
|
||||
}
|
||||
};
|
||||
|
||||
var orientation = function(n) {
|
||||
var pos = [];
|
||||
var neg = [];
|
||||
var m = matrix(n);
|
||||
var args = [];
|
||||
for(var i=0; i<n; ++i) {
|
||||
if((i&1)===0) {
|
||||
pos.push.apply(pos, determinant(cofactor(m, i)));
|
||||
} else {
|
||||
neg.push.apply(neg, determinant(cofactor(m, i)));
|
||||
}
|
||||
args.push("m" + i);
|
||||
}
|
||||
var posExpr = generateSum(pos);
|
||||
var negExpr = generateSum(neg);
|
||||
var funcName = "orientation" + n + "Exact";
|
||||
var code = [
|
||||
"function ",
|
||||
funcName,
|
||||
"(", args.join(), "){var p=",
|
||||
posExpr,
|
||||
",n=",
|
||||
negExpr,
|
||||
",d=sub(p,n);return d[d.length-1];};return ",
|
||||
funcName
|
||||
].join("");
|
||||
var proc = new Function("sum", "prod", "scale", "sub", code);
|
||||
return proc(robustSum, twoProduct, robustScale, robustSubtract);
|
||||
};
|
||||
|
||||
var orient;
|
||||
var orientation3Exact = orientation(3);
|
||||
var orientation4Exact = orientation(4);
|
||||
|
||||
var CACHED = [
|
||||
function orientation0() { return 0; },
|
||||
function orientation1() { return 0; },
|
||||
function orientation2(a, b) {
|
||||
return b[0] - a[0];
|
||||
},
|
||||
function orientation3(a, b, c) {
|
||||
var l = (a[1] - c[1]) * (b[0] - c[0]);
|
||||
var r = (a[0] - c[0]) * (b[1] - c[1]);
|
||||
var det = l - r;
|
||||
var s;
|
||||
if(l > 0) {
|
||||
if(r <= 0) {
|
||||
return det;
|
||||
} else {
|
||||
s = l + r;
|
||||
}
|
||||
} else if(l < 0) {
|
||||
if(r >= 0) {
|
||||
return det;
|
||||
} else {
|
||||
s = -(l + r);
|
||||
}
|
||||
} else {
|
||||
return det;
|
||||
}
|
||||
var tol = ERRBOUND3 * s;
|
||||
if(det >= tol || det <= -tol) {
|
||||
return det;
|
||||
}
|
||||
return orientation3Exact(a, b, c);
|
||||
},
|
||||
function orientation4(a,b,c,d) {
|
||||
var adx = a[0] - d[0];
|
||||
var bdx = b[0] - d[0];
|
||||
var cdx = c[0] - d[0];
|
||||
var ady = a[1] - d[1];
|
||||
var bdy = b[1] - d[1];
|
||||
var cdy = c[1] - d[1];
|
||||
var adz = a[2] - d[2];
|
||||
var bdz = b[2] - d[2];
|
||||
var cdz = c[2] - d[2];
|
||||
var bdxcdy = bdx * cdy;
|
||||
var cdxbdy = cdx * bdy;
|
||||
var cdxady = cdx * ady;
|
||||
var adxcdy = adx * cdy;
|
||||
var adxbdy = adx * bdy;
|
||||
var bdxady = bdx * ady;
|
||||
var det = adz * (bdxcdy - cdxbdy) +
|
||||
bdz * (cdxady - adxcdy) +
|
||||
cdz * (adxbdy - bdxady);
|
||||
var permanent = (Math.abs(bdxcdy) + Math.abs(cdxbdy)) * Math.abs(adz) +
|
||||
(Math.abs(cdxady) + Math.abs(adxcdy)) * Math.abs(bdz) +
|
||||
(Math.abs(adxbdy) + Math.abs(bdxady)) * Math.abs(cdz);
|
||||
var tol = ERRBOUND4 * permanent;
|
||||
if ((det > tol) || (-det > tol)) {
|
||||
return det;
|
||||
}
|
||||
return orientation4Exact(a,b,c,d);
|
||||
}
|
||||
];
|
||||
|
||||
var slowOrient = function(args) {
|
||||
var proc = CACHED[args.length];
|
||||
if(!proc) {
|
||||
proc = CACHED[args.length] = orientation(args.length);
|
||||
}
|
||||
return proc.apply(undefined, args);
|
||||
};
|
||||
|
||||
var generateOrientationProc = function() {
|
||||
while(CACHED.length <= NUM_EXPAND) {
|
||||
CACHED.push(orientation(CACHED.length));
|
||||
}
|
||||
var args = [];
|
||||
var procArgs = ["slow"];
|
||||
for(var i=0; i<=NUM_EXPAND; ++i) {
|
||||
args.push("a" + i);
|
||||
procArgs.push("o" + i);
|
||||
}
|
||||
var code = [
|
||||
"function getOrientation(",
|
||||
args.join(),
|
||||
"){switch(arguments.length){case 0:case 1:return 0;"
|
||||
];
|
||||
for(i=2; i<=NUM_EXPAND; ++i) {
|
||||
code.push("case ", i, ":return o", i, "(", args.slice(0, i).join(), ");");
|
||||
}
|
||||
code.push("}var s=new Array(arguments.length);for(var i=0;i<arguments.length;++i){s[i]=arguments[i]};return slow(s);}return getOrientation");
|
||||
procArgs.push(code.join(""));
|
||||
|
||||
var proc = Function.apply(undefined, procArgs);
|
||||
orient = proc.apply(undefined, [slowOrient].concat(CACHED));
|
||||
for(i=0; i<=NUM_EXPAND; ++i) {
|
||||
orient[i] = CACHED[i];
|
||||
}
|
||||
};
|
||||
|
||||
generateOrientationProc();
|
||||
|
||||
var robustPointInPolygon = function(vs, point) {
|
||||
// transform from geolib format to array syntax
|
||||
var x = geolib.longitude(point);
|
||||
var y = geolib.latitude(point);
|
||||
var coords = vs.map(function(coords) {
|
||||
return [geolib.longitude(coords), geolib.latitude(coords)];
|
||||
});
|
||||
|
||||
vs = coords;
|
||||
point = [x,y];
|
||||
|
||||
var n = vs.length;
|
||||
var inside = 1;
|
||||
var lim = n;
|
||||
|
||||
var s, c, yk, px, p;
|
||||
|
||||
for(var i = 0, j = n-1; i<lim; j=i++) {
|
||||
var a = vs[i];
|
||||
var b = vs[j];
|
||||
var yi = a[1];
|
||||
var yj = b[1];
|
||||
if(yj < yi) {
|
||||
if(yj < y && y < yi) {
|
||||
s = orient(a, b, point);
|
||||
if(s === 0) {
|
||||
return 0;
|
||||
} else {
|
||||
inside ^= (0 < s)|0;
|
||||
}
|
||||
} else if(y === yi) {
|
||||
c = vs[(i+1)%n];
|
||||
yk = c[1];
|
||||
if(yi < yk) {
|
||||
s = orient(a, b, point);
|
||||
if(s === 0) {
|
||||
return 0;
|
||||
} else {
|
||||
inside ^= (0 < s)|0;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if(yi < yj) {
|
||||
if(yi < y && y < yj) {
|
||||
s = orient(a, b, point);
|
||||
if(s === 0) {
|
||||
return 0;
|
||||
} else {
|
||||
inside ^= (s < 0)|0;
|
||||
}
|
||||
} else if(y === yi) {
|
||||
c = vs[(i+1)%n];
|
||||
yk = c[1];
|
||||
if(yk < yi) {
|
||||
s = orient(a, b, point);
|
||||
if(s === 0) {
|
||||
return 0;
|
||||
} else {
|
||||
inside ^= (s < 0)|0;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if(y === yi) {
|
||||
var x0 = Math.min(a[0], b[0]);
|
||||
var x1 = Math.max(a[0], b[0]);
|
||||
if(i === 0) {
|
||||
while(j>0) {
|
||||
var k = (j+n-1)%n;
|
||||
p = vs[k];
|
||||
if(p[1] !== y) {
|
||||
break;
|
||||
}
|
||||
px = p[0];
|
||||
x0 = Math.min(x0, px);
|
||||
x1 = Math.max(x1, px);
|
||||
j = k;
|
||||
}
|
||||
if(j === 0) {
|
||||
if(x0 <= x && x <= x1) {
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
lim = j+1;
|
||||
}
|
||||
var y0 = vs[(j+n-1)%n][1];
|
||||
while(i+1<lim) {
|
||||
p = vs[i+1];
|
||||
if(p[1] !== y) {
|
||||
break;
|
||||
}
|
||||
px = p[0];
|
||||
x0 = Math.min(x0, px);
|
||||
x1 = Math.max(x1, px);
|
||||
i += 1;
|
||||
}
|
||||
if(x0 <= x && x <= x1) {
|
||||
return 0;
|
||||
}
|
||||
var y1 = vs[(i+1)%n][1];
|
||||
if(x < x0 && (y0 < y !== y1 < y)) {
|
||||
inside ^= 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 2 * inside - 1;
|
||||
};
|
||||
|
||||
return {
|
||||
|
||||
/**
|
||||
* @param object coordinate to check e.g. {latitude: 51.5023, longitude: 7.3815}
|
||||
* @param array array with coords e.g. [{latitude: 51.5143, longitude: 7.4138}, {latitude: 123, longitude: 123}, ...]
|
||||
* @return integer -1 if point is inside, 0 if point is on boundaries, 1 if point is outside
|
||||
*/
|
||||
isPointInsideRobust: function(latlng, coords) {
|
||||
return robustPointInPolygon(coords, latlng);
|
||||
},
|
||||
|
||||
isInside: function() {
|
||||
return this.isPointInsideRobust.apply(this, arguments);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
|
||||
// Node module
|
||||
if (typeof module !== 'undefined' &&
|
||||
typeof module.exports !== 'undefined') {
|
||||
|
||||
module.exports = function(geolib) {
|
||||
geolib.extend(addOn(geolib), true);
|
||||
return geolib;
|
||||
};
|
||||
|
||||
// AMD module
|
||||
} else if (typeof define === "function" && define.amd) {
|
||||
|
||||
define(["geolib"], function (geolib) {
|
||||
geolib.extend(addOn(geolib), true);
|
||||
return geolib;
|
||||
});
|
||||
|
||||
// we're in a browser
|
||||
} else {
|
||||
|
||||
geolib.extend(addOn(geolib), true);
|
||||
|
||||
}
|
||||
|
||||
}(this, this.geolib));
|
2328
app/bower_components/geolib/src/geolib.js
vendored
2328
app/bower_components/geolib/src/geolib.js
vendored
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue