Socket
Socket
Sign inDemoInstall

json-odm

Package Overview
Dependencies
0
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.1.5 to 0.2.0

.codeclimate.yml

4

bin/json.odm.min.js

@@ -1,2 +0,2 @@

"use strict";function JsonOdm(){var t=this;this.sources={},this.selectedSource={},this.addSource=function(e,o,n){"object"==typeof o&&("undefined"==typeof t.sources[e]&&(t.sources[e]=o),n&&(t.selectedSource=o))},this.selectSource=function(e){"undefined"!=typeof t.sources[e]&&(t.selectedSource=t.sources[e])}}var root="undefined"!=typeof window?window:global,odm=new JsonOdm;root.jsonOdm||(root.jsonOdm=odm),"undefined"!=typeof module&&module.exports&&(module.exports=odm),jsonOdm.Util=function(){},jsonOdm.Util.prototype.isArray=function(t){return Array.isArray?Array.isArray(t):"[object Array]"===Object.prototype.toString.call(t)},jsonOdm.Util.prototype.is=function(t,e){e="string"==typeof e?[e]:e;var o=Object.prototype.toString.call(t);o=o.substring(8,o.length-1).toLowerCase();for(var n=0;n<e.length;n++){var r=e[n].toLowerCase();if("array"==r&&this.isArray(t))return!0;if(r==o)return!0;if(typeof t==r)return!0}return!1},jsonOdm.Util.prototype.objectKeys=Object.keys||function(){var t=Object.prototype.hasOwnProperty,e=!{toString:null}.propertyIsEnumerable("toString"),o=["toString","toLocaleString","valueOf","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","constructor"],n=o.length;return function(r){if("object"!=typeof r&&("function"!=typeof r||null===r))throw new TypeError("Object.keys called on non-object");var i,s,u=[];for(i in r)t.call(r,i)&&u.push(i);if(e)for(s=0;n>s;s++)t.call(r,o[s])&&u.push(o[s]);return u}}(),jsonOdm.Util.prototype.branch=function(t,e){function o(){if(arguments&&arguments.length&&this){var t=this[arguments[0]];return t?o.apply(t,Array.prototype.slice.call(arguments,1)):t}return this}return o.apply(t,e)},jsonOdm.Util.prototype.projectElement=function(t,e,o){var n={};for(var r in t)t.hasOwnProperty(r)&&(1==t[r]?n[r]=e[r]:"function"==typeof t[r]?n[r]=t[r](o||e):t[r]instanceof jsonOdm.Query?n[r]=t[r].$$commandQueue[t[r].$$commandQueue.length-1](e):"object"==typeof t[r]&&(n[r]=this.projectElement(t[r],e[r],o||e)));return n},jsonOdm.util=new jsonOdm.Util,jsonOdm.Geo=function(){},jsonOdm.Geo.detectAsGeometry=function(t){if(!t.type)if(jsonOdm.util.isArray(t)&&2==t.length&&!jsonOdm.util.isArray(t[0]))t=new jsonOdm.Geo.Point(t);else if(jsonOdm.util.isArray(t)&&4==t.length&&!jsonOdm.util.isArray(t[0]))t=new jsonOdm.Geo.BoundaryBox(t);else if(jsonOdm.util.isArray(t)&&t.length>=1&&jsonOdm.util.isArray(t[0])&&2==t[0].length&&!jsonOdm.util.isArray(t[0][0]))t=new jsonOdm.Geo.LineString(t);else if(jsonOdm.util.isArray(t)&&t.length>=1&&jsonOdm.util.isArray(t[0])&&t[0].length>=1&&jsonOdm.util.isArray(t[0][0])&&2==t[0][0].length&&!jsonOdm.util.isArray(t[0][0][0]))t=new jsonOdm.Geo.Polygon(t);else{if(!(jsonOdm.util.isArray(t)&&t.length>=1&&jsonOdm.util.isArray(t[0])&&t[0].length>=1&&jsonOdm.util.isArray(t[0][0])&&t[0][0].length>=1&&jsonOdm.util.isArray(t[0][0][0])&&2==t[0][0][0].length)||jsonOdm.util.isArray(t[0][0][0][0]))return!1;t=new jsonOdm.Geo.MultiPolygon(t)}return t},jsonOdm.Geo.FeatureCollection=function(t,e){this.type="FeatureCollection",this.features=t||[],e&&(this.bbox=e)},jsonOdm.Geo.Feature=function(t,e,o,n){this.geometry=t||{},e&&(this.properties=e),o&&(this.bbox=o),n&&(this.id=n)},jsonOdm.Geo.BoundaryBox=function(t){var e=Object.create(Array.prototype);return e=Array.apply(e)||e,jsonOdm.util.isArray(t)?(e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3]):(e[0]=0,e[1]=0,e[2]=0,e[3]=0),e},jsonOdm.Geo.BoundaryBox.within=function(t,e){return jsonOdm.util.isArray(t)&&4==t.length?jsonOdm.Geo.Polygon.within(new jsonOdm.Geo.Polygon([[[t[0],t[1]],[t[2],t[1]],[t[2],t[3]],[t[0],t[3]],[t[0],t[1]]]]),e):!1},jsonOdm.Geo.Point=function(t,e){this.type="Point",this.coordinates=t,e&&(this.bbox=e)},jsonOdm.Geo.Point.within=function(t,e){var o,n;if(!t.coordinates)return!1;if("Point"==e.type)return e.coordinates[0]==t.coordinates[0]&&e.coordinates[1]==t.coordinates[1];if("MultiPoint"==e.type||"LineString"==e.type){for(o=0;e.coordinates&&o<e.coordinates.length;o++)if(e.coordinates[o][0]==t.coordinates[0]&&e.coordinates[o][1]==t.coordinates[1])return!0;return!1}if("MultiLineString"==e.type){for(o=0;e.coordinates&&o<e.coordinates.length;o++)for(n=0;e.coordinates[o]&&n<e.coordinates[o].length;n++)if(e.coordinates[o][n][0]==t.coordinates[0]&&e.coordinates[o][n][1]==t.coordinates[1])return!0;return!1}if("Polygon"==e.type)return jsonOdm.Geo.pointWithinPolygon(t.coordinates,e.coordinates?e.coordinates[0]:null);if("MultiPolygon"==e.type){for(o=0;e.coordinates&&o<e.coordinates.length;o++)if(jsonOdm.Geo.pointWithinPolygon(t.coordinates,e.coordinates[o]?e.coordinates[o][0]:null))return!0;return!1}if("GeometryCollection"==e.type&&jsonOdm.util.isArray(e.geometries)){for(o=0;o<e.geometries.length;o++)if(jsonOdm.Geo.Point.within(t,e.geometries[o]))return!0;return!1}return jsonOdm.Geo.pointWithinBounds(t.coordinates,e)},jsonOdm.Geo.Point.intersects=jsonOdm.Geo.Point.within,jsonOdm.Geo.MultiPoint=function(t,e){this.type="MultiPoint",this.coordinates=t,e&&(this.bbox=e)},jsonOdm.Geo.MultiPoint.within=function(t,e){var o,n,r,i;if(!t.coordinates||!jsonOdm.util.isArray(t.coordinates))return!1;if("Point"==e.type)return 1==t.coordinates.length&&t.coordinates[0][0]==e.coordinates[0]&&t.coordinates[0][1]==e.coordinates[1];if("MultiPoint"==e.type){for(n=0;t.coordinates&&n<t.coordinates.length;n++){for(i=!1,o=0;e.coordinates&&o<e.coordinates.length;o++)if(e.coordinates[o][0]==t.coordinates[n][0]&&e.coordinates[o][1]==t.coordinates[n][1]){i=!0;break}if(!i)return!1}return!0}if("LineString"==e.type){for(r=0;t.coordinates&&r<t.coordinates.length;r++)if(!jsonOdm.Geo.pointWithinLineString(t.coordinates[r],e.coordinates))return!1;return!0}if("MultiLineString"==e.type){for(r=0;t.coordinates&&r<t.coordinates.length;r++){for(i=!1,o=0;e.coordinates&&o<e.coordinates.length;o++)if(jsonOdm.Geo.pointWithinLineString(t.coordinates[r],e.coordinates[o])){i=!0;break}if(!i)return!1}return!0}if("Polygon"==e.type){for(o=0;t.coordinates&&o<t.coordinates.length;o++)if(!jsonOdm.Geo.pointWithinPolygon(t.coordinates[o],e.coordinates?e.coordinates[0]:null))return!1;return!0}if("MultiPolygon"==e.type){for(n=0;t.coordinates&&n<t.coordinates.length;n++){for(i=!1,o=0;e.coordinates&&o<e.coordinates.length;o++)if(jsonOdm.Geo.pointWithinPolygon(t.coordinates[n],e.coordinates[o]?e.coordinates[o][0]:null)){i=!0;break}if(!i)return!1}return!0}if("GeometryCollection"==e.type&&jsonOdm.util.isArray(e.geometries)){for(o=0;o<e.geometries.length;o++)if(jsonOdm.Geo.MultiPoint.within(t,e.geometries[o]))return!0;return!1}for(o=0;o<t.coordinates.length;o++)if(!jsonOdm.Geo.pointWithinBounds(t.coordinates[o],e))return!1;return!0},jsonOdm.Geo.MultiPoint.intersects=function(t,e){var o,n,r;if(!t.coordinates||!jsonOdm.util.isArray(t.coordinates))return!1;if("Point"==e.type)return jsonOdm.Geo.Point.intersects(e,t);if("MultiPoint"==e.type){for(n=0;t.coordinates&&n<t.coordinates.length;n++)for(o=0;e.coordinates&&o<e.coordinates.length;o++)if(e.coordinates[o][0]==t.coordinates[n][0]&&e.coordinates[o][1]==t.coordinates[n][1])return!0;return!1}if("LineString"==e.type){for(r=0;t.coordinates&&r<t.coordinates.length;r++)if(jsonOdm.Geo.pointWithinLineString(t.coordinates[r],e.coordinates))return!0;return!1}if("MultiLineString"==e.type){for(r=0;t.coordinates&&r<t.coordinates.length;r++)for(o=0;e.coordinates&&o<e.coordinates.length;o++)if(jsonOdm.Geo.pointWithinLineString(t.coordinates[r],e.coordinates[o]))return!0;return!1}if("Polygon"==e.type){for(o=0;t.coordinates&&o<t.coordinates.length;o++)if(jsonOdm.Geo.pointWithinPolygon(t.coordinates[o],e.coordinates?e.coordinates[0]:null))return!0;return!1}if("MultiPolygon"==e.type){for(n=0;t.coordinates&&n<t.coordinates.length;n++)for(o=0;e.coordinates&&o<e.coordinates.length;o++)if(jsonOdm.Geo.pointWithinPolygon(t.coordinates[n],e.coordinates[o]?e.coordinates[o][0]:null))return!0;return!1}if("GeometryCollection"==e.type&&jsonOdm.util.isArray(e.geometries)){for(o=0;o<e.geometries.length;o++)if(jsonOdm.Geo.MultiPoint.intersects(t,e.geometries[o]))return!0;return!1}for(o=0;o<t.coordinates.length;o++)if(jsonOdm.Geo.pointWithinBounds(t.coordinates[o],e))return!0;return!1},jsonOdm.Geo.LineString=function(t,e){this.type="LineString",this.coordinates=t,e&&(this.bbox=e)},jsonOdm.Geo.LineString.within=function(t,e){var o,n;if(!t.coordinates||!jsonOdm.util.isArray(t.coordinates))return!1;if("Point"==e.type||"MultiPoint"==e.type)return!1;if("LineString"==e.type)return jsonOdm.Geo.lineStringWithinLineString(t.coordinates,e.coordinates);if("MultiLineString"==e.type){for(o=0;e.coordinates&&o<e.coordinates.length;o++)if(jsonOdm.Geo.lineStringWithinLineString(t.coordinates,e.coordinates[o]))return!0;return!1}if("Polygon"==e.type){for(o=0;t.coordinates&&o<t.coordinates.length-1;o++)if(!jsonOdm.Geo.edgeWithinPolygon([t.coordinates[o],t.coordinates[o+1]],e.coordinates[0]))return!1;return!0}if("MultiPolygon"==e.type){for(o=0;e.coordinates&&o<e.coordinates.length;o++)for(n=0;t.coordinates&&n<t.coordinates.length-1;n++)if(jsonOdm.Geo.edgeWithinPolygon([t.coordinates[n],t.coordinates[n+1]],e.coordinates[o][0])&&n+1==t.coordinates.length-1)return!0;return!1}if("GeometryCollection"==e.type&&jsonOdm.util.isArray(e.geometries)){for(o=0;o<e.geometries.length;o++)if(jsonOdm.Geo.LineString.within(t,e.geometries[o]))return!0;return!1}for(o=0;o<t.coordinates.length;o++)if(!jsonOdm.Geo.pointWithinBounds(t.coordinates[o],e))return!1;return!0},jsonOdm.Geo.LineString.intersects=function(t,e){var o,n;if(!t.coordinates||!jsonOdm.util.isArray(t.coordinates))return!1;if("Point"==e.type)return jsonOdm.Geo.Point.intersects(e,t);if("MultiPoint"==e.type)return jsonOdm.Geo.MultiPoint.intersects(e,t);if("LineString"==e.type){for(o=0;o<t.coordinates.length-1;o++)if(jsonOdm.Geo.edgeIntersectsLineString([t.coordinates[o],t.coordinates[o+1]],e.coordinates))return!0;return!1}if("MultiLineString"==e.type){for(o=0;e.coordinates&&o<e.coordinates.length;o++)for(n=0;n<t.coordinates.length-1;n++)if(jsonOdm.Geo.edgeIntersectsLineString([t.coordinates[n],t.coordinates[n+1]],e.coordinates[o]))return!0;return!1}if("Polygon"==e.type){for(o=0;t.coordinates&&o<t.coordinates.length-1;o++)if(jsonOdm.Geo.edgeIntersectsPolygon([t.coordinates[o],t.coordinates[o+1]],e.coordinates[0]))return!0;return!1}if("MultiPolygon"==e.type){for(o=0;e.coordinates&&o<e.coordinates.length;o++)for(n=0;t.coordinates&&n<t.coordinates.length-1;n++)if(jsonOdm.Geo.edgeIntersectsPolygon([t.coordinates[n],t.coordinates[n+1]],e.coordinates[o][0]))return!0;return!1}if("GeometryCollection"==e.type&&jsonOdm.util.isArray(e.geometries)){for(o=0;o<e.geometries.length;o++)if(jsonOdm.Geo.LineString.intersects(t,e.geometries[o]))return!0;return!1}for(o=0;t.coordinates&&o<t.coordinates.length-1;o++)if(jsonOdm.Geo.edgeIntersectsBounds([t.coordinates[o],t.coordinates[o+1]],e))return!0;return!1},jsonOdm.Geo.MultiLineString=function(t,e){this.type="MultiLineString",this.coordinates=t,e&&(this.bbox=e)},jsonOdm.Geo.MultiLineString.within=function(t,e){var o,n,r,i;if(!t.coordinates||!jsonOdm.util.isArray(t.coordinates))return!1;if("Point"==e.type||"MultiPoint"==e.type)return!1;if("LineString"==e.type){for(o=0;t.coordinates&&o<t.coordinates.length;o++)if(!jsonOdm.Geo.lineStringWithinLineString(t.coordinates[o],e.coordinates))return!1;return!0}if("MultiLineString"==e.type){for(n=0;t.coordinates&&n<t.coordinates.length;n++){for(i=!1,o=0;e.coordinates&&o<e.coordinates.length;o++)if(jsonOdm.Geo.lineStringWithinLineString(t.coordinates[n],e.coordinates[o])){i=!0;break}if(!i)return!1}return!0}if("Polygon"==e.type){for(o=0;t.coordinates&&o<t.coordinates.length;o++)for(n=0;t.coordinates&&n<t.coordinates[o].length-1;n++)if(!jsonOdm.Geo.edgeWithinPolygon([t.coordinates[o][n],t.coordinates[o][n+1]],e.coordinates[0]))return!1;return!0}if("MultiPolygon"==e.type){for(n=0;t.coordinates&&n<t.coordinates.length;n++){for(i=!1,o=0;e.coordinates&&o<e.coordinates.length;o++)for(r=0;t.coordinates[n]&&r<t.coordinates[n].length-1;r++)if(jsonOdm.Geo.edgeWithinPolygon([t.coordinates[n][r],t.coordinates[n][r+1]],e.coordinates[o][0])&&r+1==t.coordinates[n].length-1){i=!0;break}if(!i)return!1}return!0}if("GeometryCollection"==e.type&&jsonOdm.util.isArray(e.geometries)){for(o=0;o<e.geometries.length;o++)if(jsonOdm.Geo.MultiLineString.within(t,e.geometries[o]))return!0;return!1}for(o=0;o<t.coordinates.length;o++)for(n=0;n<t.coordinates[o].length;n++)if(!jsonOdm.Geo.pointWithinBounds(t.coordinates[o][n],e))return!1;return!0},jsonOdm.Geo.MultiLineString.intersects=function(t,e){var o,n,r;if(!t.coordinates||!jsonOdm.util.isArray(t.coordinates))return!1;if("Point"==e.type)return jsonOdm.Geo.Point.intersects(e,t);if("MultiPoint"==e.type)return jsonOdm.Geo.MultiPoint.intersects(e,t);if("LineString"==e.type)return jsonOdm.Geo.LineString.intersects(e,t);if("MultiLineString"==e.type){for(n=0;t.coordinates&&n<t.coordinates.length;n++)for(r=0;t.coordinates[n]&&r<t.coordinates[n].length-1;r++)for(o=0;e.coordinates&&o<e.coordinates.length;o++)if(jsonOdm.Geo.edgeIntersectsLineString([t.coordinates[n][r],t.coordinates[n][r+1]],e.coordinates[o]))return!0;return!1}if("Polygon"==e.type){for(o=0;t.coordinates&&o<t.coordinates.length;o++)for(n=0;t.coordinates&&n<t.coordinates[o].length-1;n++)if(jsonOdm.Geo.edgeIntersectsPolygon([t.coordinates[o][n],t.coordinates[o][n+1]],e.coordinates[0]))return!0;return!1}if("MultiPolygon"==e.type){for(n=0;t.coordinates&&n<t.coordinates.length;n++)for(o=0;e.coordinates&&o<e.coordinates.length;o++)for(r=0;t.coordinates[n]&&r<t.coordinates[n].length-1;r++)if(jsonOdm.Geo.edgeIntersectsPolygon([t.coordinates[n][r],t.coordinates[n][r+1]],e.coordinates[o][0]))return!0;return!1}if("GeometryCollection"==e.type&&jsonOdm.util.isArray(e.geometries)){for(o=0;o<e.geometries.length;o++)if(jsonOdm.Geo.MultiLineString.intersects(t,e.geometries[o]))return!0;return!1}for(o=0;t.coordinates&&o<t.coordinates.length;o++)for(n=0;n<t.coordinates[o].length-1;n++)if(jsonOdm.Geo.edgeIntersectsBounds([t.coordinates[o][n],t.coordinates[o][n+1]],e))return!0;return!1},jsonOdm.Geo.Polygon=function(t,e){this.type="Polygon",this.coordinates=t,e&&(this.bbox=e)},jsonOdm.Geo.Polygon.within=function(t,e){var o,n;if(!t.coordinates||!jsonOdm.util.isArray(t.coordinates))return!1;if("Point"==e.type||"MultiPoint"==e.type||"LineString"==e.type||"MultiLineString"==e.type)return!1;if("Polygon"==e.type){for(o=0;t.coordinates[0]&&o<t.coordinates[0].length-1;o++)if(!jsonOdm.Geo.edgeWithinPolygon([t.coordinates[0][o],t.coordinates[0][o+1]],e.coordinates[0]))return!1;return!0}if("MultiPolygon"==e.type){for(o=0;e.coordinates&&o<e.coordinates.length;o++)for(n=0;t.coordinates[0]&&n<t.coordinates[0].length-1;n++){var r=jsonOdm.Geo.edgeWithinPolygon([t.coordinates[0][n],t.coordinates[0][n+1]],e.coordinates[o][0]);if(!r)break;if(r&&n+1==t.coordinates[0].length-1)return!0}return!1}if("GeometryCollection"==e.type&&jsonOdm.util.isArray(e.geometries)){for(o=0;o<e.geometries.length;o++)if(jsonOdm.Geo.Polygon.within(t,e.geometries[o]))return!0;return!1}for(o=0;t.coordinates[0]&&o<t.coordinates[0].length;o++)if(!jsonOdm.Geo.pointWithinBounds(t.coordinates[0][o],e))return!1;return!0},jsonOdm.Geo.Polygon.intersects=function(t,e){var o,n;if(!t.coordinates||!jsonOdm.util.isArray(t.coordinates))return!1;if("Point"==e.type)return jsonOdm.Geo.Point.intersects(e,t);if("MultiPoint"==e.type)return jsonOdm.Geo.MultiPoint.intersects(e,t);if("LineString"==e.type)return jsonOdm.Geo.LineString.intersects(e,t);if("MultiLineString"==e.type)return jsonOdm.Geo.MultiLineString.intersects(e,t);if("Polygon"==e.type){for(o=0;t.coordinates[0]&&o<t.coordinates[0].length-1;o++)if(jsonOdm.Geo.edgeIntersectsPolygon([t.coordinates[0][o],t.coordinates[0][o+1]],e.coordinates[0]))return!0;return!1}if("MultiPolygon"==e.type){for(o=0;e.coordinates&&o<e.coordinates.length;o++)for(n=0;t.coordinates[0]&&n<t.coordinates[0].length-1;n++)if(jsonOdm.Geo.edgeIntersectsPolygon([t.coordinates[0][n],t.coordinates[0][n+1]],e.coordinates[o][0]))return!0;return!1}if("GeometryCollection"==e.type&&jsonOdm.util.isArray(e.geometries)){for(o=0;o<e.geometries.length;o++)if(jsonOdm.Geo.Polygon.intersects(t,e.geometries[o]))return!0;return!1}for(o=0;t.coordinates[0]&&o<t.coordinates[0].length-1;o++)if(jsonOdm.Geo.edgeIntersectsBounds([t.coordinates[0][o],t.coordinates[0][o+1]],e))return!0;return!1},jsonOdm.Geo.MultiPolygon=function(t,e){this.type="MultiPolygon",this.coordinates=t,e&&(this.bbox=e)},jsonOdm.Geo.MultiPolygon.within=function(t,e){var o,n,r,i;if(!t.coordinates||!jsonOdm.util.isArray(t.coordinates))return!1;if("Point"==e.type||"MultiPoint"==e.type||"LineString"==e.type||"MultiLineString"==e.type)return!1;if("Polygon"==e.type){for(o=0;t.coordinates&&o<t.coordinates.length;o++)for(n=0;n<t.coordinates[o][0].length-1;n++)if(!jsonOdm.Geo.edgeWithinPolygon([t.coordinates[o][0][n],t.coordinates[o][0][n+1]],e.coordinates[0]))return!1;return!0}if("MultiPolygon"==e.type){for(o=0;t.coordinates&&o<t.coordinates.length;o++){for(i=!1,n=0;e.coordinates&&n<e.coordinates.length;n++)for(r=0;t.coordinates[o][0]&&r<t.coordinates[o][0].length-1;r++){var s=jsonOdm.Geo.edgeWithinPolygon([t.coordinates[o][0][r],t.coordinates[o][0][r+1]],e.coordinates[n][0]);if(!s)break;if(s&&r+1==t.coordinates[o][0].length-1){i=!0;break}}if(!i)return!1}return!0}if("GeometryCollection"==e.type&&jsonOdm.util.isArray(e.geometries)){for(o=0;o<e.geometries.length;o++)if(jsonOdm.Geo.MultiPolygon.within(t,e.geometries[o]))return!0;return!1}for(o=0;o<t.coordinates.length;o++)for(n=0;n<t.coordinates[o][0].length;n++)if(!jsonOdm.Geo.pointWithinBounds(t.coordinates[o][0][n],e))return!1;return!0},jsonOdm.Geo.MultiPolygon.intersects=function(t,e){var o,n,r;if(!t.coordinates||!jsonOdm.util.isArray(t.coordinates))return!1;if("Point"==e.type)return jsonOdm.Geo.Point.intersects(e,t);if("MultiPoint"==e.type)return jsonOdm.Geo.MultiPoint.intersects(e,t);if("LineString"==e.type)return jsonOdm.Geo.LineString.intersects(e,t);if("MultiLineString"==e.type)return jsonOdm.Geo.MultiLineString.intersects(e,t);if("Polygon"==e.type)return jsonOdm.Geo.Polygon.intersects(e,t);if("MultiPolygon"==e.type){for(o=0;t.coordinates&&o<t.coordinates.length;o++)for(n=0;e.coordinates&&n<e.coordinates.length;n++)for(r=0;t.coordinates[o][0]&&r<t.coordinates[o][0].length-1;r++)if(jsonOdm.Geo.pointWithinPolygon(t.coordinates[o][0][r],e.coordinates[n][0]))return!0;return!1}if("GeometryCollection"==e.type&&jsonOdm.util.isArray(e.geometries)){for(o=0;o<e.geometries.length;o++)if(jsonOdm.Geo.MultiPolygon.intersects(t,e.geometries[o]))return!0;return!1}for(o=0;o<t.coordinates.length;o++)for(n=0;n<t.coordinates[o][0].length-1;n++)if(jsonOdm.Geo.edgeIntersectsBounds([t.coordinates[o][0][n],t.coordinates[o][0][n+1]],e))return!0;return!1},jsonOdm.Geo.GeometryCollection=function(t,e){this.type="GeometryCollection",this.geometries=t,e&&(this.bbox=e)},jsonOdm.Geo.GeometryCollection.within=function(t,e){if(!jsonOdm.util.isArray(t.geometries)||!t.geometries.length||!e.type)return!1;for(var o=0;o<t.geometries.length;o++){if(!jsonOdm.Geo[t.geometries[o].type]||!jsonOdm.Geo[t.geometries[o].type].within)return!1;if(!jsonOdm.Geo[t.geometries[o].type].within(t.geometries[o],e))return!1}return!0},jsonOdm.Geo.GeometryCollection.intersects=function(t,e){if(!jsonOdm.util.isArray(t.geometries)||!t.geometries.length||!e.type)return!1;for(var o=0;o<t.geometries.length;o++)if(jsonOdm.Geo[t.geometries[o].type]&&jsonOdm.Geo[t.geometries[o].type].intersects&&jsonOdm.Geo[t.geometries[o].type].intersects(t.geometries[o],e))return!0;return!1},jsonOdm.Geo.pointWithinPolygon=function(t,e){if(!(jsonOdm.util.isArray(t)&&jsonOdm.util.isArray(e)&&e.length>2))return!1;var o,n=0;(e[0][0]!=e[e.length-1][0]||e[0][1]!=e[e.length-1][1])&&(e=e.concat([e[0]]));for(var r=0;r<e.length-1;r++){if(e[r][0]==t[0]&&e[r][1]==t[1])return!0;if(!(e[r][0]<t[0]&&e[r+1][0]<t[0]||e[r][1]<t[1]&&e[r+1][1]<t[1]||e[r][1]>t[1]&&e[r+1][1]>t[1])){if(o=(e[r][0]-e[r+1][0])*((t[1]-e[r+1][1])/(e[r][1]-e[r+1][1]))+e[r+1][0],o==t[0]&&t[1]<=Math.max(e[r][1],e[r+1][1])&&t[1]>=Math.min(e[r][1],e[r+1][1]))return!0;o>t[0]&&n++}}return n%2==1},jsonOdm.Geo.edgeWithinPolygon=function(t,e){if(!(jsonOdm.util.isArray(t)&&2==t.length&&jsonOdm.util.isArray(e)&&e.length>=2))return!1;if((e[0][0]!=e[e.length-1][0]||e[0][1]!=e[e.length-1][1])&&(e=e.concat([e[0]])),!jsonOdm.Geo.pointWithinPolygon(t[0],e)||!jsonOdm.Geo.pointWithinPolygon(t[1],e))return!1;for(var o=0;o<e.length-1;o++)if(jsonOdm.Geo.edgeIntersectsEdge(t,[e[o],e[o+1]],!1))return!1;return!0},jsonOdm.Geo.edgeIntersectsPolygon=function(t,e){if(!(jsonOdm.util.isArray(t)&&2==t.length&&jsonOdm.util.isArray(e)&&e.length>=2))return!1;if((e[0][0]!=e[e.length-1][0]||e[0][1]!=e[e.length-1][1])&&(e=e.concat([e[0]])),jsonOdm.Geo.pointWithinPolygon(t[0],e)||jsonOdm.Geo.pointWithinPolygon(t[1],e))return!0;for(var o=0;o<e.length-1;o++)if(jsonOdm.Geo.edgeIntersectsEdge(t,[e[o],e[o+1]]))return!0;return!1},jsonOdm.Geo.edgeIntersectsLineString=function(t,e){if(!jsonOdm.util.isArray(t)||2!=t.length||!jsonOdm.util.isArray(e))return!1;for(var o=0;o<e.length-1;o++)if(jsonOdm.Geo.edgeIntersectsEdge(t,[e[o],e[o+1]]))return!0;return!1},jsonOdm.Geo.edgeIntersectsEdge=function(t,e,o){o="undefined"==typeof o?!0:o;var n=[t[1][0]-t[0][0],t[1][1]-t[0][1]],r=[Math.min(t[0][0],t[1][0]),Math.min(t[0][1],t[1][1]),Math.max(t[0][0],t[1][0]),Math.max(t[0][1],t[1][1])],i=[e[1][0]-e[0][0],e[1][1]-e[0][1]],s=[Math.min(e[0][0],e[1][0]),Math.min(e[0][1],e[1][1]),Math.max(e[0][0],e[1][0]),Math.max(e[0][1],e[1][1])];if(r[0]>s[0]&&r[0]>s[2]||r[1]>s[1]&&r[1]>s[3]||s[0]>r[0]&&s[0]>r[2]||s[1]>r[1]&&s[1]>r[3])return!1;if(i[0]*n[1]-n[0]*i[1]==0)return o&&t[0][1]+(e[0][0]-t[0][0])/n[0]*n[1]==e[0][1];var u=(e[0][1]*i[0]+t[0][0]*i[1]-e[0][0]*i[1]-t[0][1]*i[0])/(n[1]*i[0]-n[0]*i[1]),d=t[0][0]+u*n[0],c=t[0][1]+u*n[1];return o?d>=r[0]&&d<=r[2]&&c>=r[1]&&c<=r[3]&&d>=s[0]&&d<=s[2]&&c>=s[1]&&c<=s[3]:d>r[0]&&d<r[2]&&c>r[1]&&c<r[3]&&d>s[0]&&d<s[2]&&c>s[1]&&c<s[3]},jsonOdm.Geo.pointWithinLineString=function(t,e){if(!(jsonOdm.util.isArray(t)&&jsonOdm.util.isArray(e)&&e.length>=2))return!1;for(var o=0;o<e.length-1;o++)if((t[0]>=e[o][0]&&t[0]<=e[o+1][0]&&e[o][0]<=e[o+1][0]||t[0]<=e[o][0]&&t[0]>=e[o+1][0]&&e[o][0]>=e[o+1][0])&&(t[1]>=e[o][1]&&t[1]<=e[o+1][1]&&e[o][1]<=e[o+1][1]||t[1]<=e[o][1]&&t[1]>=e[o+1][1]&&e[o][1]>=e[o+1][1])&&(e[o][0]==t[0]&&e[o][1]==t[1]||e[o+1][0]==t[0]&&e[o+1][1]==t[1]||e[o][1]-e[o+1][1]!=0&&(e[o][0]-e[o+1][0])*((t[1]-e[o+1][1])/(e[o][1]-e[o+1][1]))+e[o+1][0]==t[0]||e[o][0]-e[o+1][0]!=0&&(e[o][1]-e[o+1][1])*((t[0]-e[o+1][0])/(e[o][0]-e[o+1][0]))+e[o+1][1]==t[1]))return!0;return!1},jsonOdm.Geo.pointWithinBounds=function(t,e){return jsonOdm.util.isArray(t)&&jsonOdm.util.isArray(e)&&4==e.length?t[0]>=e[0]&&t[1]>=e[1]&&t[0]<=e[2]&&t[1]<=e[3]:!1},jsonOdm.Geo.edgeIntersectsBounds=function(t,e){return jsonOdm.util.isArray(t)&&jsonOdm.util.isArray(e)&&4==e.length?jsonOdm.Geo.edgeIntersectsPolygon(t,[[e[0],e[1]],[e[2],e[1]],[e[2],e[3]],[e[0],e[3]]]):!1},jsonOdm.Geo.lineStringWithinLineString=function(t,e){if(!jsonOdm.util.isArray(t)||!jsonOdm.util.isArray(e))return!1;var o,n;for(o=0;t&&o<t.length;o++){var r=!1;for(n=0;e&&n<e.length;n++)if(t[o][0]==e[n][0]&&t[o][1]==e[n][1]){if(o+1==t.length)return!0;if(!(e[n+1]&&t[o+1][0]==e[n+1][0]&&t[o+1][1]==e[n+1][1]||t[o+1][0]==e[n][0]&&t[o+1][1]==e[n][1]||n>0&&t[o+1][0]==e[n-1][0]&&t[o+1][1]==e[n-1][1]))return!1;r=!0}if(!r)return!1}return!0},jsonOdm.Collection=function(t){var e=Object.create(Array.prototype);return e=Array.apply(e)||e,"undefined"!=typeof t&&jsonOdm.selectedSource&&jsonOdm.selectedSource[t]&&(e=e.concat(jsonOdm.selectedSource[t])),jsonOdm.Collection.decorate(e),e.$branch=function(){var t=jsonOdm.util.branch(e,arguments);return jsonOdm.Collection.decorate(t),t},e},jsonOdm.Collection.decorate=function(t){var e=function(t){jsonOdm.util.isArray(t)&&(t.$hasMany=function(e,o,n,r){"string"==typeof n&&(r=r||n);var i=n;"string"==typeof n&&jsonOdm.selectedSource&&jsonOdm.selectedSource[n]&&(i=jsonOdm.selectedSource[n]);for(var s=0;s<t.length;s++){var u=e;if(t[s].hasOwnProperty(e)&&(u=t[s][e]),"undefined"==typeof t[s][r])for(var d=0;u.length&&d<u.length;d++){for(var c=null,a=0;a<i.length;a++)if(u[d]==i[a][o]){c=i[a];break}null!=c&&(t[s][r]||(t[s][r]=[]),t[s][r].push(c))}}},t.$hasOne=function(e,o,n,r){"string"==typeof n&&(r=r||n);var i=n;"string"==typeof n&&jsonOdm.selectedSource&&jsonOdm.selectedSource[n]&&(i=jsonOdm.selectedSource[n]);for(var s=0;s<t.length;s++){var u;if(t[s].hasOwnProperty(e)&&(u=t[s][e]),"undefined"==typeof t[s][r]){for(var d=null,c=0;c<i.length;c++)if(u==i[c][o]){d=i[c];break}null!=d&&(t[s][r]=d)}}},t.$query=function(){return new jsonOdm.Query(t)})};e(t)},jsonOdm.Query=function(t){this.$$commandQueue=[],this.$$aggregationBeforeCollectQueue=[],this.$$aggregationResultQueue=[],this.$$collection=t||[]},jsonOdm.Query.prototype.$delete=function(){if(this.$$commandQueue.length<1)return this;for(var t=0;t<this.$$collection.length;){for(var e=!0,o=0;o<this.$$commandQueue.length&&(e=e&&this.$$commandQueue[o](this.$$collection[t]));o++);e?this.$$collection.splice(t,1):t++}return this},jsonOdm.Query.prototype.$result=function(t,e){if(this.$$commandQueue.length<1&&this.$$aggregationBeforeCollectQueue<1)return this.$$collection;t="undefined"==typeof t?0:t,e="undefined"==typeof e?this.$$collection.length:e;var o,n,r,i=new jsonOdm.Collection;for(n=0;n<this.$$collection.length;n++){var s=!0;for(r=0;r<this.$$commandQueue.length&&(s=s&&this.$$commandQueue[r](this.$$collection[n]));r++);if(s){if(t>0){t--;continue}if(0>=e)return i;for(o=this.$$collection[n],r=0;r<this.$$aggregationBeforeCollectQueue.length;r++)o=this.$$aggregationBeforeCollectQueue[r](n,o);i.push(o),e--}}for(n=0;n<this.$$aggregationResultQueue.length;n++)i=this.$$aggregationResultQueue[n](i);return i},jsonOdm.Query.prototype.$all=function(){return this.$result()},jsonOdm.Query.prototype.$first=function(){return this.$result(0,1)[0]},jsonOdm.Query.prototype.$aggregateCollection=function(t,e,o){return"function"==typeof t&&(t=[t]),"function"==typeof e&&(e=[e]),"function"==typeof o&&(o=[o]),jsonOdm.util.isArray(t)&&(this.$$commandQueue=this.$$commandQueue.concat(t)),jsonOdm.util.isArray(e)&&(this.$$aggregationBeforeCollectQueue=this.$$aggregationBeforeCollectQueue.concat(e)),jsonOdm.util.isArray(o)&&(this.$$aggregationResultQueue=this.$$aggregationResultQueue.concat(o)),this},jsonOdm.Query.prototype.$project=function(t){return this.$aggregateCollection(null,function(e,o){return jsonOdm.util.projectElement(t,o)})},jsonOdm.Query.prototype.$testCollection=function(t,e){var o=this.$$commandQueue.pop(),n=function(){return function(n){if(!(o instanceof jsonOdm.Collection||"function"==typeof o||"undefined"==typeof o)||"function"!=typeof e)return!1;var r="undefined"==typeof o?n:o instanceof jsonOdm.Collection?o:o(n);return!!e(r,t)}}();return this.$$commandQueue.push(n),this},jsonOdm.Query.prototype.$queryOperator=function(t,e){var o=function(t,o){return function(n){if("function"!=typeof o)return!1;for(var r=[],i=0;i<t.length;i++)if(t[i]instanceof jsonOdm.Query)for(var s=0;s<t[i].$$commandQueue.length;s++)r.push(t[i].$$commandQueue[s](n));else r.push(t[i]);return e(r)}}(t,e),n=new jsonOdm.Query(this.$$collection);return n.$$commandQueue.push(o),n},jsonOdm.Query.prototype.$branch=function(){var t=function(t){return function(e){return jsonOdm.util.branch(e,t)}}(arguments),e=new jsonOdm.Query(this.$$collection);return e.$$commandQueue.push(t),e},jsonOdm.Query.prototype.$modifyField=function(t){var e=function(t,e){return function(o){return o=null!==e?e(o):o,"function"==typeof t?t(o):o}}(t,this.$$commandQueue.length?this.$$commandQueue[this.$$commandQueue.length-1]:null);return this.$$commandQueue.push(e),this},jsonOdm.Query.stringFiledModifyer=["charAt","charCodeAt","concat","fromCharCode","indexOf","lastIndexOf","localeCompare","match","replace","search","slice","split","substr","substring","toLocaleLowerCase","toLocaleUpperCase","toLowerCase","toUpperCase","trim","valueOf"];for(var i=0;i<jsonOdm.Query.stringFiledModifyer.length;i++)jsonOdm.Query.prototype["$"+jsonOdm.Query.stringFiledModifyer[i]]=function(t){return function(){return this.$modifyField(function(t,e){return function(o){return"string"==typeof o&&String.prototype.hasOwnProperty(e)?String.prototype[e].apply(o,t):o}}(arguments,t))}}(jsonOdm.Query.stringFiledModifyer[i]);jsonOdm.Query.prototype.$add=function(){return this.$queryOperator(arguments,function(t){for(var e=t.length>0?t[0]:0,o=1;o<t.length;o++)e+=t[o];return e})},jsonOdm.Query.prototype.$subtract=function(){return this.$queryOperator(arguments,function(t){for(var e=t.length>0?t[0]:0,o=1;o<t.length;o++)e-=t[o];return e})},jsonOdm.Query.prototype.$multiply=function(){return this.$queryOperator(arguments,function(t){for(var e=t.length>0?t[0]:0,o=1;o<t.length;o++)e*=t[o];return e})},jsonOdm.Query.prototype.$divide=function(){return this.$queryOperator(arguments,function(t){for(var e=t.length>0?t[0]:0,o=1;o<t.length;o++)e/=t[o];return e})},jsonOdm.Query.prototype.$modulo=function(){return this.$queryOperator(arguments,function(t){for(var e=t.length>0?t[0]:0,o=1;o<t.length;o++)e%=t[o];return e})},jsonOdm.Query.prototype.$eq=function(){return this.$testCollection(arguments,function(t,e){for(var o=0;o<e.length;o++)if(e[o]==t)return!0;return!1})},jsonOdm.Query.prototype.$in=function(t){return this.$testCollection(t,function(t,e){for(var o=0;o<e.length;o++)if(e[o]==t)return!0;return!1})},jsonOdm.Query.prototype.$ne=function(){return this.$testCollection(arguments,function(t,e){for(var o=0;o<e.length;o++)if(e[o]==t)return!1;return!0})},jsonOdm.Query.prototype.$nin=function(t){return this.$testCollection(t,function(t,e){for(var o=0;o<e.length;o++)if(e[o]==t)return!1;return!0})},jsonOdm.Query.prototype.$gt=function(t){return this.$testCollection(t,function(t,e){return t>e})},jsonOdm.Query.prototype.$gte=function(t){return this.$testCollection(t,function(t,e){return t>=e})},jsonOdm.Query.prototype.$lt=function(t){return this.$testCollection(t,function(t,e){return e>t})},jsonOdm.Query.prototype.$lte=function(t){return this.$testCollection(t,function(t,e){return e>=t})},jsonOdm.Query.prototype.$isNull=function(){return this.$testCollection(null,function(t){return"undefined"==typeof t||null===t})},jsonOdm.Query.prototype.$exists=function(){return this.$testCollection(null,function(t){return"undefined"!=typeof t})},jsonOdm.Query.prototype.$type=function(){return this.$testCollection(arguments,function(t,e){return jsonOdm.util.is(t,e)})},jsonOdm.Query.prototype.$mod=function(){return this.$testCollection(arguments,function(t,e){return t%e[0]==e[1]})},jsonOdm.Query.prototype.$regex=function(t,e){return"string"==typeof t&&(t="string"==typeof e?new RegExp(t,e):new RegExp(t)),this.$testCollection(t,function(t,e){return e.test(t)})},jsonOdm.Query.prototype.$text=function(t){for(var e,o,n=/(^| )-([^ ]+)( |$)/g,r=/"([^"]+)"/g,i=[],s=[];null!==(e=n.exec(t));)i.push(e[2]);for(t=t.replace(n,"");null!==(o=r.exec(t));)s.push(o[1]);t=t.replace(r,"");var u=t.split(" ");return this.$testCollection([i,s,u],function(t,e){for(var o=0;o<e[0].length;o++)if(t.indexOf(e[0][o])>-1)return!1;for(o=0;o<e[1].length;o++)if(t.indexOf(e[1][o])<0)return!1;for(o=0;o<e[2].length;o++)if(t.indexOf(e[2][o])>-1)return!0;return!!e[1].length})},jsonOdm.Query.prototype.$where=function(t){return"string"==typeof t&&(t=new Function(t)),this.$testCollection(t,function(t,e){return"function"!=typeof e?!1:e.apply(t)})},jsonOdm.Query.prototype.$geoWithin=function(t){return this.$testCollection(jsonOdm.Geo.detectAsGeometry(t),function(t,e){return jsonOdm.Geo[t.type]&&jsonOdm.Geo[t.type].within&&jsonOdm.Geo[t.type].within(t,e)})},jsonOdm.Query.prototype.$geoIntersects=function(t){return this.$testCollection(jsonOdm.Geo.detectAsGeometry(t),function(t,e){return jsonOdm.Geo[t.type]&&jsonOdm.Geo[t.type].intersects&&jsonOdm.Geo[t.type].intersects(t,e)})},jsonOdm.Query.prototype.$and=function(){return this.$queryOperator(arguments,function(t){for(var e=0;e<t.length;e++)if(!t[e])return!1;return!0})},jsonOdm.Query.prototype.$nand=function(){return this.$queryOperator(arguments,function(t){for(var e=0;e<t.length;e++)if(!t[e])return!0;
return!1})},jsonOdm.Query.prototype.$not=jsonOdm.Query.prototype.$nand,jsonOdm.Query.prototype.$or=function(){return this.$queryOperator(arguments,function(t){for(var e=0;e<t.length;e++)if(t[e])return!0;return!1})},jsonOdm.Query.prototype.$nor=function(){return this.$queryOperator(arguments,function(t){for(var e=0;e<t.length;e++)if(t[e])return!1;return!0})};
"use strict";function JsonOdm(){var t=this;this.sources={},this.selectedSource={},this.addSource=function(e,n,o){"object"==typeof n&&("undefined"==typeof t.sources[e]&&(t.sources[e]=n),o&&(t.selectedSource=n))},this.selectSource=function(e){"undefined"!=typeof t.sources[e]&&(t.selectedSource=t.sources[e])}}var root="undefined"!=typeof window?window:global,odm=new JsonOdm;root.jsonOdm||(root.jsonOdm=odm),"undefined"!=typeof module&&module.exports&&(module.exports=odm),jsonOdm.Util=function(){},jsonOdm.Util.prototype.isArray=function(t){return Array.isArray?Array.isArray(t):"[object Array]"===Object.prototype.toString.call(t)},jsonOdm.Util.prototype.is=function(t,e){e="string"==typeof e?[e]:e;var n=Object.prototype.toString.call(t);n=n.substring(8,n.length-1).toLowerCase();for(var o=0;o<e.length;o++){var r=e[o].toLowerCase();if("array"==r&&this.isArray(t))return!0;if(r==n)return!0;if(typeof t==r)return!0}return!1},jsonOdm.Util.prototype.objectKeys=Object.keys||function(){var t=Object.prototype.hasOwnProperty,e=!{toString:null}.propertyIsEnumerable("toString"),n=["toString","toLocaleString","valueOf","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","constructor"],o=n.length;return function(r){if("object"!=typeof r&&("function"!=typeof r||null===r))throw new TypeError("Object.keys called on non-object");var i,s,u=[];for(i in r)t.call(r,i)&&u.push(i);if(e)for(s=0;o>s;s++)t.call(r,n[s])&&u.push(n[s]);return u}}(),jsonOdm.Util.prototype.branch=function(t,e){function n(){if(arguments&&arguments.length&&this){var t=this[arguments[0]];return t?n.apply(t,Array.prototype.slice.call(arguments,1)):t}return this}return n.apply(t,e)},jsonOdm.Util.prototype.projectElement=function(t,e,n){var o={};for(var r in t)t.hasOwnProperty(r)&&(1==t[r]?o[r]=e[r]:"function"==typeof t[r]?o[r]=t[r](n||e):t[r]instanceof jsonOdm.Query?(o[r]=t[r].$$commandQueue[t[r].$$commandQueue.length-1](e),t[r].$$accumulation!==!1&&(o[r]=t[r].$$accumulation)):"object"==typeof t[r]&&(o[r]=this.projectElement(t[r],e[r],n||e)));return o},jsonOdm.util=new jsonOdm.Util,jsonOdm.Geo=function(){},jsonOdm.Geo.detectAsGeometry=function(t){if(!t.type)if(jsonOdm.util.isArray(t)&&2===t.length&&!jsonOdm.util.isArray(t[0]))t=new jsonOdm.Geo.Point(t);else if(jsonOdm.util.isArray(t)&&4===t.length&&!jsonOdm.util.isArray(t[0]))t=new jsonOdm.Geo.BoundaryBox(t);else if(jsonOdm.util.isArray(t)&&t.length>=1&&jsonOdm.util.isArray(t[0])&&2===t[0].length&&!jsonOdm.util.isArray(t[0][0]))t=new jsonOdm.Geo.LineString(t);else if(jsonOdm.util.isArray(t)&&t.length>=1&&jsonOdm.util.isArray(t[0])&&t[0].length>=1&&jsonOdm.util.isArray(t[0][0])&&2===t[0][0].length&&!jsonOdm.util.isArray(t[0][0][0]))t=new jsonOdm.Geo.Polygon(t);else{if(!(jsonOdm.util.isArray(t)&&t.length>=1&&jsonOdm.util.isArray(t[0])&&t[0].length>=1&&jsonOdm.util.isArray(t[0][0])&&t[0][0].length>=1&&jsonOdm.util.isArray(t[0][0][0])&&2===t[0][0][0].length)||jsonOdm.util.isArray(t[0][0][0][0]))return!1;t=new jsonOdm.Geo.MultiPolygon(t)}return t},jsonOdm.Geo.FeatureCollection=function(t,e){this.type="FeatureCollection",this.features=t||[],e&&(this.bbox=e)},jsonOdm.Geo.Feature=function(t,e,n,o){this.geometry=t||{},e&&(this.properties=e),n&&(this.bbox=n),o&&(this.id=o)},jsonOdm.Geo.BoundaryBox=function(t){var e=Object.create(Array.prototype);return e=Array.apply(e)||e,jsonOdm.util.isArray(t)?(e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3]):(e[0]=0,e[1]=0,e[2]=0,e[3]=0),e},jsonOdm.Geo.BoundaryBox.within=function(t,e){return jsonOdm.util.isArray(t)&&4===t.length?jsonOdm.Geo.Polygon.within(new jsonOdm.Geo.Polygon([[[t[0],t[1]],[t[2],t[1]],[t[2],t[3]],[t[0],t[3]],[t[0],t[1]]]]),e):!1},jsonOdm.Geo.Point=function(t,e){this.type="Point",this.coordinates=t,e&&(this.bbox=e)},jsonOdm.Geo.Point.within=function(t,e){var n,o;if(!t.coordinates)return!1;if("Point"==e.type)return e.coordinates[0]==t.coordinates[0]&&e.coordinates[1]==t.coordinates[1];if("MultiPoint"==e.type||"LineString"==e.type){for(n=0;e.coordinates&&n<e.coordinates.length;n++)if(e.coordinates[n][0]==t.coordinates[0]&&e.coordinates[n][1]==t.coordinates[1])return!0;return!1}if("MultiLineString"==e.type){for(n=0;e.coordinates&&n<e.coordinates.length;n++)for(o=0;e.coordinates[n]&&o<e.coordinates[n].length;o++)if(e.coordinates[n][o][0]==t.coordinates[0]&&e.coordinates[n][o][1]==t.coordinates[1])return!0;return!1}if("Polygon"==e.type)return jsonOdm.Geo.pointWithinPolygon(t.coordinates,e.coordinates?e.coordinates[0]:null);if("MultiPolygon"==e.type){for(n=0;e.coordinates&&n<e.coordinates.length;n++)if(jsonOdm.Geo.pointWithinPolygon(t.coordinates,e.coordinates[n]?e.coordinates[n][0]:null))return!0;return!1}if("GeometryCollection"==e.type&&jsonOdm.util.isArray(e.geometries)){for(n=0;n<e.geometries.length;n++)if(jsonOdm.Geo.Point.within(t,e.geometries[n]))return!0;return!1}return jsonOdm.Geo.pointWithinBounds(t.coordinates,e)},jsonOdm.Geo.Point.intersects=jsonOdm.Geo.Point.within,jsonOdm.Geo.MultiPoint=function(t,e){this.type="MultiPoint",this.coordinates=t,e&&(this.bbox=e)},jsonOdm.Geo.MultiPoint.within=function(t,e){var n,o,r,i;if(!t.coordinates||!jsonOdm.util.isArray(t.coordinates))return!1;if("Point"==e.type)return 1==t.coordinates.length&&t.coordinates[0][0]==e.coordinates[0]&&t.coordinates[0][1]==e.coordinates[1];if("MultiPoint"==e.type){for(o=0;t.coordinates&&o<t.coordinates.length;o++){for(i=!1,n=0;e.coordinates&&n<e.coordinates.length;n++)if(e.coordinates[n][0]==t.coordinates[o][0]&&e.coordinates[n][1]==t.coordinates[o][1]){i=!0;break}if(!i)return!1}return!0}if("LineString"==e.type){for(r=0;t.coordinates&&r<t.coordinates.length;r++)if(!jsonOdm.Geo.pointWithinLineString(t.coordinates[r],e.coordinates))return!1;return!0}if("MultiLineString"==e.type){for(r=0;t.coordinates&&r<t.coordinates.length;r++){for(i=!1,n=0;e.coordinates&&n<e.coordinates.length;n++)if(jsonOdm.Geo.pointWithinLineString(t.coordinates[r],e.coordinates[n])){i=!0;break}if(!i)return!1}return!0}if("Polygon"==e.type){for(n=0;t.coordinates&&n<t.coordinates.length;n++)if(!jsonOdm.Geo.pointWithinPolygon(t.coordinates[n],e.coordinates?e.coordinates[0]:null))return!1;return!0}if("MultiPolygon"==e.type){for(o=0;t.coordinates&&o<t.coordinates.length;o++){for(i=!1,n=0;e.coordinates&&n<e.coordinates.length;n++)if(jsonOdm.Geo.pointWithinPolygon(t.coordinates[o],e.coordinates[n]?e.coordinates[n][0]:null)){i=!0;break}if(!i)return!1}return!0}if("GeometryCollection"==e.type&&jsonOdm.util.isArray(e.geometries)){for(n=0;n<e.geometries.length;n++)if(jsonOdm.Geo.MultiPoint.within(t,e.geometries[n]))return!0;return!1}for(n=0;n<t.coordinates.length;n++)if(!jsonOdm.Geo.pointWithinBounds(t.coordinates[n],e))return!1;return!0},jsonOdm.Geo.MultiPoint.intersects=function(t,e){var n,o,r;if(!t.coordinates||!jsonOdm.util.isArray(t.coordinates))return!1;if("Point"==e.type)return jsonOdm.Geo.Point.intersects(e,t);if("MultiPoint"==e.type){for(o=0;t.coordinates&&o<t.coordinates.length;o++)for(n=0;e.coordinates&&n<e.coordinates.length;n++)if(e.coordinates[n][0]==t.coordinates[o][0]&&e.coordinates[n][1]==t.coordinates[o][1])return!0;return!1}if("LineString"==e.type){for(r=0;t.coordinates&&r<t.coordinates.length;r++)if(jsonOdm.Geo.pointWithinLineString(t.coordinates[r],e.coordinates))return!0;return!1}if("MultiLineString"==e.type){for(r=0;t.coordinates&&r<t.coordinates.length;r++)for(n=0;e.coordinates&&n<e.coordinates.length;n++)if(jsonOdm.Geo.pointWithinLineString(t.coordinates[r],e.coordinates[n]))return!0;return!1}if("Polygon"==e.type){for(n=0;t.coordinates&&n<t.coordinates.length;n++)if(jsonOdm.Geo.pointWithinPolygon(t.coordinates[n],e.coordinates?e.coordinates[0]:null))return!0;return!1}if("MultiPolygon"==e.type){for(o=0;t.coordinates&&o<t.coordinates.length;o++)for(n=0;e.coordinates&&n<e.coordinates.length;n++)if(jsonOdm.Geo.pointWithinPolygon(t.coordinates[o],e.coordinates[n]?e.coordinates[n][0]:null))return!0;return!1}if("GeometryCollection"==e.type&&jsonOdm.util.isArray(e.geometries)){for(n=0;n<e.geometries.length;n++)if(jsonOdm.Geo.MultiPoint.intersects(t,e.geometries[n]))return!0;return!1}for(n=0;n<t.coordinates.length;n++)if(jsonOdm.Geo.pointWithinBounds(t.coordinates[n],e))return!0;return!1},jsonOdm.Geo.LineString=function(t,e){this.type="LineString",this.coordinates=t,e&&(this.bbox=e)},jsonOdm.Geo.LineString.within=function(t,e){var n,o;if(!t.coordinates||!jsonOdm.util.isArray(t.coordinates))return!1;if("Point"==e.type||"MultiPoint"==e.type)return!1;if("LineString"==e.type)return jsonOdm.Geo.lineStringWithinLineString(t.coordinates,e.coordinates);if("MultiLineString"==e.type){for(n=0;e.coordinates&&n<e.coordinates.length;n++)if(jsonOdm.Geo.lineStringWithinLineString(t.coordinates,e.coordinates[n]))return!0;return!1}if("Polygon"==e.type){for(n=0;t.coordinates&&n<t.coordinates.length-1;n++)if(!jsonOdm.Geo.edgeWithinPolygon([t.coordinates[n],t.coordinates[n+1]],e.coordinates[0]))return!1;return!0}if("MultiPolygon"==e.type){for(n=0;e.coordinates&&n<e.coordinates.length;n++)for(o=0;t.coordinates&&o<t.coordinates.length-1;o++)if(jsonOdm.Geo.edgeWithinPolygon([t.coordinates[o],t.coordinates[o+1]],e.coordinates[n][0])&&o+1==t.coordinates.length-1)return!0;return!1}if("GeometryCollection"==e.type&&jsonOdm.util.isArray(e.geometries)){for(n=0;n<e.geometries.length;n++)if(jsonOdm.Geo.LineString.within(t,e.geometries[n]))return!0;return!1}for(n=0;n<t.coordinates.length;n++)if(!jsonOdm.Geo.pointWithinBounds(t.coordinates[n],e))return!1;return!0},jsonOdm.Geo.LineString.intersects=function(t,e){var n,o;if(!t.coordinates||!jsonOdm.util.isArray(t.coordinates))return!1;if("Point"==e.type)return jsonOdm.Geo.Point.intersects(e,t);if("MultiPoint"==e.type)return jsonOdm.Geo.MultiPoint.intersects(e,t);if("LineString"==e.type){for(n=0;n<t.coordinates.length-1;n++)if(jsonOdm.Geo.edgeIntersectsLineString([t.coordinates[n],t.coordinates[n+1]],e.coordinates))return!0;return!1}if("MultiLineString"==e.type){for(n=0;e.coordinates&&n<e.coordinates.length;n++)for(o=0;o<t.coordinates.length-1;o++)if(jsonOdm.Geo.edgeIntersectsLineString([t.coordinates[o],t.coordinates[o+1]],e.coordinates[n]))return!0;return!1}if("Polygon"==e.type){for(n=0;t.coordinates&&n<t.coordinates.length-1;n++)if(jsonOdm.Geo.edgeIntersectsPolygon([t.coordinates[n],t.coordinates[n+1]],e.coordinates[0]))return!0;return!1}if("MultiPolygon"==e.type){for(n=0;e.coordinates&&n<e.coordinates.length;n++)for(o=0;t.coordinates&&o<t.coordinates.length-1;o++)if(jsonOdm.Geo.edgeIntersectsPolygon([t.coordinates[o],t.coordinates[o+1]],e.coordinates[n][0]))return!0;return!1}if("GeometryCollection"==e.type&&jsonOdm.util.isArray(e.geometries)){for(n=0;n<e.geometries.length;n++)if(jsonOdm.Geo.LineString.intersects(t,e.geometries[n]))return!0;return!1}for(n=0;t.coordinates&&n<t.coordinates.length-1;n++)if(jsonOdm.Geo.edgeIntersectsBounds([t.coordinates[n],t.coordinates[n+1]],e))return!0;return!1},jsonOdm.Geo.MultiLineString=function(t,e){this.type="MultiLineString",this.coordinates=t,e&&(this.bbox=e)},jsonOdm.Geo.MultiLineString.within=function(t,e){var n,o,r,i;if(!t.coordinates||!jsonOdm.util.isArray(t.coordinates))return!1;if("Point"==e.type||"MultiPoint"==e.type)return!1;if("LineString"==e.type){for(n=0;t.coordinates&&n<t.coordinates.length;n++)if(!jsonOdm.Geo.lineStringWithinLineString(t.coordinates[n],e.coordinates))return!1;return!0}if("MultiLineString"==e.type){for(o=0;t.coordinates&&o<t.coordinates.length;o++){for(i=!1,n=0;e.coordinates&&n<e.coordinates.length;n++)if(jsonOdm.Geo.lineStringWithinLineString(t.coordinates[o],e.coordinates[n])){i=!0;break}if(!i)return!1}return!0}if("Polygon"==e.type){for(n=0;t.coordinates&&n<t.coordinates.length;n++)for(o=0;t.coordinates&&o<t.coordinates[n].length-1;o++)if(!jsonOdm.Geo.edgeWithinPolygon([t.coordinates[n][o],t.coordinates[n][o+1]],e.coordinates[0]))return!1;return!0}if("MultiPolygon"==e.type){for(o=0;t.coordinates&&o<t.coordinates.length;o++){for(i=!1,n=0;e.coordinates&&n<e.coordinates.length;n++)for(r=0;t.coordinates[o]&&r<t.coordinates[o].length-1;r++)if(jsonOdm.Geo.edgeWithinPolygon([t.coordinates[o][r],t.coordinates[o][r+1]],e.coordinates[n][0])&&r+1==t.coordinates[o].length-1){i=!0;break}if(!i)return!1}return!0}if("GeometryCollection"==e.type&&jsonOdm.util.isArray(e.geometries)){for(n=0;n<e.geometries.length;n++)if(jsonOdm.Geo.MultiLineString.within(t,e.geometries[n]))return!0;return!1}for(n=0;n<t.coordinates.length;n++)for(o=0;o<t.coordinates[n].length;o++)if(!jsonOdm.Geo.pointWithinBounds(t.coordinates[n][o],e))return!1;return!0},jsonOdm.Geo.MultiLineString.intersects=function(t,e){var n,o,r;if(!t.coordinates||!jsonOdm.util.isArray(t.coordinates))return!1;if("Point"==e.type)return jsonOdm.Geo.Point.intersects(e,t);if("MultiPoint"==e.type)return jsonOdm.Geo.MultiPoint.intersects(e,t);if("LineString"==e.type)return jsonOdm.Geo.LineString.intersects(e,t);if("MultiLineString"==e.type){for(o=0;t.coordinates&&o<t.coordinates.length;o++)for(r=0;t.coordinates[o]&&r<t.coordinates[o].length-1;r++)for(n=0;e.coordinates&&n<e.coordinates.length;n++)if(jsonOdm.Geo.edgeIntersectsLineString([t.coordinates[o][r],t.coordinates[o][r+1]],e.coordinates[n]))return!0;return!1}if("Polygon"==e.type){for(n=0;t.coordinates&&n<t.coordinates.length;n++)for(o=0;t.coordinates&&o<t.coordinates[n].length-1;o++)if(jsonOdm.Geo.edgeIntersectsPolygon([t.coordinates[n][o],t.coordinates[n][o+1]],e.coordinates[0]))return!0;return!1}if("MultiPolygon"==e.type){for(o=0;t.coordinates&&o<t.coordinates.length;o++)for(n=0;e.coordinates&&n<e.coordinates.length;n++)for(r=0;t.coordinates[o]&&r<t.coordinates[o].length-1;r++)if(jsonOdm.Geo.edgeIntersectsPolygon([t.coordinates[o][r],t.coordinates[o][r+1]],e.coordinates[n][0]))return!0;return!1}if("GeometryCollection"==e.type&&jsonOdm.util.isArray(e.geometries)){for(n=0;n<e.geometries.length;n++)if(jsonOdm.Geo.MultiLineString.intersects(t,e.geometries[n]))return!0;return!1}for(n=0;t.coordinates&&n<t.coordinates.length;n++)for(o=0;o<t.coordinates[n].length-1;o++)if(jsonOdm.Geo.edgeIntersectsBounds([t.coordinates[n][o],t.coordinates[n][o+1]],e))return!0;return!1},jsonOdm.Geo.Polygon=function(t,e){this.type="Polygon",this.coordinates=t,e&&(this.bbox=e)},jsonOdm.Geo.Polygon.within=function(t,e){var n,o;if(!t.coordinates||!jsonOdm.util.isArray(t.coordinates))return!1;if("Point"==e.type||"MultiPoint"==e.type||"LineString"==e.type||"MultiLineString"==e.type)return!1;if("Polygon"==e.type){for(n=0;t.coordinates[0]&&n<t.coordinates[0].length-1;n++)if(!jsonOdm.Geo.edgeWithinPolygon([t.coordinates[0][n],t.coordinates[0][n+1]],e.coordinates[0]))return!1;return!0}if("MultiPolygon"==e.type){for(n=0;e.coordinates&&n<e.coordinates.length;n++)for(o=0;t.coordinates[0]&&o<t.coordinates[0].length-1;o++){var r=jsonOdm.Geo.edgeWithinPolygon([t.coordinates[0][o],t.coordinates[0][o+1]],e.coordinates[n][0]);if(!r)break;if(r&&o+1==t.coordinates[0].length-1)return!0}return!1}if("GeometryCollection"==e.type&&jsonOdm.util.isArray(e.geometries)){for(n=0;n<e.geometries.length;n++)if(jsonOdm.Geo.Polygon.within(t,e.geometries[n]))return!0;return!1}for(n=0;t.coordinates[0]&&n<t.coordinates[0].length;n++)if(!jsonOdm.Geo.pointWithinBounds(t.coordinates[0][n],e))return!1;return!0},jsonOdm.Geo.Polygon.intersects=function(t,e){var n,o;if(!t.coordinates||!jsonOdm.util.isArray(t.coordinates))return!1;if("Point"==e.type)return jsonOdm.Geo.Point.intersects(e,t);if("MultiPoint"==e.type)return jsonOdm.Geo.MultiPoint.intersects(e,t);if("LineString"==e.type)return jsonOdm.Geo.LineString.intersects(e,t);if("MultiLineString"==e.type)return jsonOdm.Geo.MultiLineString.intersects(e,t);if("Polygon"==e.type){for(n=0;t.coordinates[0]&&n<t.coordinates[0].length-1;n++)if(jsonOdm.Geo.edgeIntersectsPolygon([t.coordinates[0][n],t.coordinates[0][n+1]],e.coordinates[0]))return!0;return!1}if("MultiPolygon"==e.type){for(n=0;e.coordinates&&n<e.coordinates.length;n++)for(o=0;t.coordinates[0]&&o<t.coordinates[0].length-1;o++)if(jsonOdm.Geo.edgeIntersectsPolygon([t.coordinates[0][o],t.coordinates[0][o+1]],e.coordinates[n][0]))return!0;return!1}if("GeometryCollection"==e.type&&jsonOdm.util.isArray(e.geometries)){for(n=0;n<e.geometries.length;n++)if(jsonOdm.Geo.Polygon.intersects(t,e.geometries[n]))return!0;return!1}for(n=0;t.coordinates[0]&&n<t.coordinates[0].length-1;n++)if(jsonOdm.Geo.edgeIntersectsBounds([t.coordinates[0][n],t.coordinates[0][n+1]],e))return!0;return!1},jsonOdm.Geo.MultiPolygon=function(t,e){this.type="MultiPolygon",this.coordinates=t,e&&(this.bbox=e)},jsonOdm.Geo.MultiPolygon.within=function(t,e){var n,o,r,i;if(!t.coordinates||!jsonOdm.util.isArray(t.coordinates))return!1;if("Point"==e.type||"MultiPoint"==e.type||"LineString"==e.type||"MultiLineString"==e.type)return!1;if("Polygon"==e.type){for(n=0;t.coordinates&&n<t.coordinates.length;n++)for(o=0;o<t.coordinates[n][0].length-1;o++)if(!jsonOdm.Geo.edgeWithinPolygon([t.coordinates[n][0][o],t.coordinates[n][0][o+1]],e.coordinates[0]))return!1;return!0}if("MultiPolygon"==e.type){for(n=0;t.coordinates&&n<t.coordinates.length;n++){for(i=!1,o=0;e.coordinates&&o<e.coordinates.length;o++)for(r=0;t.coordinates[n][0]&&r<t.coordinates[n][0].length-1;r++){var s=jsonOdm.Geo.edgeWithinPolygon([t.coordinates[n][0][r],t.coordinates[n][0][r+1]],e.coordinates[o][0]);if(!s)break;if(s&&r+1==t.coordinates[n][0].length-1){i=!0;break}}if(!i)return!1}return!0}if("GeometryCollection"==e.type&&jsonOdm.util.isArray(e.geometries)){for(n=0;n<e.geometries.length;n++)if(jsonOdm.Geo.MultiPolygon.within(t,e.geometries[n]))return!0;return!1}for(n=0;n<t.coordinates.length;n++)for(o=0;o<t.coordinates[n][0].length;o++)if(!jsonOdm.Geo.pointWithinBounds(t.coordinates[n][0][o],e))return!1;return!0},jsonOdm.Geo.MultiPolygon.intersects=function(t,e){var n,o,r;if(!t.coordinates||!jsonOdm.util.isArray(t.coordinates))return!1;if("Point"==e.type)return jsonOdm.Geo.Point.intersects(e,t);if("MultiPoint"==e.type)return jsonOdm.Geo.MultiPoint.intersects(e,t);if("LineString"==e.type)return jsonOdm.Geo.LineString.intersects(e,t);if("MultiLineString"==e.type)return jsonOdm.Geo.MultiLineString.intersects(e,t);if("Polygon"==e.type)return jsonOdm.Geo.Polygon.intersects(e,t);if("MultiPolygon"==e.type){for(n=0;t.coordinates&&n<t.coordinates.length;n++)for(o=0;e.coordinates&&o<e.coordinates.length;o++)for(r=0;t.coordinates[n][0]&&r<t.coordinates[n][0].length-1;r++)if(jsonOdm.Geo.pointWithinPolygon(t.coordinates[n][0][r],e.coordinates[o][0]))return!0;return!1}if("GeometryCollection"==e.type&&jsonOdm.util.isArray(e.geometries)){for(n=0;n<e.geometries.length;n++)if(jsonOdm.Geo.MultiPolygon.intersects(t,e.geometries[n]))return!0;return!1}for(n=0;n<t.coordinates.length;n++)for(o=0;o<t.coordinates[n][0].length-1;o++)if(jsonOdm.Geo.edgeIntersectsBounds([t.coordinates[n][0][o],t.coordinates[n][0][o+1]],e))return!0;return!1},jsonOdm.Geo.GeometryCollection=function(t,e){this.type="GeometryCollection",this.geometries=t,e&&(this.bbox=e)},jsonOdm.Geo.GeometryCollection.within=function(t,e){if(!jsonOdm.util.isArray(t.geometries)||!t.geometries.length||!e.type)return!1;for(var n=0;n<t.geometries.length;n++){if(!jsonOdm.Geo[t.geometries[n].type]||!jsonOdm.Geo[t.geometries[n].type].within)return!1;if(!jsonOdm.Geo[t.geometries[n].type].within(t.geometries[n],e))return!1}return!0},jsonOdm.Geo.GeometryCollection.intersects=function(t,e){if(!jsonOdm.util.isArray(t.geometries)||!t.geometries.length||!e.type)return!1;for(var n=0;n<t.geometries.length;n++)if(jsonOdm.Geo[t.geometries[n].type]&&jsonOdm.Geo[t.geometries[n].type].intersects&&jsonOdm.Geo[t.geometries[n].type].intersects(t.geometries[n],e))return!0;return!1},jsonOdm.Geo.pointWithinPolygon=function(t,e){if(!(jsonOdm.util.isArray(t)&&jsonOdm.util.isArray(e)&&e.length>2))return!1;var n,o=0;(e[0][0]!=e[e.length-1][0]||e[0][1]!=e[e.length-1][1])&&(e=e.concat([e[0]]));for(var r=0;r<e.length-1;r++){if(e[r][0]==t[0]&&e[r][1]==t[1])return!0;if(!(e[r][0]<t[0]&&e[r+1][0]<t[0]||e[r][1]<t[1]&&e[r+1][1]<t[1]||e[r][1]>t[1]&&e[r+1][1]>t[1])){if(n=(e[r][0]-e[r+1][0])*((t[1]-e[r+1][1])/(e[r][1]-e[r+1][1]))+e[r+1][0],n==t[0]&&t[1]<=Math.max(e[r][1],e[r+1][1])&&t[1]>=Math.min(e[r][1],e[r+1][1]))return!0;n>t[0]&&o++}}return o%2==1},jsonOdm.Geo.edgeWithinPolygon=function(t,e){if(!(jsonOdm.util.isArray(t)&&2==t.length&&jsonOdm.util.isArray(e)&&e.length>=2))return!1;if((e[0][0]!=e[e.length-1][0]||e[0][1]!=e[e.length-1][1])&&(e=e.concat([e[0]])),!jsonOdm.Geo.pointWithinPolygon(t[0],e)||!jsonOdm.Geo.pointWithinPolygon(t[1],e))return!1;for(var n=0;n<e.length-1;n++)if(jsonOdm.Geo.edgeIntersectsEdge(t,[e[n],e[n+1]],!1))return!1;return!0},jsonOdm.Geo.edgeIntersectsPolygon=function(t,e){if(!(jsonOdm.util.isArray(t)&&2==t.length&&jsonOdm.util.isArray(e)&&e.length>=2))return!1;if((e[0][0]!=e[e.length-1][0]||e[0][1]!=e[e.length-1][1])&&(e=e.concat([e[0]])),jsonOdm.Geo.pointWithinPolygon(t[0],e)||jsonOdm.Geo.pointWithinPolygon(t[1],e))return!0;for(var n=0;n<e.length-1;n++)if(jsonOdm.Geo.edgeIntersectsEdge(t,[e[n],e[n+1]]))return!0;return!1},jsonOdm.Geo.edgeIntersectsLineString=function(t,e){if(!jsonOdm.util.isArray(t)||2!=t.length||!jsonOdm.util.isArray(e))return!1;for(var n=0;n<e.length-1;n++)if(jsonOdm.Geo.edgeIntersectsEdge(t,[e[n],e[n+1]]))return!0;return!1},jsonOdm.Geo.edgeIntersectsEdge=function(t,e,n){n="undefined"==typeof n?!0:n;var o=[t[1][0]-t[0][0],t[1][1]-t[0][1]],r=[Math.min(t[0][0],t[1][0]),Math.min(t[0][1],t[1][1]),Math.max(t[0][0],t[1][0]),Math.max(t[0][1],t[1][1])],i=[e[1][0]-e[0][0],e[1][1]-e[0][1]],s=[Math.min(e[0][0],e[1][0]),Math.min(e[0][1],e[1][1]),Math.max(e[0][0],e[1][0]),Math.max(e[0][1],e[1][1])];if(r[0]>s[0]&&r[0]>s[2]||r[1]>s[1]&&r[1]>s[3]||s[0]>r[0]&&s[0]>r[2]||s[1]>r[1]&&s[1]>r[3])return!1;if(i[0]*o[1]-o[0]*i[1]==0)return n&&t[0][1]+(e[0][0]-t[0][0])/o[0]*o[1]==e[0][1];var u=(e[0][1]*i[0]+t[0][0]*i[1]-e[0][0]*i[1]-t[0][1]*i[0])/(o[1]*i[0]-o[0]*i[1]),c=t[0][0]+u*o[0],d=t[0][1]+u*o[1];return n?c>=r[0]&&c<=r[2]&&d>=r[1]&&d<=r[3]&&c>=s[0]&&c<=s[2]&&d>=s[1]&&d<=s[3]:c>r[0]&&c<r[2]&&d>r[1]&&d<r[3]&&c>s[0]&&c<s[2]&&d>s[1]&&d<s[3]},jsonOdm.Geo.pointWithinLineString=function(t,e){if(!(jsonOdm.util.isArray(t)&&jsonOdm.util.isArray(e)&&e.length>=2))return!1;for(var n=0;n<e.length-1;n++)if((t[0]>=e[n][0]&&t[0]<=e[n+1][0]&&e[n][0]<=e[n+1][0]||t[0]<=e[n][0]&&t[0]>=e[n+1][0]&&e[n][0]>=e[n+1][0])&&(t[1]>=e[n][1]&&t[1]<=e[n+1][1]&&e[n][1]<=e[n+1][1]||t[1]<=e[n][1]&&t[1]>=e[n+1][1]&&e[n][1]>=e[n+1][1])&&(e[n][0]==t[0]&&e[n][1]==t[1]||e[n+1][0]==t[0]&&e[n+1][1]==t[1]||e[n][1]-e[n+1][1]!=0&&(e[n][0]-e[n+1][0])*((t[1]-e[n+1][1])/(e[n][1]-e[n+1][1]))+e[n+1][0]==t[0]||e[n][0]-e[n+1][0]!=0&&(e[n][1]-e[n+1][1])*((t[0]-e[n+1][0])/(e[n][0]-e[n+1][0]))+e[n+1][1]==t[1]))return!0;return!1},jsonOdm.Geo.pointWithinBounds=function(t,e){return jsonOdm.util.isArray(t)&&jsonOdm.util.isArray(e)&&4==e.length?t[0]>=e[0]&&t[1]>=e[1]&&t[0]<=e[2]&&t[1]<=e[3]:!1},jsonOdm.Geo.edgeIntersectsBounds=function(t,e){return jsonOdm.util.isArray(t)&&jsonOdm.util.isArray(e)&&4==e.length?jsonOdm.Geo.edgeIntersectsPolygon(t,[[e[0],e[1]],[e[2],e[1]],[e[2],e[3]],[e[0],e[3]]]):!1},jsonOdm.Geo.lineStringWithinLineString=function(t,e){if(!jsonOdm.util.isArray(t)||!jsonOdm.util.isArray(e))return!1;var n,o;for(n=0;t&&n<t.length;n++){var r=!1;for(o=0;e&&o<e.length;o++)if(t[n][0]==e[o][0]&&t[n][1]==e[o][1]){if(n+1==t.length)return!0;if(!(e[o+1]&&t[n+1][0]==e[o+1][0]&&t[n+1][1]==e[o+1][1]||t[n+1][0]==e[o][0]&&t[n+1][1]==e[o][1]||o>0&&t[n+1][0]==e[o-1][0]&&t[n+1][1]==e[o-1][1]))return!1;r=!0}if(!r)return!1}return!0},jsonOdm.Collection=function(t){var e=Object.create(Array.prototype);return e=Array.apply(e)||e,"undefined"!=typeof t&&jsonOdm.selectedSource&&jsonOdm.selectedSource[t]&&(e=e.concat(jsonOdm.selectedSource[t])),jsonOdm.Collection.decorate(e),e.$branch=function(){var t=jsonOdm.util.branch(e,arguments);return jsonOdm.Collection.decorate(t),t},e},jsonOdm.Collection.decorate=function(t){var e=function(t){jsonOdm.util.isArray(t)&&(t.$hasMany=function(e,n,o,r){"string"==typeof o&&(r=r||o);var i=o;"string"==typeof o&&jsonOdm.selectedSource&&jsonOdm.selectedSource[o]&&(i=jsonOdm.selectedSource[o]);for(var s=0;s<t.length;s++){var u=e;if(t[s].hasOwnProperty(e)&&(u=t[s][e]),"undefined"==typeof t[s][r])for(var c=0;u.length&&c<u.length;c++){for(var d=null,a=0;a<i.length;a++)if(u[c]==i[a][n]){d=i[a];break}null!=d&&(t[s][r]||(t[s][r]=[]),t[s][r].push(d))}}},t.$hasOne=function(e,n,o,r){"string"==typeof o&&(r=r||o);var i=o;"string"==typeof o&&jsonOdm.selectedSource&&jsonOdm.selectedSource[o]&&(i=jsonOdm.selectedSource[o]);for(var s=0;s<t.length;s++){var u;if(t[s].hasOwnProperty(e)&&(u=t[s][e]),"undefined"==typeof t[s][r]){for(var c=null,d=0;d<i.length;d++)if(u==i[d][n]){c=i[d];break}null!=c&&(t[s][r]=c)}}},t.$query=function(){return new jsonOdm.Query(t)})};e(t)},jsonOdm.Query=function(t){this.$$commandQueue=[],this.$$aggregationBeforeCollectQueue=[],this.$$aggregationResultQueue=[],this.$$collection=t||[],this.$$accumulation=!1},jsonOdm.Query.prototype.$delete=function(){if(this.$$commandQueue.length<1)return this;for(var t=0;t<this.$$collection.length;){for(var e=!0,n=0;n<this.$$commandQueue.length&&(e=e&&this.$$commandQueue[n](this.$$collection[t]));n++);e?this.$$collection.splice(t,1):t++}return this},jsonOdm.Query.prototype.$result=function(t,e){if(this.$$commandQueue.length<1&&this.$$aggregationBeforeCollectQueue<1)return this.$$collection;t="undefined"==typeof t?0:t,e="undefined"==typeof e?this.$$collection.length:e;var n,o,r,i=new jsonOdm.Collection;for(o=0;o<this.$$collection.length;o++){var s=!0;for(r=0;r<this.$$commandQueue.length;r++){var u=this.$$commandQueue[r](this.$$collection[o]);if(!(s=s&&null!==u&&u!==!1&&"undefined"!=typeof u))break}if(s){if(t>0){t--;continue}if(0>=e)return i;for(n=this.$$collection[o],r=0;r<this.$$aggregationBeforeCollectQueue.length;r++)n=this.$$aggregationBeforeCollectQueue[r](o,n);i.push(n),e--}}for(o=0;o<this.$$aggregationResultQueue.length;o++)i=this.$$aggregationResultQueue[o](i);return i},jsonOdm.Query.prototype.$all=function(){return this.$result()},jsonOdm.Query.prototype.$first=function(){return this.$result(0,1)[0]},jsonOdm.Query.prototype.$aggregateCollection=function(t,e,n){return"function"==typeof t&&(t=[t]),"function"==typeof e&&(e=[e]),"function"==typeof n&&(n=[n]),jsonOdm.util.isArray(t)&&(this.$$commandQueue=this.$$commandQueue.concat(t)),jsonOdm.util.isArray(e)&&(this.$$aggregationBeforeCollectQueue=this.$$aggregationBeforeCollectQueue.concat(e)),jsonOdm.util.isArray(n)&&(this.$$aggregationResultQueue=this.$$aggregationResultQueue.concat(n)),this},jsonOdm.Query.prototype.$group=function(){var t=arguments,e=!1,n=[];return arguments.length>1&&!jsonOdm.util.isArray(arguments[arguments.length-1])&&!jsonOdm.util.is(arguments[arguments.length-1],"string")&&"object"==typeof arguments[arguments.length-1]&&(e=arguments[arguments.length-1],t=Array.prototype.slice.call(arguments,0,arguments.length-1)),this.$aggregateCollection(function(t,e){var n={};return function(o){for(var r,i={},s=!1,u=n,c=0;c<t.length;c++){var d=jsonOdm.util.isArray(t[c])?t[c]:[t[c]];r=jsonOdm.util.branch(o,d),c<t.length-1&&("undefined"==typeof u[""+r]&&(s=!0,u[""+r]={}),u=u[""+r]);for(var a=i,l=0;l<d.length-1;l++)"undefined"==typeof a[d[l]]&&(a[d[l]]={}),a=a[d[l]];a[d[d.length-1]]=r}return u[""+r]||(u[""+r]={accumulationObject:i,subResultSet:[]},e.push(u[""+r])),u[""+r].subResultSet.push(o),!0}}(t,n),null,function(t,e){function n(t){for(var e in t)t.hasOwnProperty(e)&&(t[e]instanceof jsonOdm.Query&&(t[e].$$accumulation=!1),"object"==typeof t[e]&&n(t[e]))}return function(){for(var o=new jsonOdm.Collection,r=0;r<t.length;r++)if(e===!1)o.push(t[r].accumulationObject);else{n(e);for(var i={},s=0;s<t[r].subResultSet.length;s++)i=jsonOdm.util.projectElement(e,t[r].subResultSet[s]);for(s in t[r].accumulationObject)t[r].accumulationObject.hasOwnProperty(s)&&(i[s]=t[r].accumulationObject[s]);o.push(i)}return o}}(n,e))},jsonOdm.Query.prototype.$project=function(t){return this.$aggregateCollection(null,function(e,n){return jsonOdm.util.projectElement(t,n)})},jsonOdm.Query.prototype.$testCollection=function(t,e){var n=this.$$commandQueue.pop(),o=function(){return function(o){if(!(n instanceof jsonOdm.Collection||"function"==typeof n||"undefined"==typeof n)||"function"!=typeof e)return!1;var r="undefined"==typeof n?o:n instanceof jsonOdm.Collection?n:n(o);return!!e(r,t)}}();return this.$$commandQueue.push(o),this},jsonOdm.Query.prototype.$queryOperator=function(t,e){var n=function(t,n){return function(o){if("function"!=typeof n)return!1;for(var r=[],i=0;i<t.length;i++)if(t[i]instanceof jsonOdm.Query)for(var s=0;s<t[i].$$commandQueue.length;s++)r.push(t[i].$$commandQueue[s](o));else r.push(t[i]);return e(r)}}(t,e),o=new jsonOdm.Query(this.$$collection);return o.$$commandQueue.push(n),o},jsonOdm.Query.prototype.$branch=function(){var t=function(t){return function(e){return jsonOdm.util.branch(e,t)}}(arguments),e=new jsonOdm.Query(this.$$collection);return e.$$commandQueue.push(t),e},jsonOdm.Query.prototype.$modifyField=function(t){var e=function(t,e){return function(n){return n=null!==e?e(n):n,"function"==typeof t?t(n):n}}(t,this.$$commandQueue.length?this.$$commandQueue[this.$$commandQueue.length-1]:null);return this.$$commandQueue.push(e),this},jsonOdm.Query.stringFiledModifyer=["charAt","charCodeAt","concat","fromCharCode","indexOf","lastIndexOf","localeCompare","match","replace","search","slice","split","substr","substring","toLocaleLowerCase","toLocaleUpperCase","toLowerCase","toUpperCase","trim","valueOf"];for(var i=0;i<jsonOdm.Query.stringFiledModifyer.length;i++)jsonOdm.Query.prototype["$"+jsonOdm.Query.stringFiledModifyer[i]]=function(t){return function(){return this.$modifyField(function(t,e){return function(n){return"string"==typeof n&&String.prototype.hasOwnProperty(e)?String.prototype[e].apply(n,t):n}}(arguments,t))}}(jsonOdm.Query.stringFiledModifyer[i]);jsonOdm.Query.prototype.$accumulator=function(t,e){t="string"==typeof t?[t]:t;var n=new jsonOdm.Query(this.$$collection),o=function(t,e,n,o){return function(r){var i=null!==t?jsonOdm.util.branch(r,t):t;return n.$$accumulation=e(i,n.$$accumulation,r),o.$$accumulation=n.$$accumulation,i}}(t,e,n,this);return n.$$commandQueue.push(o),n},jsonOdm.Query.prototype.$sum=function(t){return this.$accumulator(t,function(t,e){return e===!1&&(e=0),t+e})},jsonOdm.Query.prototype.$avg=function(t){var e,n;return this.$accumulator(t,function(t,o){return o===!1&&(e=0,n=0),n+=t,e++,n/e})},jsonOdm.Query.prototype.$max=function(t){return this.$accumulator(t,function(t,e){return e===!1&&(e=t),Math.max(t,e)})},jsonOdm.Query.prototype.$min=function(t){return this.$accumulator(t,function(t,e){return e===!1&&(e=t),Math.min(t,e)})},jsonOdm.Query.prototype.$count=function(){return this.$accumulator(null,function(t,e){return e===!1&&(e=0),++e})},jsonOdm.Query.prototype.$push=function(){var t=new jsonOdm.Query(this.$$collection),e=function(t,e){return function(n){return t.$$accumulation=t.$$accumulation===!1?[]:t.$$accumulation,t.$$accumulation.push(n),e.$$accumulation=t.$$accumulation,!0}}(t,this);return t.$$commandQueue.push(e),t},jsonOdm.Query.prototype.$add=function(){return this.$queryOperator(arguments,function(t){for(var e=t.length>0?t[0]:0,n=1;n<t.length;n++)e+=t[n];return e})},jsonOdm.Query.prototype.$subtract=function(){return this.$queryOperator(arguments,function(t){for(var e=t.length>0?t[0]:0,n=1;n<t.length;n++)e-=t[n];return e})},jsonOdm.Query.prototype.$multiply=function(){return this.$queryOperator(arguments,function(t){for(var e=t.length>0?t[0]:0,n=1;n<t.length;n++)e*=t[n];return e})},jsonOdm.Query.prototype.$divide=function(){return this.$queryOperator(arguments,function(t){for(var e=t.length>0?t[0]:0,n=1;n<t.length;n++)e/=t[n];return e})},jsonOdm.Query.prototype.$modulo=function(){return this.$queryOperator(arguments,function(t){for(var e=t.length>0?t[0]:0,n=1;n<t.length;n++)e%=t[n];return e})},jsonOdm.Query.prototype.$eq=function(){return this.$testCollection(arguments,function(t,e){for(var n=0;n<e.length;n++)if(e[n]===t)return!0;return!1})},jsonOdm.Query.prototype.$in=function(t){return this.$testCollection(t,function(t,e){for(var n=0;n<e.length;n++)if(e[n]===t)return!0;return!1
})},jsonOdm.Query.prototype.$ne=function(){return this.$testCollection(arguments,function(t,e){for(var n=0;n<e.length;n++)if(e[n]===t)return!1;return!0})},jsonOdm.Query.prototype.$nin=function(t){return this.$testCollection(t,function(t,e){for(var n=0;n<e.length;n++)if(e[n]===t)return!1;return!0})},jsonOdm.Query.prototype.$gt=function(t){return this.$testCollection(t,function(t,e){return t>e})},jsonOdm.Query.prototype.$gte=function(t){return this.$testCollection(t,function(t,e){return t>=e})},jsonOdm.Query.prototype.$lt=function(t){return this.$testCollection(t,function(t,e){return e>t})},jsonOdm.Query.prototype.$lte=function(t){return this.$testCollection(t,function(t,e){return e>=t})},jsonOdm.Query.prototype.$isNull=function(){return this.$testCollection(null,function(t){return"undefined"==typeof t||null===t})},jsonOdm.Query.prototype.$exists=function(){return this.$testCollection(null,function(t){return"undefined"!=typeof t})},jsonOdm.Query.prototype.$type=function(){return this.$testCollection(arguments,function(t,e){return jsonOdm.util.is(t,e)})},jsonOdm.Query.prototype.$mod=function(){return this.$testCollection(arguments,function(t,e){return t%e[0]===e[1]})},jsonOdm.Query.prototype.$regex=function(t,e){return"string"==typeof t&&(t="string"==typeof e?new RegExp(t,e):new RegExp(t)),this.$testCollection(t,function(t,e){return e.test(t)})},jsonOdm.Query.prototype.$text=function(t){for(var e,n,o=/(^| )-([^ ]+)( |$)/g,r=/"([^"]+)"/g,i=[],s=[];null!==(e=o.exec(t));)i.push(e[2]);for(t=t.replace(o,"");null!==(n=r.exec(t));)s.push(n[1]);t=t.replace(r,"");var u=t.split(" ");return this.$testCollection([i,s,u],function(t,e){for(var n=0;n<e[0].length;n++)if(t.indexOf(e[0][n])>-1)return!1;for(n=0;n<e[1].length;n++)if(t.indexOf(e[1][n])<0)return!1;for(n=0;n<e[2].length;n++)if(t.indexOf(e[2][n])>-1)return!0;return!!e[1].length})},jsonOdm.Query.prototype.$where=function(t){return"string"==typeof t&&(t=new Function(t)),this.$testCollection(t,function(t,e){return"function"!=typeof e?!1:e.apply(t)})},jsonOdm.Query.prototype.$geoWithin=function(t){return this.$testCollection(jsonOdm.Geo.detectAsGeometry(t),function(t,e){return jsonOdm.Geo[t.type]&&jsonOdm.Geo[t.type].within&&jsonOdm.Geo[t.type].within(t,e)})},jsonOdm.Query.prototype.$geoIntersects=function(t){return this.$testCollection(jsonOdm.Geo.detectAsGeometry(t),function(t,e){return jsonOdm.Geo[t.type]&&jsonOdm.Geo[t.type].intersects&&jsonOdm.Geo[t.type].intersects(t,e)})},jsonOdm.Query.prototype.$and=function(){return this.$queryOperator(arguments,function(t){for(var e=0;e<t.length;e++)if(!t[e])return!1;return!0})},jsonOdm.Query.prototype.$nand=function(){return this.$queryOperator(arguments,function(t){for(var e=0;e<t.length;e++)if(!t[e])return!0;return!1})},jsonOdm.Query.prototype.$not=jsonOdm.Query.prototype.$nand,jsonOdm.Query.prototype.$or=function(){return this.$queryOperator(arguments,function(t){for(var e=0;e<t.length;e++)if(t[e])return!0;return!1})},jsonOdm.Query.prototype.$nor=function(){return this.$queryOperator(arguments,function(t){for(var e=0;e<t.length;e++)if(t[e])return!1;return!0})};

@@ -61,3 +61,3 @@ "use strict";

description:"A light weight but fast object document mapper for JavaScript objects.",
version:"0.1.5"
version:"0.2.0"
}, "jsonOdm"))

@@ -64,0 +64,0 @@ .pipe(jsdoc.generator('./doc',

@@ -42,4 +42,8 @@ // Karma configuration

coverageReporter: {
type : 'html',
dir : 'doc/coverage/'
dir: 'doc/coverage/',
reporters: [
// reporters not supporting the `file` property
{ type: 'html', subdir: 'report-html' },
{ type: 'lcovonly', subdir: '.', file: 'lcov.info' }
]
},

@@ -46,0 +50,0 @@

{
"name": "json-odm",
"version": "0.1.5",
"version": "0.2.0",
"description": "Object document mapper for JSON data that provides mongodb methods for querying and transformation as well as additional joining that is not provided by mongodb. >> IF YOU LIKE IT, PLEASE GIVE IT A STAR ON GITHUB <<",

@@ -30,3 +30,4 @@ "main": " ./bin/json.odm.min.js",

"scripts": {
"build": "gulp build"
"build": "gulp build",
"test": "gulp"
},

@@ -33,0 +34,0 @@ "repository": {

@@ -0,1 +1,2 @@

[![Build Status](https://travis-ci.org/konsultaner/jsonOdm.svg?branch=master)](https://travis-ci.org/konsultaner/jsonOdm)
[![npm](https://img.shields.io/npm/dm/json-odm.svg)](https://www.npmjs.com/package/json-odm)

@@ -24,3 +25,3 @@ [![npm](https://img.shields.io/npm/v/json-odm.svg)](https://www.npmjs.com/package/json-odm)

----
You can find the [documentation here](https://rawgit.com/konsultaner/jsonOdm/master/doc/jsonOdm/0.1/index.html) or compiled to the folder [/doc/jsonOdm/0.1/*](https://github.com/konsultaner/jsonOdm/blob/master/doc/jsonOdm/0.1/index.html).
You can find the [documentation here](https://rawgit.com/konsultaner/jsonOdm/master/doc/jsonOdm/0.2/index.html) or compiled to the folder [/doc/jsonOdm/0.2/*](https://github.com/konsultaner/jsonOdm/blob/master/doc/jsonOdm/0.2/index.html).

@@ -38,3 +39,4 @@ Road map

- Aggregation
- Pipeline (~~$project~~,$match,$redact,~~$limit~~,~~$skip~~,$unwind,$group,$sort,$geoNear,$out) 30% ($limit and $skip is implemented as $result(skip,limit))
- Pipeline (~~$project~~,$match,$redact,~~$limit~~,~~$skip~~,$unwind,$sort,$geoNear,$out) 30% ($limit and $skip is implemented as $result(skip,limit))
- Grouping (~~$group~~,~~$count~~,~~$sum~~,~~$avg~~,$first,$last,~~$min~~,~~$max~~,~~$push~~,$addToSet) 70% ($count is used to count the results)
- Operators (Boolean,Set,Comparison,~~Arithmetic~~,~~String~~,Array,Date,Conditional,Variable,Grouping) 20% ($mod is renamed $modulo, because Evaluation has a $mod)

@@ -41,0 +43,0 @@ - Support Promise/A+ sources for the odm.addSource

@@ -11,3 +11,4 @@ "use strict";

*/
jsonOdm.Geo = function () {};
jsonOdm.Geo = function () {
};

@@ -20,19 +21,21 @@ /**

jsonOdm.Geo.detectAsGeometry = function (geometry) {
if(!geometry.type){
if(jsonOdm.util.isArray(geometry) && geometry.length == 2 && !jsonOdm.util.isArray(geometry[0])){
if (!geometry.type) {
if (jsonOdm.util.isArray(geometry) && geometry.length === 2 && !jsonOdm.util.isArray(geometry[0])) {
geometry = new jsonOdm.Geo.Point(geometry);
}else if(jsonOdm.util.isArray(geometry) && geometry.length == 4 && !jsonOdm.util.isArray(geometry[0])){
} else if (jsonOdm.util.isArray(geometry) && geometry.length === 4 && !jsonOdm.util.isArray(geometry[0])) {
geometry = new jsonOdm.Geo.BoundaryBox(geometry);
}else if(jsonOdm.util.isArray(geometry) && geometry.length >= 1 && jsonOdm.util.isArray(geometry[0]) && geometry[0].length == 2 && !jsonOdm.util.isArray(geometry[0][0])){
} else if (jsonOdm.util.isArray(geometry) && geometry.length >= 1 && jsonOdm.util.isArray(geometry[0]) && geometry[0].length === 2 && !jsonOdm.util.isArray(geometry[0][0])) {
geometry = new jsonOdm.Geo.LineString(geometry);
}else if( jsonOdm.util.isArray(geometry) && geometry.length >= 1 &&
} else if (jsonOdm.util.isArray(geometry) && geometry.length >= 1 &&
jsonOdm.util.isArray(geometry[0]) && geometry[0].length >= 1 &&
jsonOdm.util.isArray(geometry[0][0]) && geometry[0][0].length == 2 && !jsonOdm.util.isArray(geometry[0][0][0])){
jsonOdm.util.isArray(geometry[0][0]) && geometry[0][0].length === 2 && !jsonOdm.util.isArray(geometry[0][0][0])) {
geometry = new jsonOdm.Geo.Polygon(geometry);
}else if( jsonOdm.util.isArray(geometry) && geometry.length >= 1 &&
} else if (jsonOdm.util.isArray(geometry) && geometry.length >= 1 &&
jsonOdm.util.isArray(geometry[0]) && geometry[0].length >= 1 &&
jsonOdm.util.isArray(geometry[0][0]) && geometry[0][0].length >= 1 &&
jsonOdm.util.isArray(geometry[0][0][0]) && geometry[0][0][0].length == 2 && !jsonOdm.util.isArray(geometry[0][0][0][0])){
jsonOdm.util.isArray(geometry[0][0][0]) && geometry[0][0][0].length === 2 && !jsonOdm.util.isArray(geometry[0][0][0][0])) {
geometry = new jsonOdm.Geo.MultiPolygon(geometry);
}else return false;
} else {
return false;
}
}

@@ -48,6 +51,8 @@ return geometry;

*/
jsonOdm.Geo.FeatureCollection = function (features,boundaryBox) {
jsonOdm.Geo.FeatureCollection = function (features, boundaryBox) {
this.type = "FeatureCollection";
this.features = features || [];
if(boundaryBox) this.bbox = boundaryBox;
if (boundaryBox) {
this.bbox = boundaryBox;
}
};

@@ -63,7 +68,13 @@

*/
jsonOdm.Geo.Feature = function (geometry,properties,boundaryBox,id) {
jsonOdm.Geo.Feature = function (geometry, properties, boundaryBox, id) {
this.geometry = geometry || {};
if(properties) this.properties = properties;
if(boundaryBox) this.bbox = boundaryBox;
if(id) this.id = id;
if (properties) {
this.properties = properties;
}
if (boundaryBox) {
this.bbox = boundaryBox;
}
if (id) {
this.id = id;
}
};

@@ -79,6 +90,6 @@

jsonOdm.Geo.BoundaryBox = function (boundaryBox) {
var self = Object.create( Array.prototype );
var self = Object.create(Array.prototype);
// calls the constructor of Array
self = (Array.apply(self) || self);
if(jsonOdm.util.isArray(boundaryBox)){
if (jsonOdm.util.isArray(boundaryBox)) {
self[0] = boundaryBox[0];

@@ -88,3 +99,3 @@ self[1] = boundaryBox[1];

self[3] = boundaryBox[3];
}else{
} else {
self[0] = 0;

@@ -104,6 +115,8 @@ self[1] = 0;

*/
jsonOdm.Geo.BoundaryBox.within = function (bounds,geometry) {
if(!jsonOdm.util.isArray(bounds) || bounds.length != 4) return false;
jsonOdm.Geo.BoundaryBox.within = function (bounds, geometry) {
if (!jsonOdm.util.isArray(bounds) || bounds.length !== 4) {
return false;
}
// a boundary box is equal to a polygonal box
return jsonOdm.Geo.Polygon.within(new jsonOdm.Geo.Polygon([[[bounds[0],bounds[1]],[bounds[2],bounds[1]],[bounds[2],bounds[3]],[bounds[0],bounds[3]],[bounds[0],bounds[1]]]]),geometry)
return jsonOdm.Geo.Polygon.within(new jsonOdm.Geo.Polygon([[[bounds[0], bounds[1]], [bounds[2], bounds[1]], [bounds[2], bounds[3]], [bounds[0], bounds[3]], [bounds[0], bounds[1]]]]), geometry);
};

@@ -119,6 +132,6 @@

*/
jsonOdm.Geo.Point = function (position,boundaryBox) {
jsonOdm.Geo.Point = function (position, boundaryBox) {
this.type = "Point";
this.coordinates = position;
if(boundaryBox) this.bbox = boundaryBox;
if (boundaryBox) this.bbox = boundaryBox;
};

@@ -132,3 +145,3 @@

*/
jsonOdm.Geo.Point.within = function (point,geometry) {
jsonOdm.Geo.Point.within = function (point, geometry) {
var i, j;

@@ -161,6 +174,6 @@ if (!point.coordinates) return false;

}
if(geometry.type == "GeometryCollection" && jsonOdm.util.isArray(geometry.geometries)) {
if (geometry.type == "GeometryCollection" && jsonOdm.util.isArray(geometry.geometries)) {
// maybe order it by complexity to get a better best case scenario
for(i = 0; i < geometry.geometries.length; i++){
if(jsonOdm.Geo.Point.within(point,geometry.geometries[i])) return true;
for (i = 0; i < geometry.geometries.length; i++) {
if (jsonOdm.Geo.Point.within(point, geometry.geometries[i])) return true;
}

@@ -170,3 +183,3 @@ return false;

// might be a boundary box
return jsonOdm.Geo.pointWithinBounds(point.coordinates,geometry);
return jsonOdm.Geo.pointWithinBounds(point.coordinates, geometry);
};

@@ -195,6 +208,6 @@

*/
jsonOdm.Geo.MultiPoint = function (positions,boundaryBox) {
jsonOdm.Geo.MultiPoint = function (positions, boundaryBox) {
this.type = "MultiPoint";
this.coordinates = positions;
if(boundaryBox) this.bbox = boundaryBox;
if (boundaryBox) this.bbox = boundaryBox;
};

@@ -208,3 +221,3 @@

*/
jsonOdm.Geo.MultiPoint.within = function (multiPoint,geometry) {
jsonOdm.Geo.MultiPoint.within = function (multiPoint, geometry) {
var i, j, k, found;

@@ -214,10 +227,11 @@ if (!multiPoint.coordinates || !jsonOdm.util.isArray(multiPoint.coordinates)) return false;

if (geometry.type == "MultiPoint") {
for(j = 0 ; multiPoint.coordinates && j < multiPoint.coordinates.length; j++){
for (j = 0; multiPoint.coordinates && j < multiPoint.coordinates.length; j++) {
found = false;
for (i = 0; geometry.coordinates && i < geometry.coordinates.length; i++) {
if(geometry.coordinates[i][0] == multiPoint.coordinates[j][0] && geometry.coordinates[i][1] == multiPoint.coordinates[j][1]){
found = true; break;
if (geometry.coordinates[i][0] == multiPoint.coordinates[j][0] && geometry.coordinates[i][1] == multiPoint.coordinates[j][1]) {
found = true;
break;
}
}
if(!found) return false;
if (!found) return false;
}

@@ -246,5 +260,5 @@ return true;

if (geometry.type == "Polygon") {
for(i = 0; multiPoint.coordinates && i < multiPoint.coordinates.length; i++) {
for (i = 0; multiPoint.coordinates && i < multiPoint.coordinates.length; i++) {
// we assume that polygon wholes do not intersect the outer polygon
if(!jsonOdm.Geo.pointWithinPolygon(multiPoint.coordinates[i], geometry.coordinates ? geometry.coordinates[0] : null)) return false;
if (!jsonOdm.Geo.pointWithinPolygon(multiPoint.coordinates[i], geometry.coordinates ? geometry.coordinates[0] : null)) return false;
}

@@ -254,7 +268,7 @@ return true;

if (geometry.type == "MultiPolygon") {
for(j = 0; multiPoint.coordinates && j < multiPoint.coordinates.length; j++) {
for (j = 0; multiPoint.coordinates && j < multiPoint.coordinates.length; j++) {
found = false;
for (i = 0; geometry.coordinates && i < geometry.coordinates.length; i++) {
// we assume that polygon wholes do not intersect the outer polygon
if(jsonOdm.Geo.pointWithinPolygon(multiPoint.coordinates[j], geometry.coordinates[i] ? geometry.coordinates[i][0] : null)){
if (jsonOdm.Geo.pointWithinPolygon(multiPoint.coordinates[j], geometry.coordinates[i] ? geometry.coordinates[i][0] : null)) {
found = true;

@@ -264,10 +278,10 @@ break;

}
if(!found) return false;
if (!found) return false;
}
return true;
}
if(geometry.type == "GeometryCollection" && jsonOdm.util.isArray(geometry.geometries)) {
if (geometry.type == "GeometryCollection" && jsonOdm.util.isArray(geometry.geometries)) {
// maybe order it by complexity to get a better best case scenario
for(i = 0; i < geometry.geometries.length; i++){
if(jsonOdm.Geo.MultiPoint.within(multiPoint,geometry.geometries[i])) return true;
for (i = 0; i < geometry.geometries.length; i++) {
if (jsonOdm.Geo.MultiPoint.within(multiPoint, geometry.geometries[i])) return true;
}

@@ -277,4 +291,4 @@ return false;

// assume we have a BoundaryBox given
for(i = 0; i < multiPoint.coordinates.length; i++){
if(!jsonOdm.Geo.pointWithinBounds(multiPoint.coordinates[i],geometry)) return false;
for (i = 0; i < multiPoint.coordinates.length; i++) {
if (!jsonOdm.Geo.pointWithinBounds(multiPoint.coordinates[i], geometry)) return false;
}

@@ -290,12 +304,12 @@ return true;

*/
jsonOdm.Geo.MultiPoint.intersects = function (multiPoint,geometry) {
jsonOdm.Geo.MultiPoint.intersects = function (multiPoint, geometry) {
var i, j, k;
if (!multiPoint.coordinates || !jsonOdm.util.isArray(multiPoint.coordinates)) return false;
if (geometry.type == "Point") {
return jsonOdm.Geo.Point.intersects(geometry,multiPoint);
return jsonOdm.Geo.Point.intersects(geometry, multiPoint);
}
if (geometry.type == "MultiPoint") {
for(j = 0 ; multiPoint.coordinates && j < multiPoint.coordinates.length; j++){
for (j = 0; multiPoint.coordinates && j < multiPoint.coordinates.length; j++) {
for (i = 0; geometry.coordinates && i < geometry.coordinates.length; i++) {
if(geometry.coordinates[i][0] == multiPoint.coordinates[j][0] && geometry.coordinates[i][1] == multiPoint.coordinates[j][1]) return true;
if (geometry.coordinates[i][0] == multiPoint.coordinates[j][0] && geometry.coordinates[i][1] == multiPoint.coordinates[j][1]) return true;
}

@@ -320,4 +334,4 @@ }

if (geometry.type == "Polygon") {
for(i = 0; multiPoint.coordinates && i < multiPoint.coordinates.length; i++) {
if(jsonOdm.Geo.pointWithinPolygon(multiPoint.coordinates[i], geometry.coordinates ? geometry.coordinates[0] : null)) return true;
for (i = 0; multiPoint.coordinates && i < multiPoint.coordinates.length; i++) {
if (jsonOdm.Geo.pointWithinPolygon(multiPoint.coordinates[i], geometry.coordinates ? geometry.coordinates[0] : null)) return true;
}

@@ -327,6 +341,6 @@ return false;

if (geometry.type == "MultiPolygon") {
for(j = 0; multiPoint.coordinates && j < multiPoint.coordinates.length; j++) {
for (j = 0; multiPoint.coordinates && j < multiPoint.coordinates.length; j++) {
for (i = 0; geometry.coordinates && i < geometry.coordinates.length; i++) {
// we assume that polygon wholes do not intersect the outer polygon
if(jsonOdm.Geo.pointWithinPolygon(multiPoint.coordinates[j], geometry.coordinates[i] ? geometry.coordinates[i][0] : null)) return true;
if (jsonOdm.Geo.pointWithinPolygon(multiPoint.coordinates[j], geometry.coordinates[i] ? geometry.coordinates[i][0] : null)) return true;
}

@@ -336,5 +350,5 @@ }

}
if(geometry.type == "GeometryCollection" && jsonOdm.util.isArray(geometry.geometries)) {
for(i = 0; i < geometry.geometries.length; i++){
if(jsonOdm.Geo.MultiPoint.intersects(multiPoint,geometry.geometries[i])) return true;
if (geometry.type == "GeometryCollection" && jsonOdm.util.isArray(geometry.geometries)) {
for (i = 0; i < geometry.geometries.length; i++) {
if (jsonOdm.Geo.MultiPoint.intersects(multiPoint, geometry.geometries[i])) return true;
}

@@ -344,4 +358,4 @@ return false;

// assume we have a BoundaryBox given
for(i = 0; i < multiPoint.coordinates.length; i++){
if(jsonOdm.Geo.pointWithinBounds(multiPoint.coordinates[i],geometry)) return true;
for (i = 0; i < multiPoint.coordinates.length; i++) {
if (jsonOdm.Geo.pointWithinBounds(multiPoint.coordinates[i], geometry)) return true;
}

@@ -361,6 +375,6 @@ return false;

*/
jsonOdm.Geo.LineString = function (positions,boundaryBox) {
jsonOdm.Geo.LineString = function (positions, boundaryBox) {
this.type = "LineString";
this.coordinates = positions;
if(boundaryBox) this.bbox = boundaryBox;
if (boundaryBox) this.bbox = boundaryBox;
};

@@ -380,7 +394,7 @@

if (geometry.type == "LineString") {
return jsonOdm.Geo.lineStringWithinLineString(lineString.coordinates,geometry.coordinates);
return jsonOdm.Geo.lineStringWithinLineString(lineString.coordinates, geometry.coordinates);
}
if (geometry.type == "MultiLineString") {
for (i = 0; geometry.coordinates && i < geometry.coordinates.length; i++) {
if (jsonOdm.Geo.lineStringWithinLineString(lineString.coordinates,geometry.coordinates[i])) {
if (jsonOdm.Geo.lineStringWithinLineString(lineString.coordinates, geometry.coordinates[i])) {
return true;

@@ -392,4 +406,4 @@ }

if (geometry.type == "Polygon") {
for(i = 0; lineString.coordinates && i < lineString.coordinates.length-1; i++){
if(!jsonOdm.Geo.edgeWithinPolygon([lineString.coordinates[i],lineString.coordinates[i+1]],geometry.coordinates[0]))return false;
for (i = 0; lineString.coordinates && i < lineString.coordinates.length - 1; i++) {
if (!jsonOdm.Geo.edgeWithinPolygon([lineString.coordinates[i], lineString.coordinates[i + 1]], geometry.coordinates[0]))return false;
}

@@ -400,4 +414,4 @@ return true;

for (i = 0; geometry.coordinates && i < geometry.coordinates.length; i++) {
for(j = 0; lineString.coordinates && j < lineString.coordinates.length - 1; j++){
if(jsonOdm.Geo.edgeWithinPolygon([lineString.coordinates[j],lineString.coordinates[j+1]],geometry.coordinates[i][0]) && j+1 == lineString.coordinates.length - 1){
for (j = 0; lineString.coordinates && j < lineString.coordinates.length - 1; j++) {
if (jsonOdm.Geo.edgeWithinPolygon([lineString.coordinates[j], lineString.coordinates[j + 1]], geometry.coordinates[i][0]) && j + 1 == lineString.coordinates.length - 1) {
return true;

@@ -409,6 +423,6 @@ }

}
if(geometry.type == "GeometryCollection" && jsonOdm.util.isArray(geometry.geometries)) {
if (geometry.type == "GeometryCollection" && jsonOdm.util.isArray(geometry.geometries)) {
// maybe order it by complexity to get a better best case scenario
for(i = 0; i < geometry.geometries.length; i++){
if(jsonOdm.Geo.LineString.within(lineString,geometry.geometries[i])) return true;
for (i = 0; i < geometry.geometries.length; i++) {
if (jsonOdm.Geo.LineString.within(lineString, geometry.geometries[i])) return true;
}

@@ -418,4 +432,4 @@ return false;

// assume we have a BoundaryBox given
for(i = 0; i < lineString.coordinates.length; i++){
if(!jsonOdm.Geo.pointWithinBounds(lineString.coordinates[i],geometry)){
for (i = 0; i < lineString.coordinates.length; i++) {
if (!jsonOdm.Geo.pointWithinBounds(lineString.coordinates[i], geometry)) {
return false;

@@ -438,11 +452,11 @@ }

if (geometry.type == "Point") {
return jsonOdm.Geo.Point.intersects(geometry,lineString);
return jsonOdm.Geo.Point.intersects(geometry, lineString);
}
if(geometry.type == "MultiPoint") {
return jsonOdm.Geo.MultiPoint.intersects(geometry,lineString);
if (geometry.type == "MultiPoint") {
return jsonOdm.Geo.MultiPoint.intersects(geometry, lineString);
}
if (geometry.type == "LineString") {
for(i = 0; i < lineString.coordinates.length - 1; i++){
if(jsonOdm.Geo.edgeIntersectsLineString([lineString.coordinates[i],lineString.coordinates[i+1]],geometry.coordinates)) return true;
for (i = 0; i < lineString.coordinates.length - 1; i++) {
if (jsonOdm.Geo.edgeIntersectsLineString([lineString.coordinates[i], lineString.coordinates[i + 1]], geometry.coordinates)) return true;
}

@@ -453,4 +467,4 @@ return false;

for (i = 0; geometry.coordinates && i < geometry.coordinates.length; i++) {
for(j = 0; j < lineString.coordinates.length - 1; j++){
if(jsonOdm.Geo.edgeIntersectsLineString([lineString.coordinates[j],lineString.coordinates[j+1]],geometry.coordinates[i])) return true;
for (j = 0; j < lineString.coordinates.length - 1; j++) {
if (jsonOdm.Geo.edgeIntersectsLineString([lineString.coordinates[j], lineString.coordinates[j + 1]], geometry.coordinates[i])) return true;
}

@@ -461,4 +475,4 @@ }

if (geometry.type == "Polygon") {
for(i = 0; lineString.coordinates && i < lineString.coordinates.length - 1; i++){
if(jsonOdm.Geo.edgeIntersectsPolygon([lineString.coordinates[i],lineString.coordinates[i+1]],geometry.coordinates[0]))return true;
for (i = 0; lineString.coordinates && i < lineString.coordinates.length - 1; i++) {
if (jsonOdm.Geo.edgeIntersectsPolygon([lineString.coordinates[i], lineString.coordinates[i + 1]], geometry.coordinates[0]))return true;
}

@@ -469,4 +483,4 @@ return false;

for (i = 0; geometry.coordinates && i < geometry.coordinates.length; i++) {
for(j = 0; lineString.coordinates && j < lineString.coordinates.length - 1; j++){
if(jsonOdm.Geo.edgeIntersectsPolygon([lineString.coordinates[j],lineString.coordinates[j+1]],geometry.coordinates[i][0])) return true;
for (j = 0; lineString.coordinates && j < lineString.coordinates.length - 1; j++) {
if (jsonOdm.Geo.edgeIntersectsPolygon([lineString.coordinates[j], lineString.coordinates[j + 1]], geometry.coordinates[i][0])) return true;
}

@@ -476,6 +490,6 @@ }

}
if(geometry.type == "GeometryCollection" && jsonOdm.util.isArray(geometry.geometries)) {
if (geometry.type == "GeometryCollection" && jsonOdm.util.isArray(geometry.geometries)) {
// maybe order it by complexity to get a better best case scenario
for(i = 0; i < geometry.geometries.length; i++){
if(jsonOdm.Geo.LineString.intersects(lineString,geometry.geometries[i])) return true;
for (i = 0; i < geometry.geometries.length; i++) {
if (jsonOdm.Geo.LineString.intersects(lineString, geometry.geometries[i])) return true;
}

@@ -485,4 +499,4 @@ return false;

// assume we have a BoundaryBox given
for(i = 0; lineString.coordinates && i < lineString.coordinates.length - 1; i++){
if(jsonOdm.Geo.edgeIntersectsBounds([lineString.coordinates[i],lineString.coordinates[i + 1]],geometry))return true;
for (i = 0; lineString.coordinates && i < lineString.coordinates.length - 1; i++) {
if (jsonOdm.Geo.edgeIntersectsBounds([lineString.coordinates[i], lineString.coordinates[i + 1]], geometry))return true;
}

@@ -503,6 +517,6 @@ return false;

*/
jsonOdm.Geo.MultiLineString = function (positions,boundaryBox) {
jsonOdm.Geo.MultiLineString = function (positions, boundaryBox) {
this.type = "MultiLineString";
this.coordinates = positions;
if(boundaryBox) this.bbox = boundaryBox;
if (boundaryBox) this.bbox = boundaryBox;
};

@@ -523,3 +537,3 @@

for (i = 0; multiLineString.coordinates && i < multiLineString.coordinates.length; i++) {
if(!jsonOdm.Geo.lineStringWithinLineString(multiLineString.coordinates[i],geometry.coordinates)) return false;
if (!jsonOdm.Geo.lineStringWithinLineString(multiLineString.coordinates[i], geometry.coordinates)) return false;
}

@@ -532,3 +546,3 @@ return true;

for (i = 0; geometry.coordinates && i < geometry.coordinates.length; i++) {
if (jsonOdm.Geo.lineStringWithinLineString(multiLineString.coordinates[j],geometry.coordinates[i])) {
if (jsonOdm.Geo.lineStringWithinLineString(multiLineString.coordinates[j], geometry.coordinates[i])) {
found = true;

@@ -538,3 +552,3 @@ break;

}
if(!found) return false;
if (!found) return false;
}

@@ -544,5 +558,5 @@ return true;

if (geometry.type == "Polygon") {
for(i = 0; multiLineString.coordinates && i < multiLineString.coordinates.length; i++){
for(j = 0; multiLineString.coordinates && j < multiLineString.coordinates[i].length - 1; j++){
if(!jsonOdm.Geo.edgeWithinPolygon([multiLineString.coordinates[i][j],multiLineString.coordinates[i][j+1]],geometry.coordinates[0])) return false;
for (i = 0; multiLineString.coordinates && i < multiLineString.coordinates.length; i++) {
for (j = 0; multiLineString.coordinates && j < multiLineString.coordinates[i].length - 1; j++) {
if (!jsonOdm.Geo.edgeWithinPolygon([multiLineString.coordinates[i][j], multiLineString.coordinates[i][j + 1]], geometry.coordinates[0])) return false;
}

@@ -553,12 +567,13 @@ }

if (geometry.type == "MultiPolygon") {
for(j = 0; multiLineString.coordinates && j < multiLineString.coordinates.length; j++) {
for (j = 0; multiLineString.coordinates && j < multiLineString.coordinates.length; j++) {
found = false;
for (i = 0; geometry.coordinates && i < geometry.coordinates.length; i++) {
for (k = 0; multiLineString.coordinates[j] && k < multiLineString.coordinates[j].length - 1; k++) {
if (jsonOdm.Geo.edgeWithinPolygon([multiLineString.coordinates[j][k],multiLineString.coordinates[j][k+1]], geometry.coordinates[i][0]) && k + 1 == multiLineString.coordinates[j].length - 1) {
found = true; break;
if (jsonOdm.Geo.edgeWithinPolygon([multiLineString.coordinates[j][k], multiLineString.coordinates[j][k + 1]], geometry.coordinates[i][0]) && k + 1 == multiLineString.coordinates[j].length - 1) {
found = true;
break;
}
}
}
if(!found){
if (!found) {
return false;

@@ -569,6 +584,6 @@ }

}
if(geometry.type == "GeometryCollection" && jsonOdm.util.isArray(geometry.geometries)) {
if (geometry.type == "GeometryCollection" && jsonOdm.util.isArray(geometry.geometries)) {
// maybe order it by complexity to get a better best case scenario
for(i = 0; i < geometry.geometries.length; i++){
if(jsonOdm.Geo.MultiLineString.within(multiLineString,geometry.geometries[i])) return true;
for (i = 0; i < geometry.geometries.length; i++) {
if (jsonOdm.Geo.MultiLineString.within(multiLineString, geometry.geometries[i])) return true;
}

@@ -578,5 +593,5 @@ return false;

// assume we have a BoundaryBox given
for(i = 0; i < multiLineString.coordinates.length; i++){
for(j = 0; j < multiLineString.coordinates[i].length; j++){
if(!jsonOdm.Geo.pointWithinBounds(multiLineString.coordinates[i][j],geometry)){
for (i = 0; i < multiLineString.coordinates.length; i++) {
for (j = 0; j < multiLineString.coordinates[i].length; j++) {
if (!jsonOdm.Geo.pointWithinBounds(multiLineString.coordinates[i][j], geometry)) {
return false;

@@ -599,9 +614,9 @@ }

if (geometry.type == "Point") {
return jsonOdm.Geo.Point.intersects(geometry,multiLineString);
return jsonOdm.Geo.Point.intersects(geometry, multiLineString);
}
if(geometry.type == "MultiPoint") {
return jsonOdm.Geo.MultiPoint.intersects(geometry,multiLineString);
if (geometry.type == "MultiPoint") {
return jsonOdm.Geo.MultiPoint.intersects(geometry, multiLineString);
}
if (geometry.type == "LineString") {
return jsonOdm.Geo.LineString.intersects(geometry,multiLineString);
return jsonOdm.Geo.LineString.intersects(geometry, multiLineString);
}

@@ -612,3 +627,3 @@ if (geometry.type == "MultiLineString") {

for (i = 0; geometry.coordinates && i < geometry.coordinates.length; i++) {
if (jsonOdm.Geo.edgeIntersectsLineString([multiLineString.coordinates[j][k],multiLineString.coordinates[j][k+1]], geometry.coordinates[i])) return true;
if (jsonOdm.Geo.edgeIntersectsLineString([multiLineString.coordinates[j][k], multiLineString.coordinates[j][k + 1]], geometry.coordinates[i])) return true;
}

@@ -620,5 +635,5 @@ }

if (geometry.type == "Polygon") {
for(i = 0; multiLineString.coordinates && i < multiLineString.coordinates.length; i++){
for(j = 0; multiLineString.coordinates && j < multiLineString.coordinates[i].length - 1; j++){
if(jsonOdm.Geo.edgeIntersectsPolygon([multiLineString.coordinates[i][j],multiLineString.coordinates[i][j+1]],geometry.coordinates[0])) return true;
for (i = 0; multiLineString.coordinates && i < multiLineString.coordinates.length; i++) {
for (j = 0; multiLineString.coordinates && j < multiLineString.coordinates[i].length - 1; j++) {
if (jsonOdm.Geo.edgeIntersectsPolygon([multiLineString.coordinates[i][j], multiLineString.coordinates[i][j + 1]], geometry.coordinates[0])) return true;
}

@@ -629,6 +644,6 @@ }

if (geometry.type == "MultiPolygon") {
for(j = 0; multiLineString.coordinates && j < multiLineString.coordinates.length; j++) {
for (j = 0; multiLineString.coordinates && j < multiLineString.coordinates.length; j++) {
for (i = 0; geometry.coordinates && i < geometry.coordinates.length; i++) {
for (k = 0; multiLineString.coordinates[j] && k < multiLineString.coordinates[j].length - 1; k++) {
if (jsonOdm.Geo.edgeIntersectsPolygon([multiLineString.coordinates[j][k],multiLineString.coordinates[j][k+1]], geometry.coordinates[i][0])) return true;
if (jsonOdm.Geo.edgeIntersectsPolygon([multiLineString.coordinates[j][k], multiLineString.coordinates[j][k + 1]], geometry.coordinates[i][0])) return true;
}

@@ -639,6 +654,6 @@ }

}
if(geometry.type == "GeometryCollection" && jsonOdm.util.isArray(geometry.geometries)) {
if (geometry.type == "GeometryCollection" && jsonOdm.util.isArray(geometry.geometries)) {
// maybe order it by complexity to get a better best case scenario
for(i = 0; i < geometry.geometries.length; i++){
if(jsonOdm.Geo.MultiLineString.intersects(multiLineString,geometry.geometries[i])) return true;
for (i = 0; i < geometry.geometries.length; i++) {
if (jsonOdm.Geo.MultiLineString.intersects(multiLineString, geometry.geometries[i])) return true;
}

@@ -648,5 +663,5 @@ return false;

// assume we have a BoundaryBox given
for(i = 0; multiLineString.coordinates && i < multiLineString.coordinates.length; i++){
for(j = 0; j < multiLineString.coordinates[i].length - 1; j++){
if(jsonOdm.Geo.edgeIntersectsBounds([multiLineString.coordinates[i][j],multiLineString.coordinates[i][j+1]],geometry)) return true;
for (i = 0; multiLineString.coordinates && i < multiLineString.coordinates.length; i++) {
for (j = 0; j < multiLineString.coordinates[i].length - 1; j++) {
if (jsonOdm.Geo.edgeIntersectsBounds([multiLineString.coordinates[i][j], multiLineString.coordinates[i][j + 1]], geometry)) return true;
}

@@ -671,6 +686,6 @@ }

*/
jsonOdm.Geo.Polygon = function (positions,boundaryBox) {
jsonOdm.Geo.Polygon = function (positions, boundaryBox) {
this.type = "Polygon";
this.coordinates = positions;
if(boundaryBox) this.bbox = boundaryBox;
if (boundaryBox) this.bbox = boundaryBox;
};

@@ -684,3 +699,3 @@

*/
jsonOdm.Geo.Polygon.within = function (polygon,geometry) {
jsonOdm.Geo.Polygon.within = function (polygon, geometry) {
var i, j;

@@ -691,4 +706,4 @@ if (!polygon.coordinates || !jsonOdm.util.isArray(polygon.coordinates)) return false;

if (geometry.type == "Polygon") {
for(i = 0; polygon.coordinates[0] && i < polygon.coordinates[0].length - 1; i++){
if(!jsonOdm.Geo.edgeWithinPolygon([polygon.coordinates[0][i],polygon.coordinates[0][i+1]],geometry.coordinates[0])) return false;
for (i = 0; polygon.coordinates[0] && i < polygon.coordinates[0].length - 1; i++) {
if (!jsonOdm.Geo.edgeWithinPolygon([polygon.coordinates[0][i], polygon.coordinates[0][i + 1]], geometry.coordinates[0])) return false;
}

@@ -698,6 +713,6 @@ return true;

if (geometry.type == "MultiPolygon") {
for(i = 0; geometry.coordinates && i < geometry.coordinates.length; i++) {
for (i = 0; geometry.coordinates && i < geometry.coordinates.length; i++) {
for (j = 0; polygon.coordinates[0] && j < polygon.coordinates[0].length - 1; j++) {
var inside = jsonOdm.Geo.edgeWithinPolygon([polygon.coordinates[0][j], polygon.coordinates[0][j + 1]], geometry.coordinates[i][0]);
if(!inside) break;
if (!inside) break;
if (inside && j + 1 == polygon.coordinates[0].length - 1) {

@@ -710,6 +725,6 @@ return true;

}
if(geometry.type == "GeometryCollection" && jsonOdm.util.isArray(geometry.geometries)) {
if (geometry.type == "GeometryCollection" && jsonOdm.util.isArray(geometry.geometries)) {
// maybe order it by complexity to get a better best case scenario
for(i = 0; i < geometry.geometries.length; i++){
if(jsonOdm.Geo.Polygon.within(polygon,geometry.geometries[i])) return true;
for (i = 0; i < geometry.geometries.length; i++) {
if (jsonOdm.Geo.Polygon.within(polygon, geometry.geometries[i])) return true;
}

@@ -719,4 +734,4 @@ return false;

// assume we have a BoundaryBox given
for(i = 0;polygon.coordinates[0] && i < polygon.coordinates[0].length; i++){
if(!jsonOdm.Geo.pointWithinBounds(polygon.coordinates[0][i],geometry)){
for (i = 0; polygon.coordinates[0] && i < polygon.coordinates[0].length; i++) {
if (!jsonOdm.Geo.pointWithinBounds(polygon.coordinates[0][i], geometry)) {
return false;

@@ -734,21 +749,21 @@ }

*/
jsonOdm.Geo.Polygon.intersects = function (polygon,geometry) {
jsonOdm.Geo.Polygon.intersects = function (polygon, geometry) {
var i, j;
if (!polygon.coordinates || !jsonOdm.util.isArray(polygon.coordinates)) return false;
if (geometry.type == "Point") {
return jsonOdm.Geo.Point.intersects(geometry,polygon);
return jsonOdm.Geo.Point.intersects(geometry, polygon);
}
if(geometry.type == "MultiPoint") {
return jsonOdm.Geo.MultiPoint.intersects(geometry,polygon);
if (geometry.type == "MultiPoint") {
return jsonOdm.Geo.MultiPoint.intersects(geometry, polygon);
}
if (geometry.type == "LineString") {
return jsonOdm.Geo.LineString.intersects(geometry,polygon);
return jsonOdm.Geo.LineString.intersects(geometry, polygon);
}
if (geometry.type == "MultiLineString") {
return jsonOdm.Geo.MultiLineString.intersects(geometry,polygon);
return jsonOdm.Geo.MultiLineString.intersects(geometry, polygon);
}
if (geometry.type == "Polygon") {
for(i = 0; polygon.coordinates[0] && i < polygon.coordinates[0].length - 1; i++){
if(jsonOdm.Geo.edgeIntersectsPolygon([polygon.coordinates[0][i],polygon.coordinates[0][i+1]],geometry.coordinates[0])) return true;
for (i = 0; polygon.coordinates[0] && i < polygon.coordinates[0].length - 1; i++) {
if (jsonOdm.Geo.edgeIntersectsPolygon([polygon.coordinates[0][i], polygon.coordinates[0][i + 1]], geometry.coordinates[0])) return true;
}

@@ -758,5 +773,5 @@ return false;

if (geometry.type == "MultiPolygon") {
for(i = 0; geometry.coordinates && i < geometry.coordinates.length; i++) {
for (i = 0; geometry.coordinates && i < geometry.coordinates.length; i++) {
for (j = 0; polygon.coordinates[0] && j < polygon.coordinates[0].length - 1; j++) {
if(jsonOdm.Geo.edgeIntersectsPolygon([polygon.coordinates[0][j],polygon.coordinates[0][j+1]], geometry.coordinates[i][0])) return true;
if (jsonOdm.Geo.edgeIntersectsPolygon([polygon.coordinates[0][j], polygon.coordinates[0][j + 1]], geometry.coordinates[i][0])) return true;
}

@@ -766,6 +781,6 @@ }

}
if(geometry.type == "GeometryCollection" && jsonOdm.util.isArray(geometry.geometries)) {
if (geometry.type == "GeometryCollection" && jsonOdm.util.isArray(geometry.geometries)) {
// maybe order it by complexity to get a better best case scenario
for(i = 0; i < geometry.geometries.length; i++){
if(jsonOdm.Geo.Polygon.intersects(polygon,geometry.geometries[i])) return true;
for (i = 0; i < geometry.geometries.length; i++) {
if (jsonOdm.Geo.Polygon.intersects(polygon, geometry.geometries[i])) return true;
}

@@ -775,4 +790,4 @@ return false;

// assume we have a BoundaryBox given
for(i = 0;polygon.coordinates[0] && i < polygon.coordinates[0].length - 1; i++){
if(jsonOdm.Geo.edgeIntersectsBounds([polygon.coordinates[0][i],polygon.coordinates[0][i+1]],geometry)){
for (i = 0; polygon.coordinates[0] && i < polygon.coordinates[0].length - 1; i++) {
if (jsonOdm.Geo.edgeIntersectsBounds([polygon.coordinates[0][i], polygon.coordinates[0][i + 1]], geometry)) {
return true;

@@ -801,6 +816,6 @@ }

*/
jsonOdm.Geo.MultiPolygon = function (positions,boundaryBox) {
jsonOdm.Geo.MultiPolygon = function (positions, boundaryBox) {
this.type = "MultiPolygon";
this.coordinates = positions;
if(boundaryBox) this.bbox = boundaryBox;
if (boundaryBox) this.bbox = boundaryBox;
};

@@ -814,3 +829,3 @@

*/
jsonOdm.Geo.MultiPolygon.within = function (multiPolygon,geometry) {
jsonOdm.Geo.MultiPolygon.within = function (multiPolygon, geometry) {
var i, j, k, found;

@@ -821,3 +836,3 @@ if (!multiPolygon.coordinates || !jsonOdm.util.isArray(multiPolygon.coordinates)) return false;

if (geometry.type == "Polygon") {
for(i = 0; multiPolygon.coordinates && i < multiPolygon.coordinates.length; i++) {
for (i = 0; multiPolygon.coordinates && i < multiPolygon.coordinates.length; i++) {
for (j = 0; j < multiPolygon.coordinates[i][0].length - 1; j++) {

@@ -835,15 +850,16 @@ if (!jsonOdm.Geo.edgeWithinPolygon([multiPolygon.coordinates[i][0][j], multiPolygon.coordinates[i][0][j + 1]], geometry.coordinates[0])) return false;

var inside = jsonOdm.Geo.edgeWithinPolygon([multiPolygon.coordinates[i][0][k], multiPolygon.coordinates[i][0][k + 1]], geometry.coordinates[j][0]);
if(!inside) break;
if (!inside) break;
if (inside && k + 1 == multiPolygon.coordinates[i][0].length - 1) {
found = true; break;
found = true;
break;
}
}
}
if(!found) return false;
if (!found) return false;
}
return true;
}
if(geometry.type == "GeometryCollection" && jsonOdm.util.isArray(geometry.geometries)) {
for(i = 0; i < geometry.geometries.length; i++){
if(jsonOdm.Geo.MultiPolygon.within(multiPolygon,geometry.geometries[i])) return true;
if (geometry.type == "GeometryCollection" && jsonOdm.util.isArray(geometry.geometries)) {
for (i = 0; i < geometry.geometries.length; i++) {
if (jsonOdm.Geo.MultiPolygon.within(multiPolygon, geometry.geometries[i])) return true;
}

@@ -853,3 +869,3 @@ return false;

// assume we have a BoundaryBox given
for(i = 0; i < multiPolygon.coordinates.length; i++) {
for (i = 0; i < multiPolygon.coordinates.length; i++) {
for (j = 0; j < multiPolygon.coordinates[i][0].length; j++) {

@@ -870,19 +886,19 @@ if (!jsonOdm.Geo.pointWithinBounds(multiPolygon.coordinates[i][0][j], geometry)) {

*/
jsonOdm.Geo.MultiPolygon.intersects = function (multiPolygon,geometry) {
jsonOdm.Geo.MultiPolygon.intersects = function (multiPolygon, geometry) {
var i, j, k;
if (!multiPolygon.coordinates || !jsonOdm.util.isArray(multiPolygon.coordinates)) return false;
if (geometry.type == "Point") {
return jsonOdm.Geo.Point.intersects(geometry,multiPolygon);
return jsonOdm.Geo.Point.intersects(geometry, multiPolygon);
}
if(geometry.type == "MultiPoint") {
return jsonOdm.Geo.MultiPoint.intersects(geometry,multiPolygon);
if (geometry.type == "MultiPoint") {
return jsonOdm.Geo.MultiPoint.intersects(geometry, multiPolygon);
}
if (geometry.type == "LineString") {
return jsonOdm.Geo.LineString.intersects(geometry,multiPolygon);
return jsonOdm.Geo.LineString.intersects(geometry, multiPolygon);
}
if (geometry.type == "MultiLineString") {
return jsonOdm.Geo.MultiLineString.intersects(geometry,multiPolygon);
return jsonOdm.Geo.MultiLineString.intersects(geometry, multiPolygon);
}
if (geometry.type == "Polygon") {
return jsonOdm.Geo.Polygon.intersects(geometry,multiPolygon);
return jsonOdm.Geo.Polygon.intersects(geometry, multiPolygon);
}

@@ -894,3 +910,3 @@

for (k = 0; multiPolygon.coordinates[i][0] && k < multiPolygon.coordinates[i][0].length - 1; k++) {
if(jsonOdm.Geo.pointWithinPolygon(multiPolygon.coordinates[i][0][k], geometry.coordinates[j][0])) return true;
if (jsonOdm.Geo.pointWithinPolygon(multiPolygon.coordinates[i][0][k], geometry.coordinates[j][0])) return true;
}

@@ -901,5 +917,5 @@ }

}
if(geometry.type == "GeometryCollection" && jsonOdm.util.isArray(geometry.geometries)) {
for(i = 0; i < geometry.geometries.length; i++){
if(jsonOdm.Geo.MultiPolygon.intersects(multiPolygon,geometry.geometries[i])) return true;
if (geometry.type == "GeometryCollection" && jsonOdm.util.isArray(geometry.geometries)) {
for (i = 0; i < geometry.geometries.length; i++) {
if (jsonOdm.Geo.MultiPolygon.intersects(multiPolygon, geometry.geometries[i])) return true;
}

@@ -909,5 +925,5 @@ return false;

// assume we have a BoundaryBox given
for(i = 0; i < multiPolygon.coordinates.length; i++) {
for (i = 0; i < multiPolygon.coordinates.length; i++) {
for (j = 0; j < multiPolygon.coordinates[i][0].length - 1; j++) {
if (jsonOdm.Geo.edgeIntersectsBounds([multiPolygon.coordinates[i][0][j],multiPolygon.coordinates[i][0][j+1]], geometry)) {
if (jsonOdm.Geo.edgeIntersectsBounds([multiPolygon.coordinates[i][0][j], multiPolygon.coordinates[i][0][j + 1]], geometry)) {
return true;

@@ -932,6 +948,6 @@ }

*/
jsonOdm.Geo.GeometryCollection = function (geometries,boundaryBox) {
jsonOdm.Geo.GeometryCollection = function (geometries, boundaryBox) {
this.type = "GeometryCollection";
this.geometries = geometries;
if(boundaryBox) this.bbox = boundaryBox;
if (boundaryBox) this.bbox = boundaryBox;
};

@@ -945,10 +961,10 @@

*/
jsonOdm.Geo.GeometryCollection.within = function(geometryCollection,geometry){
if(!jsonOdm.util.isArray(geometryCollection.geometries) || !geometryCollection.geometries.length || !geometry.type) return false;
for(var i = 0; i < geometryCollection.geometries.length; i++){
if(jsonOdm.Geo[geometryCollection.geometries[i].type] && jsonOdm.Geo[geometryCollection.geometries[i].type].within){
if(!jsonOdm.Geo[geometryCollection.geometries[i].type].within(geometryCollection.geometries[i],geometry)) {
jsonOdm.Geo.GeometryCollection.within = function (geometryCollection, geometry) {
if (!jsonOdm.util.isArray(geometryCollection.geometries) || !geometryCollection.geometries.length || !geometry.type) return false;
for (var i = 0; i < geometryCollection.geometries.length; i++) {
if (jsonOdm.Geo[geometryCollection.geometries[i].type] && jsonOdm.Geo[geometryCollection.geometries[i].type].within) {
if (!jsonOdm.Geo[geometryCollection.geometries[i].type].within(geometryCollection.geometries[i], geometry)) {
return false;
}
}else return false;
} else return false;
}

@@ -964,7 +980,7 @@ return true;

*/
jsonOdm.Geo.GeometryCollection.intersects = function(geometryCollection,geometry){
if(!jsonOdm.util.isArray(geometryCollection.geometries) || !geometryCollection.geometries.length || !geometry.type) return false;
for(var i = 0; i < geometryCollection.geometries.length; i++){
if(jsonOdm.Geo[geometryCollection.geometries[i].type] && jsonOdm.Geo[geometryCollection.geometries[i].type].intersects){
if(jsonOdm.Geo[geometryCollection.geometries[i].type].intersects(geometryCollection.geometries[i],geometry)) {
jsonOdm.Geo.GeometryCollection.intersects = function (geometryCollection, geometry) {
if (!jsonOdm.util.isArray(geometryCollection.geometries) || !geometryCollection.geometries.length || !geometry.type) return false;
for (var i = 0; i < geometryCollection.geometries.length; i++) {
if (jsonOdm.Geo[geometryCollection.geometries[i].type] && jsonOdm.Geo[geometryCollection.geometries[i].type].intersects) {
if (jsonOdm.Geo[geometryCollection.geometries[i].type].intersects(geometryCollection.geometries[i], geometry)) {
return true;

@@ -983,27 +999,27 @@ }

*/
jsonOdm.Geo.pointWithinPolygon = function (point,polygon) {
if(!(jsonOdm.util.isArray(point) && jsonOdm.util.isArray(polygon) && polygon.length > 2)) return false;
jsonOdm.Geo.pointWithinPolygon = function (point, polygon) {
if (!(jsonOdm.util.isArray(point) && jsonOdm.util.isArray(polygon) && polygon.length > 2)) return false;
var intersection = 0,foundX;
var intersection = 0, foundX;
// close the polygon
if(!(polygon[0][0] == polygon[polygon.length-1][0] && polygon[0][1] == polygon[polygon.length-1][1])) polygon = polygon.concat([polygon[0]]);
if (!(polygon[0][0] == polygon[polygon.length - 1][0] && polygon[0][1] == polygon[polygon.length - 1][1])) polygon = polygon.concat([polygon[0]]);
// do not enter the last point because the calculation also reads the i+1th index
for(var i = 0; i < polygon.length - 1; i++){
if(polygon[i][0] == point[0] && polygon[i][1] == point[1]) return true; // vertex equals the given point
if(
polygon[i][0] < point[0] && polygon[i+1][0] < point[0] || // the vector is only in section 1 or 4 of the coordinate system normalized to the point, so it does not intersect the positive x-axis
polygon[i][1] < point[1] && polygon[i+1][1] < point[1] || // the vector is only in section 1 or 2 of the coordinate system normalized to the point, so it does not intersect the positive x-axis
polygon[i][1] > point[1] && polygon[i+1][1] > point[1] // the vector is only in section 3 or 4 of the coordinate system normalized to the point, so it does not intersect the positive x-axis
){
for (var i = 0; i < polygon.length - 1; i++) {
if (polygon[i][0] == point[0] && polygon[i][1] == point[1]) return true; // vertex equals the given point
if (
polygon[i][0] < point[0] && polygon[i + 1][0] < point[0] || // the vector is only in section 1 or 4 of the coordinate system normalized to the point, so it does not intersect the positive x-axis
polygon[i][1] < point[1] && polygon[i + 1][1] < point[1] || // the vector is only in section 1 or 2 of the coordinate system normalized to the point, so it does not intersect the positive x-axis
polygon[i][1] > point[1] && polygon[i + 1][1] > point[1] // the vector is only in section 3 or 4 of the coordinate system normalized to the point, so it does not intersect the positive x-axis
) {
continue;
}
foundX = (polygon[i][0]-polygon[i+1][0]) * ((point[1]-polygon[i+1][1])/(polygon[i][1]-polygon[i+1][1])) + polygon[i+1][0];
foundX = (polygon[i][0] - polygon[i + 1][0]) * ((point[1] - polygon[i + 1][1]) / (polygon[i][1] - polygon[i + 1][1])) + polygon[i + 1][0];
// on the edge
if(foundX == point[0] && point[1] <= Math.max(polygon[i][1],polygon[i+1][1]) && point[1] >= Math.min(polygon[i][1],polygon[i+1][1]))return true;
if (foundX == point[0] && point[1] <= Math.max(polygon[i][1], polygon[i + 1][1]) && point[1] >= Math.min(polygon[i][1], polygon[i + 1][1]))return true;
// the vector intersects the positive x-axis of the coordinate system normalized to the point
if(foundX > point[0])intersection++;
if (foundX > point[0])intersection++;
}
return intersection%2 == 1; // the normalized x-axis needs to be intersected by a odd amount of intersections
return intersection % 2 == 1; // the normalized x-axis needs to be intersected by a odd amount of intersections
};

@@ -1018,11 +1034,11 @@

jsonOdm.Geo.edgeWithinPolygon = function (edge, polygon) {
if(!(jsonOdm.util.isArray(edge) && edge.length == 2 && jsonOdm.util.isArray(polygon) && polygon.length >= 2)) return false;
if (!(jsonOdm.util.isArray(edge) && edge.length == 2 && jsonOdm.util.isArray(polygon) && polygon.length >= 2)) return false;
// close the polygon
if(!(polygon[0][0] == polygon[polygon.length-1][0] && polygon[0][1] == polygon[polygon.length-1][1])) polygon = polygon.concat([polygon[0]]);
if(!jsonOdm.Geo.pointWithinPolygon(edge[0], polygon) || !jsonOdm.Geo.pointWithinPolygon(edge[1], polygon)) return false;
if (!(polygon[0][0] == polygon[polygon.length - 1][0] && polygon[0][1] == polygon[polygon.length - 1][1])) polygon = polygon.concat([polygon[0]]);
if (!jsonOdm.Geo.pointWithinPolygon(edge[0], polygon) || !jsonOdm.Geo.pointWithinPolygon(edge[1], polygon)) return false;
for(var i = 0; i < polygon.length - 1; i++){
for (var i = 0; i < polygon.length - 1; i++) {
// All points may be inside the polygon but their might be faces that are outside the polygon
if(jsonOdm.Geo.edgeIntersectsEdge(edge,[polygon[i],polygon[i+1]],false)){
if (jsonOdm.Geo.edgeIntersectsEdge(edge, [polygon[i], polygon[i + 1]], false)) {
return false;

@@ -1041,11 +1057,11 @@ }

jsonOdm.Geo.edgeIntersectsPolygon = function (edge, polygon) {
if(!(jsonOdm.util.isArray(edge) && edge.length == 2 && jsonOdm.util.isArray(polygon) && polygon.length >= 2)) return false;
if (!(jsonOdm.util.isArray(edge) && edge.length == 2 && jsonOdm.util.isArray(polygon) && polygon.length >= 2)) return false;
// close the polygon
if(!(polygon[0][0] == polygon[polygon.length-1][0] && polygon[0][1] == polygon[polygon.length-1][1])) polygon = polygon.concat([polygon[0]]);
if(jsonOdm.Geo.pointWithinPolygon(edge[0], polygon) || jsonOdm.Geo.pointWithinPolygon(edge[1], polygon)) return true;
if (!(polygon[0][0] == polygon[polygon.length - 1][0] && polygon[0][1] == polygon[polygon.length - 1][1])) polygon = polygon.concat([polygon[0]]);
if (jsonOdm.Geo.pointWithinPolygon(edge[0], polygon) || jsonOdm.Geo.pointWithinPolygon(edge[1], polygon)) return true;
for(var i = 0; i < polygon.length - 1; i++){
for (var i = 0; i < polygon.length - 1; i++) {
// All points may be outside the polygon but their might be faces that are inside the polygon
if(jsonOdm.Geo.edgeIntersectsEdge(edge,[polygon[i],polygon[i+1]])){
if (jsonOdm.Geo.edgeIntersectsEdge(edge, [polygon[i], polygon[i + 1]])) {
return true;

@@ -1064,5 +1080,5 @@ }

jsonOdm.Geo.edgeIntersectsLineString = function (edge, lineString) {
if(!(jsonOdm.util.isArray(edge) && edge.length == 2 && jsonOdm.util.isArray(lineString))) return false;
for(var i = 0; i < lineString.length - 1; i++){
if(jsonOdm.Geo.edgeIntersectsEdge(edge,[lineString[i],lineString[i+1]])){
if (!(jsonOdm.util.isArray(edge) && edge.length == 2 && jsonOdm.util.isArray(lineString))) return false;
for (var i = 0; i < lineString.length - 1; i++) {
if (jsonOdm.Geo.edgeIntersectsEdge(edge, [lineString[i], lineString[i + 1]])) {
return true;

@@ -1081,12 +1097,12 @@ }

*/
jsonOdm.Geo.edgeIntersectsEdge = function (edge1,edge2,allowOnEdge) {
jsonOdm.Geo.edgeIntersectsEdge = function (edge1, edge2, allowOnEdge) {
allowOnEdge = typeof allowOnEdge == "undefined" ? true : allowOnEdge;
var directionVector1 = [edge1[1][0]-edge1[0][0],edge1[1][1]-edge1[0][1]],
bounds1 = [Math.min(edge1[0][0],edge1[1][0]),Math.min(edge1[0][1],edge1[1][1]),Math.max(edge1[0][0],edge1[1][0]),Math.max(edge1[0][1],edge1[1][1])],
directionVector2 = [edge2[1][0]-edge2[0][0],edge2[1][1]-edge2[0][1]],
bounds2 = [Math.min(edge2[0][0],edge2[1][0]),Math.min(edge2[0][1],edge2[1][1]),Math.max(edge2[0][0],edge2[1][0]),Math.max(edge2[0][1],edge2[1][1])]
;
var directionVector1 = [edge1[1][0] - edge1[0][0], edge1[1][1] - edge1[0][1]],
bounds1 = [Math.min(edge1[0][0], edge1[1][0]), Math.min(edge1[0][1], edge1[1][1]), Math.max(edge1[0][0], edge1[1][0]), Math.max(edge1[0][1], edge1[1][1])],
directionVector2 = [edge2[1][0] - edge2[0][0], edge2[1][1] - edge2[0][1]],
bounds2 = [Math.min(edge2[0][0], edge2[1][0]), Math.min(edge2[0][1], edge2[1][1]), Math.max(edge2[0][0], edge2[1][0]), Math.max(edge2[0][1], edge2[1][1])]
;
// if not in bounds or if both edges are parallel with not intersection result
if(
if (
(bounds1[0] > bounds2[0] && bounds1[0] > bounds2[2]) || (bounds1[1] > bounds2[1] && bounds1[1] > bounds2[3]) ||

@@ -1098,14 +1114,14 @@ (bounds2[0] > bounds1[0] && bounds2[0] > bounds1[2]) || (bounds2[1] > bounds1[1] && bounds2[1] > bounds1[3])

if((directionVector2[0]*directionVector1[1] - directionVector1[0]*directionVector2[1]) == 0){
return allowOnEdge && edge1[0][1]+(((edge2[0][0]-edge1[0][0])/(directionVector1[0]))*(directionVector1[1])) == edge2[0][1];
if ((directionVector2[0] * directionVector1[1] - directionVector1[0] * directionVector2[1]) == 0) {
return allowOnEdge && edge1[0][1] + (((edge2[0][0] - edge1[0][0]) / (directionVector1[0])) * (directionVector1[1])) == edge2[0][1];
}
var t = (edge2[0][1]*(directionVector2[0]) + edge1[0][0]*(directionVector2[1]) - edge2[0][0]*(directionVector2[1]) - edge1[0][1]*(directionVector2[0])) / ((directionVector1[1])*(directionVector2[0])-(directionVector1[0])*(directionVector2[1])),
x = edge1[0][0] + (t*(directionVector1[0])),
y = edge1[0][1] + (t*(directionVector1[1]));
var t = (edge2[0][1] * (directionVector2[0]) + edge1[0][0] * (directionVector2[1]) - edge2[0][0] * (directionVector2[1]) - edge1[0][1] * (directionVector2[0])) / ((directionVector1[1]) * (directionVector2[0]) - (directionVector1[0]) * (directionVector2[1])),
x = edge1[0][0] + (t * (directionVector1[0])),
y = edge1[0][1] + (t * (directionVector1[1]));
// intersection needs to be inside the bounds
return allowOnEdge ?
(x >= bounds1[0] && x <= bounds1[2] && y >= bounds1[1] && y <= bounds1[3] && x >= bounds2[0] && x <= bounds2[2] && y >= bounds2[1] && y <= bounds2[3]) :
(x > bounds1[0] && x < bounds1[2] && y > bounds1[1] && y < bounds1[3] && x > bounds2[0] && x < bounds2[2] && y > bounds2[1] && y < bounds2[3]);
(x >= bounds1[0] && x <= bounds1[2] && y >= bounds1[1] && y <= bounds1[3] && x >= bounds2[0] && x <= bounds2[2] && y >= bounds2[1] && y <= bounds2[3]) :
(x > bounds1[0] && x < bounds1[2] && y > bounds1[1] && y < bounds1[3] && x > bounds2[0] && x < bounds2[2] && y > bounds2[1] && y < bounds2[3]);
};

@@ -1120,14 +1136,14 @@

jsonOdm.Geo.pointWithinLineString = function (point, lineString) {
if(!(jsonOdm.util.isArray(point) && jsonOdm.util.isArray(lineString) && lineString.length >= 2)) return false;
for(var i = 0; i < lineString.length - 1; i++) {
if(
if (!(jsonOdm.util.isArray(point) && jsonOdm.util.isArray(lineString) && lineString.length >= 2)) return false;
for (var i = 0; i < lineString.length - 1; i++) {
if (
// out of bounds check
(
(point[0] >= lineString[i][0] && point[0] <= lineString[i+1][0] && lineString[i][0] <= lineString[i+1][0]) ||
(point[0] <= lineString[i][0] && point[0] >= lineString[i+1][0] && lineString[i][0] >= lineString[i+1][0])
) &&
(
(point[1] >= lineString[i][1] && point[1] <= lineString[i+1][1] && lineString[i][1] <= lineString[i+1][1]) ||
(point[1] <= lineString[i][1] && point[1] >= lineString[i+1][1] && lineString[i][1] >= lineString[i+1][1])
)
(
(point[0] >= lineString[i][0] && point[0] <= lineString[i + 1][0] && lineString[i][0] <= lineString[i + 1][0]) ||
(point[0] <= lineString[i][0] && point[0] >= lineString[i + 1][0] && lineString[i][0] >= lineString[i + 1][0])
) &&
(
(point[1] >= lineString[i][1] && point[1] <= lineString[i + 1][1] && lineString[i][1] <= lineString[i + 1][1]) ||
(point[1] <= lineString[i][1] && point[1] >= lineString[i + 1][1] && lineString[i][1] >= lineString[i + 1][1])
)
) {

@@ -1137,7 +1153,7 @@ // point was on the current path

(lineString[i] [0] == point[0] && lineString[i] [1] == point[1]) ||
(lineString[i+1][0] == point[0] && lineString[i+1][1] == point[1]) ||
(lineString[i + 1][0] == point[0] && lineString[i + 1][1] == point[1]) ||
((lineString[i][1] - lineString[i + 1][1]) != 0 && ((lineString[i][0] - lineString[i + 1][0]) * ((point[1] - lineString[i+1][1]) / (lineString[i][1] - lineString[i + 1][1])) + lineString[i+1][0] == point[0])) ||
((lineString[i][0] - lineString[i + 1][0]) != 0 && ((lineString[i][1] - lineString[i + 1][1]) * ((point[0] - lineString[i+1][0]) / (lineString[i][0] - lineString[i + 1][0])) + lineString[i+1][1] == point[1]))
) return true;
((lineString[i][1] - lineString[i + 1][1]) != 0 && ((lineString[i][0] - lineString[i + 1][0]) * ((point[1] - lineString[i + 1][1]) / (lineString[i][1] - lineString[i + 1][1])) + lineString[i + 1][0] == point[0])) ||
((lineString[i][0] - lineString[i + 1][0]) != 0 && ((lineString[i][1] - lineString[i + 1][1]) * ((point[0] - lineString[i + 1][0]) / (lineString[i][0] - lineString[i + 1][0])) + lineString[i + 1][1] == point[1]))
) return true;
}

@@ -1155,3 +1171,3 @@ }

jsonOdm.Geo.pointWithinBounds = function (point, bounds) {
if(!(jsonOdm.util.isArray(point) && jsonOdm.util.isArray(bounds) && bounds.length == 4)) return false;
if (!(jsonOdm.util.isArray(point) && jsonOdm.util.isArray(bounds) && bounds.length == 4)) return false;
return point[0] >= bounds[0] && point[1] >= bounds[1] && point[0] <= bounds[2] && point[1] <= bounds[3];

@@ -1167,4 +1183,4 @@ };

jsonOdm.Geo.edgeIntersectsBounds = function (edge, bounds) {
if(!(jsonOdm.util.isArray(edge) && jsonOdm.util.isArray(bounds) && bounds.length == 4)) return false;
return jsonOdm.Geo.edgeIntersectsPolygon(edge,[[bounds[0],bounds[1]],[bounds[2],bounds[1]],[bounds[2],bounds[3]],[bounds[0],bounds[3]]]);
if (!(jsonOdm.util.isArray(edge) && jsonOdm.util.isArray(bounds) && bounds.length == 4)) return false;
return jsonOdm.Geo.edgeIntersectsPolygon(edge, [[bounds[0], bounds[1]], [bounds[2], bounds[1]], [bounds[2], bounds[3]], [bounds[0], bounds[3]]]);
};

@@ -1178,21 +1194,21 @@

*/
jsonOdm.Geo.lineStringWithinLineString = function (lineString,inLineString) {
if(!(jsonOdm.util.isArray(lineString) && jsonOdm.util.isArray(inLineString))) return false;
var i,j;
jsonOdm.Geo.lineStringWithinLineString = function (lineString, inLineString) {
if (!(jsonOdm.util.isArray(lineString) && jsonOdm.util.isArray(inLineString))) return false;
var i, j;
for (i = 0; lineString && i < lineString.length; i++) {
var found = false;
for (j = 0; inLineString && j < inLineString.length; j++) {
if(lineString[i][0] == inLineString[j][0] && lineString[i][1] == inLineString[j][1]){
if(i+1 == lineString.length){
if (lineString[i][0] == inLineString[j][0] && lineString[i][1] == inLineString[j][1]) {
if (i + 1 == lineString.length) {
return true; // we have successfully found the last matching line point
}
// the next vertex needs to match the next geometry point or the previous or the same again
if(
if (
!(
// next is not the next one
(inLineString[j+1] && lineString[i+1][0] == inLineString[j+1][0] && lineString[i+1][1] == inLineString[j+1][1]) ||
// next is not the same one
(lineString[i+1][0] == inLineString[j][0] && lineString[i+1][1] == inLineString[j][1]) ||
// next is not the previous one
(j > 0 && lineString[i+1][0] == inLineString[j-1][0] && lineString[i+1][1] == inLineString[j-1][1])
(inLineString[j + 1] && lineString[i + 1][0] == inLineString[j + 1][0] && lineString[i + 1][1] == inLineString[j + 1][1]) ||
// next is not the same one
(lineString[i + 1][0] == inLineString[j][0] && lineString[i + 1][1] == inLineString[j][1]) ||
// next is not the previous one
(j > 0 && lineString[i + 1][0] == inLineString[j - 1][0] && lineString[i + 1][1] == inLineString[j - 1][1])
)

@@ -1203,5 +1219,5 @@ ) return false;

}
if(!found) return false;
if (!found) return false;
}
return true;
};
"use strict";
/** @namespace jsonOdm.Query */
/**

@@ -27,2 +29,3 @@ * The query object that holds the collection to be queried

this.$$collection = collection || [];
this.$$accumulation = false;
};

@@ -40,14 +43,16 @@

jsonOdm.Query.prototype.$delete = function () {
if(this.$$commandQueue.length < 1) return this;
for(var i = 0; i < this.$$collection.length;){
if (this.$$commandQueue.length < 1) {
return this;
}
for (var i = 0; i < this.$$collection.length;) {
var validCollection = true;
for(var j = 0; j < this.$$commandQueue.length; j++){
if(!(validCollection = validCollection && this.$$commandQueue[j](this.$$collection[i]))){
for (var j = 0; j < this.$$commandQueue.length; j++) {
if (!(validCollection = validCollection && this.$$commandQueue[j](this.$$collection[i]))) {
break;
}
}
if(validCollection){
this.$$collection.splice(i,1);
}else{
i++
if (validCollection) {
this.$$collection.splice(i, 1);
} else {
i++;
}

@@ -69,24 +74,32 @@ }

*/
jsonOdm.Query.prototype.$result = function (start,length) {
if(this.$$commandQueue.length < 1 && this.$$aggregationBeforeCollectQueue < 1) return this.$$collection;
start = typeof start == "undefined" ? 0 : start;
length = typeof length == "undefined" ? this.$$collection.length : length;
jsonOdm.Query.prototype.$result = function (start, length) {
if (this.$$commandQueue.length < 1 && this.$$aggregationBeforeCollectQueue < 1) {
return this.$$collection;
}
start = typeof start === "undefined" ? 0 : start;
length = typeof length === "undefined" ? this.$$collection.length : length;
var filterCollection = new jsonOdm.Collection(),
resultingElement, i,j;
resultingElement, i, j;
for(i = 0; i < this.$$collection.length; i++){
for (i = 0; i < this.$$collection.length; i++) {
var validCollection = true;
for(j = 0; j < this.$$commandQueue.length; j++){
if(!(validCollection = validCollection && this.$$commandQueue[j](this.$$collection[i]))){
for (j = 0; j < this.$$commandQueue.length; j++) {
var commandResult = this.$$commandQueue[j](this.$$collection[i]);
if (!(validCollection = validCollection && commandResult !== null && commandResult !== false && typeof commandResult !== "undefined")) {
break;
}
}
if(validCollection){
if(start > 0) {start--;continue;}
if(length <= 0){return filterCollection}
if (validCollection) {
if (start > 0) {
start--;
continue;
}
if (length <= 0) {
return filterCollection;
}
resultingElement = this.$$collection[i];
for(j = 0; j < this.$$aggregationBeforeCollectQueue.length; j++){
resultingElement = this.$$aggregationBeforeCollectQueue[j](i,resultingElement);
for (j = 0; j < this.$$aggregationBeforeCollectQueue.length; j++) {
resultingElement = this.$$aggregationBeforeCollectQueue[j](i, resultingElement);
}

@@ -97,3 +110,3 @@ filterCollection.push(resultingElement);

}
for(i = 0; i < this.$$aggregationResultQueue.length; i++){
for (i = 0; i < this.$$aggregationResultQueue.length; i++) {
filterCollection = this.$$aggregationResultQueue[i](filterCollection);

@@ -122,3 +135,3 @@ }

jsonOdm.Query.prototype.$first = function () {
return this.$result(0,1)[0];
return this.$result(0, 1)[0];
};

@@ -135,14 +148,20 @@

*/
jsonOdm.Query.prototype.$aggregateCollection = function (afterValidation,beforeCollect,aggregation) {
var i;
if(typeof afterValidation == "function") afterValidation = [afterValidation];
if(typeof beforeCollect == "function") beforeCollect = [beforeCollect];
if(typeof aggregation == "function") aggregation = [aggregation];
if(jsonOdm.util.isArray(afterValidation)){
jsonOdm.Query.prototype.$aggregateCollection = function (afterValidation, beforeCollect, aggregation) {
if (typeof afterValidation === "function") {
afterValidation = [afterValidation];
}
if (typeof beforeCollect === "function") {
beforeCollect = [beforeCollect];
}
if (typeof aggregation === "function") {
aggregation = [aggregation];
}
if (jsonOdm.util.isArray(afterValidation)) {
this.$$commandQueue = this.$$commandQueue.concat(afterValidation);
}
if(jsonOdm.util.isArray(beforeCollect)){
if (jsonOdm.util.isArray(beforeCollect)) {
this.$$aggregationBeforeCollectQueue = this.$$aggregationBeforeCollectQueue.concat(beforeCollect);
}
if(jsonOdm.util.isArray(aggregation)){
if (jsonOdm.util.isArray(aggregation)) {
this.$$aggregationResultQueue = this.$$aggregationResultQueue.concat(aggregation);

@@ -154,5 +173,126 @@ }

/**
* Groups all elements of a collection by a given grouping schema
* @param {...jsonOdm.Query} by
* @return {jsonOdm.Query}
* @example
* var collection = new jsonOdm.Collection("employees");
* var $query = collection.$query();
* var groupedResult = $query.$and($query.$branch("age").$gt(21),$query.$branch("age").$lt(50)) // query before grouping
* .$group(
* "salaryRate", // as used with $branch
* ["salaryGroup","name"], // as used with $branch
* // A projection object defining the accumulation
* {
* missingDays:$query.$sum("daysAtHome"),
* holidayDays:$query.$sum("daysOnHoliday"),
* averageMissingDays:$query.$avg("daysAtHome"),
* averageHolidayDays:$query.$avg("daysOnHoliday"),
* count:$query.$count()
* }
* ).$all();
* // RESULT COULD BE
* // [
* // {"salaryRate":3300,"salaryGroup":{"name":"Developer"},"missingDays":22,"holidayDays":144,"averageMissingDays":11,"averageHolidayDays":72,$count:2},
* // {"salaryRate":2800,"salaryGroup":{"name":"Tester"} ,"missingDays":10,"holidayDays":66 ,"averageMissingDays":5, "averageHolidayDays":33,$count:2},
* // {"salaryRate":4800,"salaryGroup":{"name":"Boss"} ,"missingDays":12,"holidayDays":33 ,"averageMissingDays":12,"averageHolidayDays":33,$count:1}
* // ]
*/
jsonOdm.Query.prototype.$group = function (by) {
var orderBy = arguments;
var accumulationProjection = false;
var aggregationResult = [];
// last argument might be a projection
if (
arguments.length > 1 && !(jsonOdm.util.isArray(arguments[arguments.length - 1])) && !(jsonOdm.util.is(arguments[arguments.length - 1], "string")) &&
typeof arguments[arguments.length - 1] === "object"
) {
accumulationProjection = arguments[arguments.length - 1];
orderBy = Array.prototype.slice.call(arguments, 0, arguments.length - 1);
}
return this.$aggregateCollection(
(function (orderBy, aggregationResult) {
var valueVariations = {};
return function (collectionElement) {
// walk through the collection
var accumulationObject = {},
newValueVariation = false,
currentValueVariation = valueVariations,
value;
// create result sets matching the order by parameters
for (var i = 0; i < orderBy.length; i++) {
var currentOrderBy = jsonOdm.util.isArray(orderBy[i]) ? orderBy[i] : [orderBy[i]];
value = jsonOdm.util.branch(collectionElement, currentOrderBy);
if (i < orderBy.length - 1) {
if (typeof currentValueVariation["" + value] === "undefined") {
newValueVariation = true;
currentValueVariation["" + value] = {};
}
currentValueVariation = currentValueVariation["" + value];
}
var accumulationObjectBuffer = accumulationObject;
for (var j = 0; j < currentOrderBy.length - 1; j++) {
if (typeof accumulationObjectBuffer[currentOrderBy[j]] === "undefined") {
accumulationObjectBuffer[currentOrderBy[j]] = {};
}
accumulationObjectBuffer = accumulationObjectBuffer[currentOrderBy[j]];
}
accumulationObjectBuffer[currentOrderBy[currentOrderBy.length - 1]] = value;
}
if (!currentValueVariation["" + value]) {
// this valueVariation has not been found before
currentValueVariation["" + value] = {
accumulationObject: accumulationObject,
subResultSet: []
};
aggregationResult.push(currentValueVariation["" + value]);
}
currentValueVariation["" + value].subResultSet.push(collectionElement);
return true;
};
})(orderBy, aggregationResult),
null,
(function (aggregationResult, accumulationProjection) {
function falseQueryAccumulation(projection) {
for (var i in projection) {
if (!projection.hasOwnProperty(i)) {
continue;
}
if (projection[i] instanceof jsonOdm.Query) {
projection[i].$$accumulation = false;
}
if (typeof projection[i] === "object") {
falseQueryAccumulation(projection[i]);
}
}
}
return function () {
var resultCollection = new jsonOdm.Collection();
for (var i = 0; i < aggregationResult.length; i++) {
if (accumulationProjection === false) {
resultCollection.push(aggregationResult[i].accumulationObject);
} else {
falseQueryAccumulation(accumulationProjection);
var projectionResult = {};
for (var j = 0; j < aggregationResult[i].subResultSet.length; j++) {
projectionResult = jsonOdm.util.projectElement(accumulationProjection, aggregationResult[i].subResultSet[j]);
}
for (j in aggregationResult[i].accumulationObject) {
if (aggregationResult[i].accumulationObject.hasOwnProperty(j)) {
projectionResult[j] = aggregationResult[i].accumulationObject[j];
}
}
resultCollection.push(projectionResult);
}
}
return resultCollection;
};
})(aggregationResult, accumulationProjection));
};
/**
* Projects all elements of the collection into a given schema
* @param {*} projection The projection definition with nested definitions
* @return jsonOdm.Query
* @return {jsonOdm.Query}
* @example

@@ -173,8 +313,8 @@ * var collection = new jsonOdm.Collection("myBooks");

* copiesSold: $query.$branch("copies")
* })
*
* });
* var collectionResult = $query.$all();
*/
jsonOdm.Query.prototype.$project = function (projection) {
return this.$aggregateCollection(null, function (index,element) {
return jsonOdm.util.projectElement(projection,element)
return this.$aggregateCollection(null, function (index, element) {
return jsonOdm.util.projectElement(projection, element);
});

@@ -191,10 +331,12 @@ };

*/
jsonOdm.Query.prototype.$testCollection = function (comparables,collectionTest) {
jsonOdm.Query.prototype.$testCollection = function (comparables, collectionTest) {
var lastCommand = this.$$commandQueue.pop();
var $testCollection = (function () {
return function (collection) {
if(!((lastCommand instanceof jsonOdm.Collection || typeof lastCommand == "function" || typeof lastCommand == "undefined") && typeof collectionTest == "function")) return false;
var collectionValue = typeof lastCommand == "undefined"?collection:(lastCommand instanceof jsonOdm.Collection?lastCommand:lastCommand(collection));
return !!collectionTest(collectionValue,comparables);
}
if (!((lastCommand instanceof jsonOdm.Collection || typeof lastCommand === "function" || typeof lastCommand === "undefined") && typeof collectionTest === "function")) {
return false;
}
var collectionValue = typeof lastCommand === "undefined" ? collection : (lastCommand instanceof jsonOdm.Collection ? lastCommand : lastCommand(collection));
return !!collectionTest(collectionValue, comparables);
};
})();

@@ -211,13 +353,15 @@ this.$$commandQueue.push($testCollection);

*/
jsonOdm.Query.prototype.$queryOperator = function (queries,operator) {
var $testCollection = (function (queries,oprator) {
jsonOdm.Query.prototype.$queryOperator = function (queries, operator) {
var $testCollection = (function (queries, oprator) {
return function (collection) {
if(typeof oprator != "function") return false;
if (typeof oprator !== "function") {
return false;
}
var commandResults = [];
for(var i = 0; i < queries.length; i++){
if(queries[i] instanceof jsonOdm.Query){
for(var j = 0; j < queries[i].$$commandQueue.length; j++){
for (var i = 0; i < queries.length; i++) {
if (queries[i] instanceof jsonOdm.Query) {
for (var j = 0; j < queries[i].$$commandQueue.length; j++) {
commandResults.push(queries[i].$$commandQueue[j](collection));
}
}else{
} else {
// also accept raw values

@@ -228,4 +372,4 @@ commandResults.push(queries[i]);

return operator(commandResults);
}
})(queries,operator);
};
})(queries, operator);
var subQuery = new jsonOdm.Query(this.$$collection);

@@ -241,3 +385,3 @@ subQuery.$$commandQueue.push($testCollection);

jsonOdm.Query.prototype.$branch = function (node) {
var $branch = (function(nodes){
var $branch = (function (nodes) {
/**

@@ -247,4 +391,4 @@ * @param {*} The collection to go down

*/
return function(collection){
return jsonOdm.util.branch(collection,nodes);
return function (collection) {
return jsonOdm.util.branch(collection, nodes);
};

@@ -257,2 +401,4 @@ })(arguments);

// FIELD MODIFIER
/** Modify fields before validation

@@ -262,3 +408,3 @@ * @return {jsonOdm.Query}

jsonOdm.Query.prototype.$modifyField = function (modifier) {
var $modifyer = (function(modifier,lastCommand){
var $modifier = (function (modifier, lastCommand) {
/**

@@ -268,8 +414,8 @@ * @param {*} The collection to go down

*/
return function(collection){
collection = lastCommand!==null?lastCommand(collection):collection;
return typeof modifier == "function" ? modifier(collection) : collection;
return function (collection) {
collection = lastCommand !== null ? lastCommand(collection) : collection;
return typeof modifier === "function" ? modifier(collection) : collection;
};
})(modifier,this.$$commandQueue.length?this.$$commandQueue[this.$$commandQueue.length-1]:null);
this.$$commandQueue.push($modifyer);
})(modifier, this.$$commandQueue.length ? this.$$commandQueue[this.$$commandQueue.length - 1] : null);
this.$$commandQueue.push($modifier);
return this;

@@ -289,18 +435,171 @@ };

*/
jsonOdm.Query.stringFiledModifyer = ["charAt","charCodeAt","concat","fromCharCode","indexOf","lastIndexOf","localeCompare","match","replace","search","slice","split","substr","substring","toLocaleLowerCase","toLocaleUpperCase","toLowerCase","toUpperCase","trim","valueOf"];
for(var i = 0; i < jsonOdm.Query.stringFiledModifyer.length; i++){
jsonOdm.Query.prototype["$"+jsonOdm.Query.stringFiledModifyer[i]] = (
function (modifyer) {
jsonOdm.Query.stringFiledModifyer = ["charAt", "charCodeAt", "concat", "fromCharCode", "indexOf", "lastIndexOf", "localeCompare", "match", "replace", "search", "slice", "split", "substr", "substring", "toLocaleLowerCase", "toLocaleUpperCase", "toLowerCase", "toUpperCase", "trim", "valueOf"];
for (var i = 0; i < jsonOdm.Query.stringFiledModifyer.length; i++) {
jsonOdm.Query.prototype["$" + jsonOdm.Query.stringFiledModifyer[i]] = (function (modifyer) {
return function () {
return this.$modifyField((function (args,modifyer) {
return this.$modifyField((function (args, modifyer) {
return function (value) {
return typeof value == "string" && String.prototype.hasOwnProperty(modifyer)?String.prototype[modifyer].apply(value,args):value;
}
})(arguments,modifyer))
}
}
)(jsonOdm.Query.stringFiledModifyer[i]);
return typeof value === "string" && String.prototype.hasOwnProperty(modifyer) ? String.prototype[modifyer].apply(value, args) : value;
};
})(arguments, modifyer));
};
})(jsonOdm.Query.stringFiledModifyer[i]);
}
// ACCUMULATION FUNCTIONS
/** Go down the property tree of the collection
* @param {String[]} nodes A variable of nodes to traverse down the json tree
* @param {function} accumulator
* @return {jsonOdm.Query}
*/
jsonOdm.Query.prototype.$accumulator = function (nodes, accumulator) {
nodes = typeof nodes === "string" ? [nodes] : nodes;
var subQuery = new jsonOdm.Query(this.$$collection);
var $accumulator = (function (nodes, accumulator, query, parentQuery) {
/**
* @param {*} The collection to go down
* @return {Query|boolean} The query object with the sub collection or false if querying was impossible
*/
return function (collection) {
var value = nodes !== null ? jsonOdm.util.branch(collection, nodes) : nodes;
query.$$accumulation = accumulator(value, query.$$accumulation, collection);
parentQuery.$$accumulation = query.$$accumulation;
return value;
};
})(nodes, accumulator, subQuery, this);
subQuery.$$commandQueue.push($accumulator);
return subQuery;
};
/**
* Performs the accumulation sum of a field. It's integrated to be used with $group. May as well be used as stand alone.
* @param {...String} branch Internally calls the $branch method to receive the field values
* @return {jsonOdm.Query}
* @example
* // SHOULD BE USED WITH $group
* var collection = new jsonOdm.Collection("employees");
* var $query = collection.$query();
* $query.$sum("daysOff").$all();
* console.log($query.$$accumulation);
*/
jsonOdm.Query.prototype.$sum = function (branch) {
return this.$accumulator(branch, function (value, accumulation) {
if (accumulation === false) {
accumulation = 0;
}
return value + accumulation;
});
};
/**
* Performs the accumulation average of a field. It's integrated to be used with $group. May as well be used as stand alone.
* @param {...String} branch Internally calls the $branch method to receive the field values
* @return {jsonOdm.Query}
* @example
* // SHOULD BE USED WITH $group
* var collection = new jsonOdm.Collection("employees");
* var $query = collection.$query();
* $query.$avg("daysOff").$all();
* console.log($query.$$accumulation);
*/
jsonOdm.Query.prototype.$avg = function (branch) {
var count, sum;
return this.$accumulator(branch, function (value, accumulation) {
if (accumulation === false) {
count = 0;
sum = 0;
}
sum += value;
count++;
return sum / count;
});
};
/**
* Performs the accumulation max of a field. It's integrated to be used with $group. May as well be used as stand alone.
* @param {...String} branch Internally calls the $branch method to receive the field values
* @return {jsonOdm.Query}
* @example
* // SHOULD BE USED WITH $group
* var collection = new jsonOdm.Collection("employees");
* var $query = collection.$query();
* $query.$max("daysOff").$all();
* console.log($query.$$accumulation);
*/
jsonOdm.Query.prototype.$max = function (branch) {
return this.$accumulator(branch, function (value, accumulation) {
if (accumulation === false) {
accumulation = value;
}
return Math.max(value, accumulation);
});
};
/**
* Performs the accumulation min of a field. It's integrated to be used with $group. May as well be used as stand alone.
* @param {...String} branch Internally calls the $branch method to receive the field values
* @return {jsonOdm.Query}
* @example
* // SHOULD BE USED WITH $group
* var collection = new jsonOdm.Collection("employees");
* var $query = collection.$query();
* $query.$max("daysOff").$all();
* console.log($query.$$accumulation);
*/
jsonOdm.Query.prototype.$min = function (branch) {
return this.$accumulator(branch, function (value, accumulation) {
if (accumulation === false) {
accumulation = value;
}
return Math.min(value, accumulation);
});
};
/**
* Counts the grouped elements
* @return {jsonOdm.Query}
* @example
* // SHOULD BE USED WITH $group
* var collection = new jsonOdm.Collection("employees");
* var $query = collection.$count();
* $query.$count("daysOff").$all();
* expect(collection.length).toBe($query.$$accumulation);
*/
jsonOdm.Query.prototype.$count = function () {
return this.$accumulator(null, function (value, accumulation) {
if (accumulation === false) {
accumulation = 0;
}
return ++accumulation;
});
};
/**
* adds the grouped elements to result set
* @return {jsonOdm.Query}
* @example
* // SHOULD BE USED WITH $group
* var collection = new jsonOdm.Collection("employees");
* var $query = collection.$query();
* $query.$push("daysOff").$all()
* expect(collection.length).toBe($query.$$accumulation.length);
*/
jsonOdm.Query.prototype.$push = function () {
var subQuery = new jsonOdm.Query(this.$$collection);
var $push = (function (query, parentQuery) {
return function (collectionElement) {
query.$$accumulation = query.$$accumulation === false ? [] : query.$$accumulation;
query.$$accumulation.push(collectionElement);
parentQuery.$$accumulation = query.$$accumulation;
return true;
};
})(subQuery, this);
subQuery.$$commandQueue.push($push);
return subQuery;
};
// ARITHMETIC FUNCTIONS
/**
* Performs an arithmetic addition on two or more field values

@@ -324,3 +623,3 @@ * @param {jsonOdm.Query|Number} branch1

var result = queryResults.length > 0 ? queryResults[0] : 0;
for(var i = 1; i < queryResults.length; i++){
for (var i = 1; i < queryResults.length; i++) {
result += queryResults[i];

@@ -351,3 +650,3 @@ }

var result = queryResults.length > 0 ? queryResults[0] : 0;
for(var i = 1; i < queryResults.length; i++){
for (var i = 1; i < queryResults.length; i++) {
result -= queryResults[i];

@@ -378,3 +677,3 @@ }

var result = queryResults.length > 0 ? queryResults[0] : 0;
for(var i = 1; i < queryResults.length; i++){
for (var i = 1; i < queryResults.length; i++) {
result *= queryResults[i];

@@ -405,3 +704,3 @@ }

var result = queryResults.length > 0 ? queryResults[0] : 0;
for(var i = 1; i < queryResults.length; i++){
for (var i = 1; i < queryResults.length; i++) {
result /= queryResults[i];

@@ -432,3 +731,3 @@ }

var result = queryResults.length > 0 ? queryResults[0] : 0;
for(var i = 1; i < queryResults.length; i++){
for (var i = 1; i < queryResults.length; i++) {
result = result % queryResults[i];

@@ -447,4 +746,8 @@ }

jsonOdm.Query.prototype.$eq = function (comparable) {
return this.$testCollection(arguments,function (collectionValue, possibleValues) {
for(var i = 0; i < possibleValues.length; i++) if(possibleValues[i] == collectionValue) return true;
return this.$testCollection(arguments, function (collectionValue, possibleValues) {
for (var i = 0; i < possibleValues.length; i++) {
if (possibleValues[i] === collectionValue) {
return true;
}
}
return false;

@@ -461,4 +764,8 @@ });

jsonOdm.Query.prototype.$in = function (comparable) {
return this.$testCollection(comparable,function (collectionValue, possibleValues) {
for(var i = 0; i < possibleValues.length; i++) if(possibleValues[i] == collectionValue) return true;
return this.$testCollection(comparable, function (collectionValue, possibleValues) {
for (var i = 0; i < possibleValues.length; i++) {
if (possibleValues[i] === collectionValue) {
return true;
}
}
return false;

@@ -476,3 +783,7 @@ });

return this.$testCollection(arguments, function (collectionValue, possibleValues) {
for(var i = 0; i < possibleValues.length; i++) if(possibleValues[i] == collectionValue) return false;
for (var i = 0; i < possibleValues.length; i++) {
if (possibleValues[i] === collectionValue) {
return false;
}
}
return true;

@@ -490,3 +801,7 @@ });

return this.$testCollection(comparable, function (collectionValue, possibleValues) {
for(var i = 0; i < possibleValues.length; i++) if(possibleValues[i] == collectionValue) return false;
for (var i = 0; i < possibleValues.length; i++) {
if (possibleValues[i] === collectionValue) {
return false;
}
}
return true;

@@ -550,3 +865,3 @@ });

return this.$testCollection(null, function (collectionValue) {
return typeof collectionValue == 'undefined' || collectionValue === null;
return typeof collectionValue === 'undefined' || collectionValue === null;
});

@@ -579,3 +894,3 @@ };

return this.$testCollection(arguments, function (collectionValue, possibleTypes) {
return jsonOdm.util.is(collectionValue,possibleTypes);
return jsonOdm.util.is(collectionValue, possibleTypes);
});

@@ -594,5 +909,5 @@ };

*/
jsonOdm.Query.prototype.$mod = function (divisor,remainder) {
return this.$testCollection(arguments, function (collectionValue,args) {
return collectionValue % args[0] == args[1];
jsonOdm.Query.prototype.$mod = function (divisor, remainder) {
return this.$testCollection(arguments, function (collectionValue, args) {
return collectionValue % args[0] === args[1];
});

@@ -619,5 +934,7 @@ };

*/
jsonOdm.Query.prototype.$regex = function (regex,options) {
if(typeof regex == "string") regex = typeof options == "string" ? new RegExp(regex,options) : new RegExp(regex);
return this.$testCollection(regex, function (collectionValue,regex) {
jsonOdm.Query.prototype.$regex = function (regex, options) {
if (typeof regex === "string") {
regex = typeof options === "string" ? new RegExp(regex, options) : new RegExp(regex);
}
return this.$testCollection(regex, function (collectionValue, regex) {
return regex.test(collectionValue);

@@ -641,25 +958,31 @@ });

var andRegExp = /"([^"]+)"/g;
var nots = [],ands = [];
var notMatches,andMatches;
var nots = [], ands = [];
var notMatches, andMatches;
while ((notMatches = notRegExp.exec(text)) !== null) {
nots.push(notMatches[2]);
}
text = text.replace(notRegExp,"");
text = text.replace(notRegExp, "");
while ((andMatches = andRegExp.exec(text)) !== null) {
ands.push(andMatches[1]);
}
text = text.replace(andRegExp,"");
text = text.replace(andRegExp, "");
var ors = text.split(" ");
return this.$testCollection([nots,ands,ors], function (collectionValue,logics) {
return this.$testCollection([nots, ands, ors], function (collectionValue, logics) {
// nots
for(var i = 0;i < logics[0].length; i++){
if(collectionValue.indexOf(logics[0][i]) > -1) return false;
for (var i = 0; i < logics[0].length; i++) {
if (collectionValue.indexOf(logics[0][i]) > -1) {
return false;
}
}
// ands
for(i = 0;i < logics[1].length; i++){
if(collectionValue.indexOf(logics[1][i]) < 0) return false;
for (i = 0; i < logics[1].length; i++) {
if (collectionValue.indexOf(logics[1][i]) < 0) {
return false;
}
}
// ors
for(i = 0; i < logics[2].length; i++){
if(collectionValue.indexOf(logics[2][i]) > -1) return true;
for (i = 0; i < logics[2].length; i++) {
if (collectionValue.indexOf(logics[2][i]) > -1) {
return true;
}
}

@@ -674,3 +997,3 @@ // if there are no ors, matching all ands is enough

* @example
* // using a string to find Harry
* // !!!! NOT SUPPORTED ANYMORE !!!! using a string to find Harry
* collection.$query().$where("return this.name == 'Harry';").$first();

@@ -685,7 +1008,6 @@ * // using a function to find Harry

jsonOdm.Query.prototype.$where = function (evaluation) {
if(typeof evaluation == "string"){
evaluation = new Function(evaluation);
}
return this.$testCollection(evaluation, function (collectionValue,evaluation) {
if(typeof evaluation != "function") return false;
return this.$testCollection(evaluation, function (collectionValue, evaluation) {
if (typeof evaluation !== "function") {
return false;
}
return evaluation.apply(collectionValue);

@@ -736,4 +1058,4 @@ });

jsonOdm.Query.prototype.$geoWithin = function (geometry) {
return this.$testCollection(jsonOdm.Geo.detectAsGeometry(geometry), function (collectionValue,geometry) {
return jsonOdm.Geo[collectionValue.type] && jsonOdm.Geo[collectionValue.type].within && jsonOdm.Geo[collectionValue.type].within(collectionValue,geometry);
return this.$testCollection(jsonOdm.Geo.detectAsGeometry(geometry), function (collectionValue, geometry) {
return jsonOdm.Geo[collectionValue.type] && jsonOdm.Geo[collectionValue.type].within && jsonOdm.Geo[collectionValue.type].within(collectionValue, geometry);
});

@@ -782,4 +1104,4 @@ };

jsonOdm.Query.prototype.$geoIntersects = function (geometry) {
return this.$testCollection(jsonOdm.Geo.detectAsGeometry(geometry), function (collectionValue,geometry) {
return jsonOdm.Geo[collectionValue.type] && jsonOdm.Geo[collectionValue.type].intersects && jsonOdm.Geo[collectionValue.type].intersects(collectionValue,geometry);
return this.$testCollection(jsonOdm.Geo.detectAsGeometry(geometry), function (collectionValue, geometry) {
return jsonOdm.Geo[collectionValue.type] && jsonOdm.Geo[collectionValue.type].intersects && jsonOdm.Geo[collectionValue.type].intersects(collectionValue, geometry);
});

@@ -797,4 +1119,6 @@ };

return this.$queryOperator(arguments, function (queryResults) {
for(var i = 0; i < queryResults.length; i++){
if(!queryResults[i]) return false;
for (var i = 0; i < queryResults.length; i++) {
if (!queryResults[i]) {
return false;
}
}

@@ -813,4 +1137,6 @@ return true;

return this.$queryOperator(arguments, function (queryResults) {
for(var i = 0; i < queryResults.length; i++){
if(!queryResults[i]) return true;
for (var i = 0; i < queryResults.length; i++) {
if (!queryResults[i]) {
return true;
}
}

@@ -840,4 +1166,6 @@ return false;

return this.$queryOperator(arguments, function (queryResults) {
for(var i = 0; i < queryResults.length; i++){
if(queryResults[i]) return true;
for (var i = 0; i < queryResults.length; i++) {
if (queryResults[i]) {
return true;
}
}

@@ -856,4 +1184,6 @@ return false;

return this.$queryOperator(arguments, function (queryResults) {
for(var i = 0; i < queryResults.length; i++){
if(queryResults[i]) return false;
for (var i = 0; i < queryResults.length; i++) {
if (queryResults[i]) {
return false;
}
}

@@ -860,0 +1190,0 @@ return true;

@@ -136,2 +136,3 @@ "use strict";

projectionResult[key] = projection[key].$$commandQueue[projection[key].$$commandQueue.length-1](element);
if(projection[key].$$accumulation !== false) projectionResult[key] = projection[key].$$accumulation;
}else if(typeof projection[key] === 'object'){

@@ -138,0 +139,0 @@ projectionResult[key] = this.projectElement(projection[key],element[key],parentElement || element);

@@ -29,2 +29,712 @@ describe("Collection", function () {

],
// generated with http://www.generatedata.com/
"employees":[
{
"name": "Alec Velez",
"salaryGroupId": 4,
"holidayDaysTaken": 13,
"daysOff": 9,
"extraHoursWorked": 17
},
{
"name": "Evan Leach",
"salaryGroupId": 2,
"holidayDaysTaken": 6,
"daysOff": 6,
"extraHoursWorked": 78
},
{
"name": "Amela Sanchez",
"salaryGroupId": 2,
"holidayDaysTaken": 0,
"daysOff": 2,
"extraHoursWorked": 77
},
{
"name": "Jin Hoover",
"salaryGroupId": 3,
"holidayDaysTaken": 23,
"daysOff": 3,
"extraHoursWorked": 16
},
{
"name": "Palmer Velasquez",
"salaryGroupId": 1,
"holidayDaysTaken": 23,
"daysOff": 10,
"extraHoursWorked": 6
},
{
"name": "Tanya Grant",
"salaryGroupId": 2,
"holidayDaysTaken": 14,
"daysOff": 10,
"extraHoursWorked": 62
},
{
"name": "Reuben Carrillo",
"salaryGroupId": 4,
"holidayDaysTaken": 4,
"daysOff": 8,
"extraHoursWorked": 44
},
{
"name": "Cleo Peterson",
"salaryGroupId": 1,
"holidayDaysTaken": 17,
"daysOff": 5,
"extraHoursWorked": 30
},
{
"name": "Michael Blanchard",
"salaryGroupId": 5,
"holidayDaysTaken": 5,
"daysOff": 3,
"extraHoursWorked": 20
},
{
"name": "Martena Conley",
"salaryGroupId": 1,
"holidayDaysTaken": 20,
"daysOff": 6,
"extraHoursWorked": 0
},
{
"name": "Quentin Alston",
"salaryGroupId": 2,
"holidayDaysTaken": 23,
"daysOff": 2,
"extraHoursWorked": 78
},
{
"name": "Quinlan Livingston",
"salaryGroupId": 3,
"holidayDaysTaken": 19,
"daysOff": 8,
"extraHoursWorked": 27
},
{
"name": "Ayanna Norris",
"salaryGroupId": 1,
"holidayDaysTaken": 9,
"daysOff": 9,
"extraHoursWorked": 67
},
{
"name": "Amela Wolfe",
"salaryGroupId": 1,
"holidayDaysTaken": 4,
"daysOff": 1,
"extraHoursWorked": 68
},
{
"name": "Cherokee Beach",
"salaryGroupId": 2,
"holidayDaysTaken": 0,
"daysOff": 9,
"extraHoursWorked": 18
},
{
"name": "Clayton Wiley",
"salaryGroupId": 3,
"holidayDaysTaken": 3,
"daysOff": 10,
"extraHoursWorked": 57
},
{
"name": "Anika Gonzales",
"salaryGroupId": 3,
"holidayDaysTaken": 3,
"daysOff": 10,
"extraHoursWorked": 63
},
{
"name": "Irma Goodwin",
"salaryGroupId": 4,
"holidayDaysTaken": 23,
"daysOff": 3,
"extraHoursWorked": 4
},
{
"name": "Jin Eaton",
"salaryGroupId": 2,
"holidayDaysTaken": 15,
"daysOff": 4,
"extraHoursWorked": 36
},
{
"name": "Ursa Mcgowan",
"salaryGroupId": 4,
"holidayDaysTaken": 11,
"daysOff": 8,
"extraHoursWorked": 43
},
{
"name": "Sacha Hernandez",
"salaryGroupId": 5,
"holidayDaysTaken": 15,
"daysOff": 10,
"extraHoursWorked": 24
},
{
"name": "Emerson Roberson",
"salaryGroupId": 3,
"holidayDaysTaken": 2,
"daysOff": 3,
"extraHoursWorked": 60
},
{
"name": "Giselle Scott",
"salaryGroupId": 4,
"holidayDaysTaken": 24,
"daysOff": 6,
"extraHoursWorked": 73
},
{
"name": "Rina Gallagher",
"salaryGroupId": 2,
"holidayDaysTaken": 8,
"daysOff": 7,
"extraHoursWorked": 45
},
{
"name": "Mason Peters",
"salaryGroupId": 3,
"holidayDaysTaken": 1,
"daysOff": 5,
"extraHoursWorked": 53
},
{
"name": "Haviva Smith",
"salaryGroupId": 1,
"holidayDaysTaken": 0,
"daysOff": 7,
"extraHoursWorked": 13
},
{
"name": "Lois Lyons",
"salaryGroupId": 4,
"holidayDaysTaken": 11,
"daysOff": 9,
"extraHoursWorked": 61
},
{
"name": "Latifah Powell",
"salaryGroupId": 5,
"holidayDaysTaken": 10,
"daysOff": 4,
"extraHoursWorked": 52
},
{
"name": "Gloria Gilmore",
"salaryGroupId": 4,
"holidayDaysTaken": 3,
"daysOff": 6,
"extraHoursWorked": 34
},
{
"name": "Rajah Gross",
"salaryGroupId": 2,
"holidayDaysTaken": 22,
"daysOff": 5,
"extraHoursWorked": 23
},
{
"name": "Sybill Brooks",
"salaryGroupId": 5,
"holidayDaysTaken": 21,
"daysOff": 4,
"extraHoursWorked": 78
},
{
"name": "Stephanie Sandoval",
"salaryGroupId": 3,
"holidayDaysTaken": 1,
"daysOff": 6,
"extraHoursWorked": 30
},
{
"name": "Maris Juarez",
"salaryGroupId": 5,
"holidayDaysTaken": 5,
"daysOff": 1,
"extraHoursWorked": 2
},
{
"name": "Demetrius Acosta",
"salaryGroupId": 2,
"holidayDaysTaken": 11,
"daysOff": 3,
"extraHoursWorked": 44
},
{
"name": "Chadwick Heath",
"salaryGroupId": 1,
"holidayDaysTaken": 6,
"daysOff": 7,
"extraHoursWorked": 25
},
{
"name": "Moana Murphy",
"salaryGroupId": 4,
"holidayDaysTaken": 0,
"daysOff": 5,
"extraHoursWorked": 68
},
{
"name": "Britanni Campos",
"salaryGroupId": 1,
"holidayDaysTaken": 0,
"daysOff": 9,
"extraHoursWorked": 43
},
{
"name": "Mari Watkins",
"salaryGroupId": 2,
"holidayDaysTaken": 10,
"daysOff": 8,
"extraHoursWorked": 43
},
{
"name": "Mikayla Goff",
"salaryGroupId": 1,
"holidayDaysTaken": 6,
"daysOff": 8,
"extraHoursWorked": 2
},
{
"name": "Samantha Duke",
"salaryGroupId": 3,
"holidayDaysTaken": 15,
"daysOff": 7,
"extraHoursWorked": 56
},
{
"name": "Zeph Baird",
"salaryGroupId": 5,
"holidayDaysTaken": 0,
"daysOff": 2,
"extraHoursWorked": 57
},
{
"name": "Kyra Hale",
"salaryGroupId": 5,
"holidayDaysTaken": 2,
"daysOff": 2,
"extraHoursWorked": 26
},
{
"name": "Kelsie Montoya",
"salaryGroupId": 3,
"holidayDaysTaken": 17,
"daysOff": 0,
"extraHoursWorked": 71
},
{
"name": "Rooney Buck",
"salaryGroupId": 1,
"holidayDaysTaken": 0,
"daysOff": 1,
"extraHoursWorked": 49
},
{
"name": "Chaney Bernard",
"salaryGroupId": 1,
"holidayDaysTaken": 22,
"daysOff": 7,
"extraHoursWorked": 5
},
{
"name": "Samantha White",
"salaryGroupId": 1,
"holidayDaysTaken": 23,
"daysOff": 6,
"extraHoursWorked": 49
},
{
"name": "Talon Downs",
"salaryGroupId": 4,
"holidayDaysTaken": 24,
"daysOff": 4,
"extraHoursWorked": 54
},
{
"name": "Kimberley Trujillo",
"salaryGroupId": 4,
"holidayDaysTaken": 19,
"daysOff": 5,
"extraHoursWorked": 11
},
{
"name": "Ross Hyde",
"salaryGroupId": 5,
"holidayDaysTaken": 0,
"daysOff": 4,
"extraHoursWorked": 46
},
{
"name": "Indigo Shelton",
"salaryGroupId": 1,
"holidayDaysTaken": 19,
"daysOff": 10,
"extraHoursWorked": 25
},
{
"name": "Alisa Sears",
"salaryGroupId": 5,
"holidayDaysTaken": 8,
"daysOff": 3,
"extraHoursWorked": 79
},
{
"name": "Leigh Koch",
"salaryGroupId": 2,
"holidayDaysTaken": 5,
"daysOff": 5,
"extraHoursWorked": 24
},
{
"name": "Stone Mathis",
"salaryGroupId": 5,
"holidayDaysTaken": 21,
"daysOff": 9,
"extraHoursWorked": 15
},
{
"name": "Jemima English",
"salaryGroupId": 3,
"holidayDaysTaken": 1,
"daysOff": 2,
"extraHoursWorked": 59
},
{
"name": "Aline Cochran",
"salaryGroupId": 1,
"holidayDaysTaken": 10,
"daysOff": 6,
"extraHoursWorked": 16
},
{
"name": "Stella Boone",
"salaryGroupId": 2,
"holidayDaysTaken": 19,
"daysOff": 4,
"extraHoursWorked": 5
},
{
"name": "Tamara House",
"salaryGroupId": 1,
"holidayDaysTaken": 22,
"daysOff": 6,
"extraHoursWorked": 59
},
{
"name": "Blaine Foreman",
"salaryGroupId": 2,
"holidayDaysTaken": 23,
"daysOff": 5,
"extraHoursWorked": 63
},
{
"name": "Michael Travis",
"salaryGroupId": 2,
"holidayDaysTaken": 11,
"daysOff": 6,
"extraHoursWorked": 17
},
{
"name": "Travis Morrow",
"salaryGroupId": 3,
"holidayDaysTaken": 24,
"daysOff": 9,
"extraHoursWorked": 44
},
{
"name": "Angelica Fulton",
"salaryGroupId": 2,
"holidayDaysTaken": 7,
"daysOff": 2,
"extraHoursWorked": 44
},
{
"name": "Libby Clements",
"salaryGroupId": 1,
"holidayDaysTaken": 8,
"daysOff": 9,
"extraHoursWorked": 30
},
{
"name": "Nerea Dean",
"salaryGroupId": 5,
"holidayDaysTaken": 12,
"daysOff": 1,
"extraHoursWorked": 67
},
{
"name": "Alexa Eaton",
"salaryGroupId": 5,
"holidayDaysTaken": 10,
"daysOff": 6,
"extraHoursWorked": 35
},
{
"name": "Edward Vincent",
"salaryGroupId": 2,
"holidayDaysTaken": 6,
"daysOff": 3,
"extraHoursWorked": 29
},
{
"name": "Noel Santana",
"salaryGroupId": 1,
"holidayDaysTaken": 8,
"daysOff": 5,
"extraHoursWorked": 73
},
{
"name": "Shelby Stanton",
"salaryGroupId": 1,
"holidayDaysTaken": 13,
"daysOff": 3,
"extraHoursWorked": 31
},
{
"name": "Reuben Dillon",
"salaryGroupId": 3,
"holidayDaysTaken": 14,
"daysOff": 6,
"extraHoursWorked": 20
},
{
"name": "Quyn Alford",
"salaryGroupId": 4,
"holidayDaysTaken": 5,
"daysOff": 10,
"extraHoursWorked": 65
},
{
"name": "Aaron Matthews",
"salaryGroupId": 3,
"holidayDaysTaken": 6,
"daysOff": 10,
"extraHoursWorked": 79
},
{
"name": "Inga Austin",
"salaryGroupId": 2,
"holidayDaysTaken": 10,
"daysOff": 0,
"extraHoursWorked": 49
},
{
"name": "Lydia Madden",
"salaryGroupId": 4,
"holidayDaysTaken": 12,
"daysOff": 2,
"extraHoursWorked": 7
},
{
"name": "Herrod Riddle",
"salaryGroupId": 2,
"holidayDaysTaken": 9,
"daysOff": 10,
"extraHoursWorked": 64
},
{
"name": "Odysseus Petty",
"salaryGroupId": 1,
"holidayDaysTaken": 24,
"daysOff": 5,
"extraHoursWorked": 39
},
{
"name": "Fitzgerald Lee",
"salaryGroupId": 3,
"holidayDaysTaken": 22,
"daysOff": 5,
"extraHoursWorked": 38
},
{
"name": "Barbara Tucker",
"salaryGroupId": 2,
"holidayDaysTaken": 22,
"daysOff": 5,
"extraHoursWorked": 59
},
{
"name": "Rhoda Jensen",
"salaryGroupId": 4,
"holidayDaysTaken": 2,
"daysOff": 5,
"extraHoursWorked": 44
},
{
"name": "Jackson Chase",
"salaryGroupId": 4,
"holidayDaysTaken": 12,
"daysOff": 5,
"extraHoursWorked": 42
},
{
"name": "Roth Jackson",
"salaryGroupId": 4,
"holidayDaysTaken": 16,
"daysOff": 1,
"extraHoursWorked": 27
},
{
"name": "Reuben Macdonald",
"salaryGroupId": 3,
"holidayDaysTaken": 14,
"daysOff": 2,
"extraHoursWorked": 52
},
{
"name": "Knox Shaw",
"salaryGroupId": 4,
"holidayDaysTaken": 3,
"daysOff": 3,
"extraHoursWorked": 53
},
{
"name": "Silas Mcdowell",
"salaryGroupId": 1,
"holidayDaysTaken": 7,
"daysOff": 1,
"extraHoursWorked": 71
},
{
"name": "Eve Durham",
"salaryGroupId": 5,
"holidayDaysTaken": 21,
"daysOff": 0,
"extraHoursWorked": 8
},
{
"name": "May Peck",
"salaryGroupId": 5,
"holidayDaysTaken": 1,
"daysOff": 0,
"extraHoursWorked": 42
},
{
"name": "Brent Gay",
"salaryGroupId": 1,
"holidayDaysTaken": 10,
"daysOff": 7,
"extraHoursWorked": 77
},
{
"name": "Naida Burris",
"salaryGroupId": 2,
"holidayDaysTaken": 12,
"daysOff": 0,
"extraHoursWorked": 61
},
{
"name": "Paloma Langley",
"salaryGroupId": 2,
"holidayDaysTaken": 9,
"daysOff": 1,
"extraHoursWorked": 44
},
{
"name": "Lewis Vega",
"salaryGroupId": 5,
"holidayDaysTaken": 21,
"daysOff": 3,
"extraHoursWorked": 65
},
{
"name": "Macaulay Stout",
"salaryGroupId": 2,
"holidayDaysTaken": 14,
"daysOff": 7,
"extraHoursWorked": 63
},
{
"name": "Yvette Cruz",
"salaryGroupId": 4,
"holidayDaysTaken": 11,
"daysOff": 3,
"extraHoursWorked": 36
},
{
"name": "Shelley Best",
"salaryGroupId": 2,
"holidayDaysTaken": 4,
"daysOff": 6,
"extraHoursWorked": 24
},
{
"name": "Louis Pennington",
"salaryGroupId": 4,
"holidayDaysTaken": 8,
"daysOff": 6,
"extraHoursWorked": 47
},
{
"name": "Kibo Chen",
"salaryGroupId": 5,
"holidayDaysTaken": 13,
"daysOff": 4,
"extraHoursWorked": 60
},
{
"name": "Stacey Burnett",
"salaryGroupId": 5,
"holidayDaysTaken": 21,
"daysOff": 4,
"extraHoursWorked": 71
},
{
"name": "Virginia Kidd",
"salaryGroupId": 4,
"holidayDaysTaken": 13,
"daysOff": 1,
"extraHoursWorked": 9
},
{
"name": "Gisela Moore",
"salaryGroupId": 4,
"holidayDaysTaken": 24,
"daysOff": 1,
"extraHoursWorked": 16
},
{
"name": "Serina Reyes",
"salaryGroupId": 1,
"holidayDaysTaken": 3,
"daysOff": 7,
"extraHoursWorked": 20
},
{
"name": "Brody Keller",
"salaryGroupId": 1,
"holidayDaysTaken": 1,
"daysOff": 0,
"extraHoursWorked": 80
},
{
"name": "Ralph Mcdonald",
"salaryGroupId": 3,
"holidayDaysTaken": 20,
"daysOff": 2,
"extraHoursWorked": 0
},
{
"name": "Sharon Hayden",
"salaryGroupId": 4,
"holidayDaysTaken": 24,
"daysOff": 1,
"extraHoursWorked": 21
}
],
"salaryGroup":[
{id:1,name:"Trainee",salary:"1400€"},
{id:2,name:"Junior",salary:"2100€"},
{id:3,name:"General",salary:"2600€"},
{id:4,name:"Senior",salary:"3200€"},
{id:5,name:"Master",salary:"4800€"}
],
"arithmeticCollection":[

@@ -358,2 +1068,78 @@ {id:1,cars:12,trucks:23,bikes:8},

});
describe("Accumulation operators", function () {
var collection, q;
beforeEach(function () {
collection = new jsonOdm.Collection("employees");
collection.$hasOne("id","salaryGroupId","salaryGroup");
q = collection.$query();
});
it("Should group the collection by fields", function () {
var grouped = q.$group(
"salaryGroupId",
["salaryGroup","name"],
"daysOff",
{
"allExtraHours":q.$sum("extraHoursWorked"),
"allDaysOff":q.$sum("daysOff"),
"elements": q.$push(),
"count":q.$count()
}
).$all();
for(var i = 0; i < grouped.length; i++){
expect(grouped[i].count).toBe(grouped[i].elements.length);
expect(grouped[i].count * grouped[i].daysOff).toBe(grouped[i].allDaysOff);
var allExtraHoursWorked = 0;
for(var j = 0; j < grouped[i].elements.length; j++){
allExtraHoursWorked += grouped[i].elements[j].extraHoursWorked;
expect(grouped[i].salaryGroup.name).toBe(grouped[i].elements[j].salaryGroup.name);
}
expect(allExtraHoursWorked).toBe(grouped[i].allExtraHours);
}
});
it("Should sum up a field", function () {
// sum up manually
var expectedSum = 0;
for(var i = 0; i < testSource.employees.length; i++){
expectedSum += testSource.employees[i].daysOff;
}
q.$sum("daysOff").$all();
expect(expectedSum).toBe(q.$$accumulation);
});
it("Should get the average of a field", function () {
// sum up manually
var sum = 0;
for(var i = 0; i < testSource.employees.length; i++){
sum += testSource.employees[i].daysOff;
}
var subQ = q.$avg("daysOff");
subQ.$all();
expect(sum/testSource.employees.length).toBe(subQ.$$accumulation);
});
it("Should get the maximum of a field", function () {
// sum up manually
var max = 0;
for(var i = 0; i < testSource.employees.length; i++){
max = Math.max(max,testSource.employees[i].daysOff);
}
q.$max("daysOff").$all();
expect(max).toBe(q.$$accumulation);
});
it("Should get the maximum of a field", function () {
// sum up manually
var min = 0;
for(var i = 0; i < testSource.employees.length; i++){
min = Math.min(min,testSource.employees[i].daysOff);
}
q.$min("daysOff").$all();
expect(min).toBe(q.$$accumulation);
});
it("Should count all elements", function () {
q.$count().$all();
expect(collection.length).toBe(q.$$accumulation);
});
it("Should count all elements", function () {
q.$push().$all();
expect(collection.length).toBe(q.$$accumulation.length);
});
});
describe("Arithmetic operators", function () {

@@ -469,6 +1255,6 @@ var collection, q;

it("Should find all english rules",function(){
expect(collection.$query().$where("return this.lang == 'en'").$all().length).toBe(2);
expect(collection.$query().$where("return this.lang == 'en'").$all().length).toBe(0);
});
it("Should find first english rules",function(){
expect(collection.$query().$where("return this.lang == 'en'").$first().id).toBe(1);
expect(collection.$query().$where("return this.lang == 'en'").$first()).toBeUndefined();
});

@@ -484,3 +1270,3 @@ it("Should find all english rules",function(){

});
})
});
describe("Delete elements", function () {

@@ -487,0 +1273,0 @@ var collection = new jsonOdm.Collection("aLot");

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc