diff --git a/modules/behavior/lasso.js b/modules/behavior/lasso.js index 92ce6b46bb..bf91bc0e09 100644 --- a/modules/behavior/lasso.js +++ b/modules/behavior/lasso.js @@ -1,6 +1,8 @@ import { select as d3_select } from 'd3-selection'; -import { geoExtent, geoPointInPolygon } from '../geo'; +import { geoPointInPolygon } from '../geo'; +import { Extent } from '@id-sdk/extent'; + import { modeSelect } from '../modes/select'; import { uiLasso } from '../ui/lasso'; import { utilArrayIntersection } from '../util/array'; @@ -62,7 +64,7 @@ export function behaviorLasso(context) { } var bounds = lasso.extent().map(context.projection.invert); - var extent = geoExtent(normalize(bounds[0], bounds[1])); + var extent = new Extent(normalize(bounds[0], bounds[1])); var intersects = context.history().intersects(extent).filter(function(entity) { return entity.type === 'node' && diff --git a/modules/behavior/paste.js b/modules/behavior/paste.js index e075f6dba4..70f266600c 100644 --- a/modules/behavior/paste.js +++ b/modules/behavior/paste.js @@ -1,6 +1,7 @@ import { actionCopyEntities } from '../actions/copy_entities'; import { actionMove } from '../actions/move'; -import { geoExtent, geoPointInPolygon, geoVecSubtract } from '../geo'; +import { geoPointInPolygon, geoVecSubtract } from '../geo'; +import { Extent } from '@id-sdk/extent'; import { modeMove } from '../modes/move'; import { uiCmd } from '../ui/cmd'; @@ -16,14 +17,14 @@ export function behaviorPaste(context) { var baseGraph = context.graph(); var mouse = context.map().mouse(); var projection = context.projection; - var viewport = geoExtent(projection.clipExtent()).polygon(); + var viewport = new Extent(projection.clipExtent()).polygon(); if (!geoPointInPolygon(mouse, viewport)) return; var oldIDs = context.copyIDs(); if (!oldIDs.length) return; - var extent = geoExtent(); + var extent = new Extent(); var oldGraph = context.copyGraph(); var newIDs = []; @@ -38,7 +39,7 @@ export function behaviorPaste(context) { var oldEntity = oldGraph.entity(id); var newEntity = copies[id]; - extent._extend(oldEntity.extent(oldGraph)); + extent = extent.extend(oldEntity.extent(oldGraph)); // Exclude child nodes from newIDs if their parent way was also copied. var parents = context.graph().parentWays(newEntity); diff --git a/modules/core/rapid_context.js b/modules/core/rapid_context.js index 0fc3aff9e4..0db2335bca 100644 --- a/modules/core/rapid_context.js +++ b/modules/core/rapid_context.js @@ -1,4 +1,4 @@ -import { geoExtent } from '../geo'; +import { Extent } from '@id-sdk/extent'; import { localizer, t } from '../core/localizer'; import toGeoJSON from '@mapbox/togeojson'; import { dispatch as d3_dispatch } from 'd3-dispatch'; @@ -66,7 +66,7 @@ export function coreRapidContext(context) { } }); - _taskExtent = new geoExtent([minlon, minlat], [maxlon, maxlat]); + _taskExtent = new Extent([minlon, minlat], [maxlon, maxlat]); dispatch.call('task_extent_set'); } }; diff --git a/modules/core/validation/models.js b/modules/core/validation/models.js index 0489e0be9e..d25914f726 100644 --- a/modules/core/validation/models.js +++ b/modules/core/validation/models.js @@ -1,4 +1,4 @@ -import { geoExtent } from '../../geo'; +import { Extent } from '@id-sdk/extent'; import { t } from '../../core/localizer'; export function validationIssue(attrs) { @@ -42,12 +42,12 @@ export function validationIssue(attrs) { this.extent = function(resolver) { if (this.loc) { - return geoExtent(this.loc); + return new Extent(this.loc); } if (this.entityIds && this.entityIds.length) { return this.entityIds.reduce(function(extent, entityId) { return extent.extend(resolver.entity(entityId).extent(resolver)); - }, geoExtent()); + }, new Extent()); } return null; }; diff --git a/modules/core/validator.js b/modules/core/validator.js index 135fe5aadf..4e02a19160 100644 --- a/modules/core/validator.js +++ b/modules/core/validator.js @@ -2,7 +2,7 @@ import { dispatch as d3_dispatch } from 'd3-dispatch'; import { prefs } from './preferences'; import { coreDifference } from './difference'; -import { geoExtent } from '../geo/extent'; +import { Extent } from '@id-sdk/extent'; import { modeSelect } from '../modes/select'; import { utilArrayChunk, utilArrayGroupBy, utilRebind } from '../util'; import * as Validations from '../validations/index'; @@ -155,7 +155,7 @@ export function coreValidator(context) { // uncache existing cache.uncacheIssuesOfType('unsquare_way'); - const buildings = context.history().tree().intersects(geoExtent([-180,-90],[180, 90]), graph) // everywhere + const buildings = context.history().tree().intersects(new Extent([-180,-90],[180, 90]), graph) // everywhere .filter(entity => (entity.type === 'way' && entity.tags.building && entity.tags.building !== 'no')); // rerun for all buildings diff --git a/modules/geo/extent.js b/modules/geo/extent.js deleted file mode 100644 index b935245afc..0000000000 --- a/modules/geo/extent.js +++ /dev/null @@ -1,146 +0,0 @@ -import { geoMetersToLat, geoMetersToLon } from './geo'; - - -export function geoExtent(min, max) { - if (!(this instanceof geoExtent)) { - return new geoExtent(min, max); - } else if (min instanceof geoExtent) { - return min; - } else if (min && min.length === 2 && min[0].length === 2 && min[1].length === 2) { - this[0] = min[0]; - this[1] = min[1]; - } else { - this[0] = min || [ Infinity, Infinity]; - this[1] = max || min || [-Infinity, -Infinity]; - } -} - - -export function geoExtentFromBounds(mapBounds) { - return geoExtent([ - [mapBounds.minlon, mapBounds.minlat], - [mapBounds.maxlon, mapBounds.maxlat] - ]); -} - - -geoExtent.prototype = new Array(2); - -Object.assign(geoExtent.prototype, { - - equals: function (obj) { - return this[0][0] === obj[0][0] && - this[0][1] === obj[0][1] && - this[1][0] === obj[1][0] && - this[1][1] === obj[1][1]; - }, - - - extend: function(obj) { - if (!(obj instanceof geoExtent)) obj = new geoExtent(obj); - return geoExtent( - [Math.min(obj[0][0], this[0][0]), Math.min(obj[0][1], this[0][1])], - [Math.max(obj[1][0], this[1][0]), Math.max(obj[1][1], this[1][1])] - ); - }, - - - _extend: function(extent) { - this[0][0] = Math.min(extent[0][0], this[0][0]); - this[0][1] = Math.min(extent[0][1], this[0][1]); - this[1][0] = Math.max(extent[1][0], this[1][0]); - this[1][1] = Math.max(extent[1][1], this[1][1]); - }, - - - area: function() { - return Math.abs((this[1][0] - this[0][0]) * (this[1][1] - this[0][1])); - }, - - - center: function() { - return [(this[0][0] + this[1][0]) / 2, (this[0][1] + this[1][1]) / 2]; - }, - - - rectangle: function() { - return [this[0][0], this[0][1], this[1][0], this[1][1]]; - }, - - - bbox: function() { - return { minX: this[0][0], minY: this[0][1], maxX: this[1][0], maxY: this[1][1] }; - }, - - - polygon: function() { - return [ - [this[0][0], this[0][1]], - [this[0][0], this[1][1]], - [this[1][0], this[1][1]], - [this[1][0], this[0][1]], - [this[0][0], this[0][1]] - ]; - }, - - - contains: function(obj) { - if (!(obj instanceof geoExtent)) obj = new geoExtent(obj); - return obj[0][0] >= this[0][0] && - obj[0][1] >= this[0][1] && - obj[1][0] <= this[1][0] && - obj[1][1] <= this[1][1]; - }, - - - intersects: function(obj) { - if (!(obj instanceof geoExtent)) obj = new geoExtent(obj); - return obj[0][0] <= this[1][0] && - obj[0][1] <= this[1][1] && - obj[1][0] >= this[0][0] && - obj[1][1] >= this[0][1]; - }, - - - intersection: function(obj) { - if (!this.intersects(obj)) return new geoExtent(); - return new geoExtent( - [Math.max(obj[0][0], this[0][0]), Math.max(obj[0][1], this[0][1])], - [Math.min(obj[1][0], this[1][0]), Math.min(obj[1][1], this[1][1])] - ); - }, - - - percentContainedIn: function(obj) { - if (!(obj instanceof geoExtent)) obj = new geoExtent(obj); - var a1 = this.intersection(obj).area(); - var a2 = this.area(); - - if (a1 === Infinity || a2 === Infinity) { - return 0; - } else if (a1 === 0 || a2 === 0) { - if (obj.contains(this)) { - return 1; - } - return 0; - } else { - return a1 / a2; - } - }, - - - padByMeters: function(meters) { - var dLat = geoMetersToLat(meters); - var dLon = geoMetersToLon(meters, this.center()[1]); - return geoExtent( - [this[0][0] - dLon, this[0][1] - dLat], - [this[1][0] + dLon, this[1][1] + dLat] - ); - }, - - - toParam: function() { - return this.rectangle().join(','); - } - -}); diff --git a/modules/geo/geom.js b/modules/geo/geom.js index 53d87457ae..adf39b7e89 100644 --- a/modules/geo/geom.js +++ b/modules/geo/geom.js @@ -3,7 +3,7 @@ import { polygonCentroid as d3_polygonCentroid } from 'd3-polygon'; -import { geoExtent } from './extent.js'; +import { Extent } from '@id-sdk/extent'; import { geoVecAngle, geoVecCross, geoVecDot, geoVecEqual, @@ -291,8 +291,8 @@ export function geoGetSmallestSurroundingRectangle(points) { var angle = Math.atan2(c2[1] - c1[1], c2[0] - c1[0]); var poly = geoRotate(hull, -angle, centroid); var extent = poly.reduce(function(extent, point) { - return extent.extend(geoExtent(point)); - }, geoExtent()); + return extent.extend(new Extent(point)); + }, new Extent()); var area = extent.area(); if (area < minArea) { diff --git a/modules/geo/index.js b/modules/geo/index.js index 9ad258a58f..8a4fcf96a9 100644 --- a/modules/geo/index.js +++ b/modules/geo/index.js @@ -1,6 +1,3 @@ -export { geoExtent } from './extent.js'; -export { geoExtentFromBounds } from './extent.js'; - export { geoLatToMeters } from './geo.js'; export { geoLonToMeters } from './geo.js'; export { geoMetersToLat } from './geo.js'; diff --git a/modules/geo/raw_mercator.js b/modules/geo/raw_mercator.js index 26f98a04e2..0c87b05764 100644 --- a/modules/geo/raw_mercator.js +++ b/modules/geo/raw_mercator.js @@ -1,3 +1,4 @@ +import { Extent } from '@id-sdk/extent'; import { geoMercatorRaw as d3_geoMercatorRaw, geoTransform as d3_geoTransform diff --git a/modules/modes/select.js b/modules/modes/select.js index bf0e57a7bd..96be0bd267 100644 --- a/modules/modes/select.js +++ b/modules/modes/select.js @@ -16,7 +16,8 @@ import { behaviorSelect } from '../behavior/select'; import { operationMove } from '../operations/move'; import { prefs } from '../core/preferences'; -import { geoExtent, geoChooseEdge, geoMetersToLat, geoMetersToLon } from '../geo'; +import { Extent } from '@id-sdk/extent'; +import { geoChooseEdge, geoMetersToLat, geoMetersToLon } from '../geo'; import { modeBrowse } from './browse'; import { modeDragNode } from './drag_node'; import { modeDragNote } from './drag_note'; @@ -277,11 +278,11 @@ export function modeSelect(context, selectedIDs) { selectElements(); if (_follow) { - var extent = geoExtent(); + var extent = new Extent(); var graph = context.graph(); selectedIDs.forEach(function(id) { var entity = context.entity(id); - extent._extend(entity.extent(graph)); + extent = extent.extend(entity.extent(graph)); }); var loc = extent.center(); @@ -343,9 +344,9 @@ export function modeSelect(context, selectedIDs) { function tooSmall() { if (isUp) return false; - let dLon = Math.abs(extent[1][0] - extent[0][0]); - let dLat = Math.abs(extent[1][1] - extent[0][1]); - return dLon < geoMetersToLon(1, extent[1][1]) && + let dLon = Math.abs(extent.max[0] - extent.min[0]); + let dLat = Math.abs(extent.max[1] - extent.min[1]); + return dLon < geoMetersToLon(1, extent.max[1]) && dLat < geoMetersToLat(1); } diff --git a/modules/modes/select_data.js b/modules/modes/select_data.js index 51e18b9465..19ad813856 100644 --- a/modules/modes/select_data.js +++ b/modules/modes/select_data.js @@ -11,7 +11,7 @@ import { behaviorSelect } from '../behavior/select'; import { t } from '../core/localizer'; -import { geoExtent } from '../geo'; +import { Extent } from '@id-sdk/extent'; import { modeBrowse } from './browse'; import { modeDragNode } from './drag_node'; import { modeDragNote } from './drag_note'; @@ -61,8 +61,9 @@ export function modeSelectData(context, selectedDatum) { } - mode.zoomToSelected = function() { - var extent = geoExtent(d3_geoBounds(selectedDatum)); + mode.zoomToSelected = function () { + var bounds = d3_geoBounds(selectedDatum); + var extent = new Extent(bounds[0], bounds[1]); context.map().centerZoomEase(extent.center(), context.map().trimmedExtentZoom(extent)); }; @@ -83,7 +84,7 @@ export function modeSelectData(context, selectedDatum) { sidebar.show(dataEditor.datum(selectedDatum)); // expand the sidebar, avoid obscuring the data if needed - var extent = geoExtent(d3_geoBounds(selectedDatum)); + var extent = new Extent(d3_geoBounds(selectedDatum)); sidebar.expand(sidebar.intersects(extent)); context.map() diff --git a/modules/operations/paste.js b/modules/operations/paste.js index 30e61d2222..24ac29d800 100644 --- a/modules/operations/paste.js +++ b/modules/operations/paste.js @@ -2,7 +2,9 @@ import { actionCopyEntities } from '../actions/copy_entities'; import { actionMove } from '../actions/move'; import { modeSelect } from '../modes/select'; -import { geoExtent, geoVecSubtract } from '../geo'; +import { geoVecSubtract } from '../geo'; +import { Extent } from '@id-sdk/extent'; + import { t } from '../core/localizer'; import { uiCmd } from '../ui/cmd'; import { utilDisplayLabel } from '../util/util'; @@ -20,7 +22,7 @@ export function operationPaste(context) { if (!oldIDs.length) return; var projection = context.projection; - var extent = geoExtent(); + var extent = new Extent(); var oldGraph = context.copyGraph(); var newIDs = []; @@ -35,7 +37,7 @@ export function operationPaste(context) { var oldEntity = oldGraph.entity(id); var newEntity = copies[id]; - extent._extend(oldEntity.extent(oldGraph)); + extent = extent.extend(oldEntity.extent(oldGraph)); // Exclude child nodes from newIDs if their parent way was also copied. var parents = context.graph().parentWays(newEntity); diff --git a/modules/osm/changeset.js b/modules/osm/changeset.js index 29cd214d5a..8c439be868 100644 --- a/modules/osm/changeset.js +++ b/modules/osm/changeset.js @@ -1,5 +1,5 @@ import { osmEntity } from './entity'; -import { geoExtent } from '../geo'; +import { Extent } from '@id-sdk/extent'; export function osmChangeset() { @@ -21,7 +21,7 @@ Object.assign(osmChangeset.prototype, { extent: function() { - return new geoExtent(); + return new new Extent(); }, diff --git a/modules/osm/node.js b/modules/osm/node.js index 7b42197ff1..976a9f89ad 100644 --- a/modules/osm/node.js +++ b/modules/osm/node.js @@ -1,5 +1,7 @@ import { osmEntity } from './entity'; -import { geoAngle, geoExtent } from '../geo'; +import { geoAngle } from '../geo'; +import { Extent } from '@id-sdk/extent'; + import { utilArrayUniq } from '../util'; @@ -20,7 +22,7 @@ Object.assign(osmNode.prototype, { loc: [9999, 9999], extent: function() { - return new geoExtent(this.loc); + return new Extent(this.loc); }, diff --git a/modules/osm/note.js b/modules/osm/note.js index 18bf426d3f..5595d132ae 100644 --- a/modules/osm/note.js +++ b/modules/osm/note.js @@ -1,4 +1,4 @@ -import { geoExtent } from '../geo'; +import { Extent } from '@id-sdk/extent'; export function osmNote() { @@ -44,7 +44,7 @@ Object.assign(osmNote.prototype, { }, extent: function() { - return new geoExtent(this.loc); + return new Extent(this.loc); }, update: function(attrs) { diff --git a/modules/osm/relation.js b/modules/osm/relation.js index f2c94d3b8a..4c16ddfc05 100644 --- a/modules/osm/relation.js +++ b/modules/osm/relation.js @@ -2,7 +2,8 @@ import { geoArea as d3_geoArea } from 'd3-geo'; import { osmEntity } from './entity'; import { osmJoinWays } from './multipolygon'; -import { geoExtent, geoPolygonContainsPolygon, geoPolygonIntersectsPolygon } from '../geo'; +import { geoPolygonContainsPolygon, geoPolygonIntersectsPolygon } from '../geo'; +import { Extent } from '@id-sdk/extent'; export function osmRelation() { @@ -51,15 +52,15 @@ Object.assign(osmRelation.prototype, { extent: function(resolver, memo) { return resolver.transient(this, 'extent', function() { - if (memo && memo[this.id]) return geoExtent(); + if (memo && memo[this.id]) return new Extent(); memo = memo || {}; memo[this.id] = true; - var extent = geoExtent(); + var extent = new Extent(); for (var i = 0; i < this.members.length; i++) { var member = resolver.hasEntity(this.members[i].id); if (member) { - extent._extend(member.extent(resolver, memo)); + extent = extent.extend(member.extent(resolver, memo)); } } return extent; diff --git a/modules/osm/way.js b/modules/osm/way.js index 881ad5d84f..6c1413567a 100644 --- a/modules/osm/way.js +++ b/modules/osm/way.js @@ -1,10 +1,11 @@ import { geoArea as d3_geoArea } from 'd3-geo'; -import { geoExtent, geoVecCross } from '../geo'; +import { geoVecCross } from '../geo'; import { osmEntity } from './entity'; import { osmLanes } from './lanes'; import { osmTagSuggestingArea, osmOneWayTags, osmRightSideIsInsideTags } from './tags'; import { utilArrayUniq } from '../util'; +import { Extent } from '@id-sdk/extent'; export function osmWay() { @@ -44,11 +45,11 @@ Object.assign(osmWay.prototype, { extent: function(resolver) { return resolver.transient(this, 'extent', function() { - var extent = geoExtent(); + var extent = new Extent(); for (var i = 0; i < this.nodes.length; i++) { var node = resolver.hasEntity(this.nodes[i]); if (node) { - extent._extend(node.extent()); + extent = extent.extend(node.extent()); } } return extent; @@ -269,7 +270,7 @@ Object.assign(osmWay.prototype, { function segmentExtent(graph) { var n1 = graph.hasEntity(this.nodes[0]); var n2 = graph.hasEntity(this.nodes[1]); - return n1 && n2 && geoExtent([ + return n1 && n2 && new Extent( [ Math.min(n1.loc[0], n2.loc[0]), Math.min(n1.loc[1], n2.loc[1]) @@ -278,7 +279,7 @@ Object.assign(osmWay.prototype, { Math.max(n1.loc[0], n2.loc[0]), Math.max(n1.loc[1], n2.loc[1]) ] - ]); + ); } return graph.transient(this, 'segments', function() { diff --git a/modules/renderer/background.js b/modules/renderer/background.js index ef2f0c328d..3526fe7185 100644 --- a/modules/renderer/background.js +++ b/modules/renderer/background.js @@ -6,12 +6,13 @@ import whichPolygon from 'which-polygon'; import { prefs } from '../core/preferences'; import { fileFetcher } from '../core/file_fetcher'; -import { geoExtent, geoMetersToOffset, geoOffsetToMeters} from '../geo'; +import { geoMetersToOffset, geoOffsetToMeters} from '../geo'; import { rendererBackgroundSource } from './background_source'; import { rendererTileLayer } from './tile_layer'; import { utilQsString, utilStringQs } from '../util'; import { utilDetect } from '../util/detect'; import { utilRebind } from '../util/rebind'; +import { Extent } from '@id-sdk/extent'; let _imageryIndex = null; @@ -464,7 +465,7 @@ export function rendererBackground(context) { if (!qmap) return false; const params = qmap.split('/').map(Number); if (params.length < 3 || params.some(isNaN)) return false; - return geoExtent([params[2], params[1]]); // lon,lat + return new Extent([params[2], params[1]]); // lon,lat } const hash = utilStringQs(window.location.hash); diff --git a/modules/renderer/background_source.js b/modules/renderer/background_source.js index 6723d550f0..1302cff08d 100644 --- a/modules/renderer/background_source.js +++ b/modules/renderer/background_source.js @@ -2,9 +2,10 @@ import { geoArea as d3_geoArea, geoMercatorRaw as d3_geoMercatorRaw } from 'd3-g import { json as d3_json } from 'd3-fetch'; import { t, localizer } from '../core/localizer'; -import { geoExtent, geoSphericalDistance } from '../geo'; +import { geoSphericalDistance } from '../geo'; import { utilQsString, utilStringQs } from '../util'; import { utilAesDecrypt } from '../util/aes'; +import { Extent } from '@id-sdk/extent'; var isRetina = window.devicePixelRatio && window.devicePixelRatio >= 2; @@ -312,7 +313,7 @@ rendererBackgroundSource.Bing = function(data, dispatch) { areas: provider.coverageAreas.map(function(area) { return { zoom: [area.zoomMin, area.zoomMax], - extent: geoExtent([area.bbox[1], area.bbox[0]], [area.bbox[3], area.bbox[2]]) + extent: new Extent([area.bbox[1], area.bbox[0]], [area.bbox[3], area.bbox[2]]) }; }) }; diff --git a/modules/renderer/map.js b/modules/renderer/map.js index fcc8a420d8..10344b8ece 100644 --- a/modules/renderer/map.js +++ b/modules/renderer/map.js @@ -7,7 +7,7 @@ import { select as d3_select } from 'd3-selection'; import { zoom as d3_zoom, zoomIdentity as d3_zoomIdentity } from 'd3-zoom'; import { prefs } from '../core/preferences'; -import { geoExtent, geoRawMercator, geoScaleToZoom, geoZoomToScale } from '../geo'; +import { geoRawMercator, geoScaleToZoom, geoZoomToScale } from '../geo'; import { modeBrowse } from '../modes/browse'; import { svgAreas, svgLabels, svgLayers, svgLines, svgMidpoints, svgPoints, svgVertices } from '../svg'; import { utilFastMouse, utilFunctor, utilSetTransform, utilEntityAndDeepMemberIDs } from '../util/util'; @@ -18,6 +18,8 @@ import { utilRebind } from '../util/rebind'; import { utilZoomPan } from '../util/zoom_pan'; import { utilDoubleUp } from '../util/double_up'; +import { Extent } from '@id-sdk/extent'; + // constants var TILESIZE = 256; var minZoom = 2; @@ -981,12 +983,12 @@ export function rendererMap(context) { map.extent = function(val) { if (!arguments.length) { - return new geoExtent( + return new Extent( projection.invert([0, _dimensions[1]]), projection.invert([_dimensions[0], 0]) ); } else { - var extent = geoExtent(val); + var extent = new Extent(val); map.centerZoom(extent.center(), map.extentZoom(extent)); } }; @@ -997,20 +999,20 @@ export function rendererMap(context) { var headerY = 71; var footerY = 30; var pad = 10; - return new geoExtent( + return new Extent( projection.invert([pad, _dimensions[1] - footerY - pad]), projection.invert([_dimensions[0] - pad, headerY + pad]) ); } else { - var extent = geoExtent(val); + var extent = new Extent(val); map.centerZoom(extent.center(), map.trimmedExtentZoom(extent)); } }; function calcExtentZoom(extent, dim) { - var tl = projection([extent[0][0], extent[1][1]]); - var br = projection([extent[1][0], extent[0][1]]); + var tl = projection([extent.min[0], extent.max[1]]); + var br = projection([extent.max[0], extent.min[1]]); // Calculate maximum zoom that fits extent var hFactor = (br[0] - tl[0]) / dim[0]; @@ -1024,7 +1026,7 @@ export function rendererMap(context) { map.extentZoom = function(val) { - return calcExtentZoom(geoExtent(val), _dimensions); + return calcExtentZoom(new Extent(val), _dimensions); }; @@ -1032,7 +1034,7 @@ export function rendererMap(context) { var trimY = 120; var trimX = 40; var trimmed = [_dimensions[0] - trimX, _dimensions[1] - trimY]; - return calcExtentZoom(geoExtent(val), trimmed); + return calcExtentZoom(new Extent(val), trimmed); }; diff --git a/modules/services/improveOSM.js b/modules/services/improveOSM.js index 6da7bcc8d4..101ad6ba75 100644 --- a/modules/services/improveOSM.js +++ b/modules/services/improveOSM.js @@ -6,12 +6,12 @@ import { json as d3_json } from 'd3-fetch'; import { Projection, Tiler } from '@id-sdk/math'; import { fileFetcher } from '../core/file_fetcher'; -import { geoExtent, geoVecAdd, geoVecScale } from '../geo'; +import { geoVecAdd, geoVecScale } from '../geo'; import { QAItem } from '../osm'; import { serviceOsm } from './index'; import { t } from '../core/localizer'; import { utilRebind, utilQsString } from '../util'; - +import { Extent } from '@id-sdk/extent'; const TILEZOOM = 14; const tiler = new Tiler().zoomRange([TILEZOOM, TILEZOOM]); @@ -115,7 +115,7 @@ function preventCoincident(loc, bumpUp) { bumpUp ? [0, 0.00001] : [0, 0]; loc = geoVecAdd(loc, delta); - let bbox = geoExtent(loc).bbox(); + let bbox = new Extent(loc).bbox(); coincident = _cache.rtree.search(bbox).length; } while (coincident); @@ -442,7 +442,7 @@ export default { const viewport = projection.clipExtent(); const min = [viewport[0][0], viewport[1][1]]; const max = [viewport[1][0], viewport[0][1]]; - const bbox = geoExtent(projection.invert(min), projection.invert(max)).bbox(); + const bbox = new Extent(projection.invert(min), projection.invert(max)).bbox(); return _cache.rtree.search(bbox).map(d => d.data); }, diff --git a/modules/services/keepRight.js b/modules/services/keepRight.js index ed28d7ab89..2e7a1b6229 100644 --- a/modules/services/keepRight.js +++ b/modules/services/keepRight.js @@ -6,10 +6,11 @@ import { json as d3_json } from 'd3-fetch'; import { Projection, Tiler } from '@id-sdk/math'; import { fileFetcher } from '../core/file_fetcher'; -import { geoExtent, geoVecAdd } from '../geo'; +import { geoVecAdd } from '../geo'; import { QAItem } from '../osm'; import { t } from '../core/localizer'; import { utilRebind, utilQsString } from '../util'; +import { Extent } from '@id-sdk/extent'; const TILEZOOM = 14; const tiler = new Tiler().zoomRange([TILEZOOM, TILEZOOM]); @@ -380,7 +381,7 @@ export default { // first time, move marker up. after that, move marker right. let delta = coincident ? [0.00001, 0] : [0, 0.00001]; loc = geoVecAdd(loc, delta); - let bbox = geoExtent(loc).bbox(); + let bbox = new Extent(loc).bbox(); coincident = _cache.rtree.search(bbox).length; } while (coincident); @@ -464,7 +465,7 @@ export default { const viewport = projection.clipExtent(); const min = [viewport[0][0], viewport[1][1]]; const max = [viewport[1][0], viewport[0][1]]; - const bbox = geoExtent(projection.invert(min), projection.invert(max)).bbox(); + const bbox = new Extent(projection.invert(min), projection.invert(max)).bbox(); return _cache.rtree.search(bbox).map(d => d.data); }, diff --git a/modules/services/mapillary.js b/modules/services/mapillary.js index 29f8c5df2f..c71da13f78 100644 --- a/modules/services/mapillary.js +++ b/modules/services/mapillary.js @@ -8,8 +8,9 @@ import Protobuf from 'pbf'; import RBush from 'rbush'; import { VectorTile } from '@mapbox/vector-tile'; -import { geoExtent, geoScaleToZoom } from '../geo'; +import { geoScaleToZoom } from '../geo'; import { utilQsString, utilRebind, utilStringQs } from '../util'; +import { Extent } from '@id-sdk/extent'; const accessToken = 'MLY|3376030635833192|f13ab0bdf6b2f7b99e0d8bd5868e1d88'; const apiUrl = 'https://graph.mapillary.com/'; @@ -289,7 +290,7 @@ export default { const viewport = projection.clipExtent(); const min = [viewport[0][0], viewport[1][1]]; const max = [viewport[1][0], viewport[0][1]]; - const bbox = geoExtent(projection.invert(min), projection.invert(max)).bbox(); + const bbox = new Extent(projection.invert(min), projection.invert(max)).bbox(); const sequenceIds = {}; let lineStrings = []; diff --git a/modules/services/nominatim.js b/modules/services/nominatim.js index 9aee69649c..b1ae31c865 100644 --- a/modules/services/nominatim.js +++ b/modules/services/nominatim.js @@ -1,7 +1,7 @@ import { json as d3_json } from 'd3-fetch'; import RBush from 'rbush'; -import { geoExtent } from '../geo'; +import { Extent } from '@id-sdk/extent'; import { utilQsString } from '../util'; @@ -60,7 +60,7 @@ export default { if (result && result.error) { throw new Error(result.error); } - var extent = geoExtent(loc).padByMeters(200); + var extent = new Extent(loc).padByMeters(200); _nominatimCache.insert(Object.assign(extent.bbox(), {data: result})); if (callback) callback(null, result); }) diff --git a/modules/services/openstreetcam.js b/modules/services/openstreetcam.js index 410b356cf8..ab7da878a6 100644 --- a/modules/services/openstreetcam.js +++ b/modules/services/openstreetcam.js @@ -6,8 +6,9 @@ import { Projection, Tiler } from '@id-sdk/math'; import RBush from 'rbush'; import { localizer } from '../core/localizer'; -import { geoExtent, geoScaleToZoom } from '../geo'; +import { geoScaleToZoom } from '../geo'; import { utilArrayUnion, utilQsString, utilRebind, utilSetTransform, utilStringQs } from '../util'; +import { Extent } from '@id-sdk/extent'; var apibase = 'https://openstreetcam.org'; @@ -208,7 +209,7 @@ export default { var viewport = projection.clipExtent(); var min = [viewport[0][0], viewport[1][1]]; var max = [viewport[1][0], viewport[0][1]]; - var bbox = geoExtent(projection.invert(min), projection.invert(max)).bbox(); + var bbox = new Extent(projection.invert(min), projection.invert(max)).bbox(); var sequenceKeys = {}; // all sequences for images in viewport diff --git a/modules/services/osm.js b/modules/services/osm.js index eee87a9865..b9338a121b 100644 --- a/modules/services/osm.js +++ b/modules/services/osm.js @@ -10,9 +10,10 @@ import osmAuth from 'osm-auth'; import RBush from 'rbush'; import { JXON } from '../util/jxon'; -import { geoExtent, geoVecAdd, geoZoomToScale } from '../geo'; +import { geoVecAdd, geoZoomToScale } from '../geo'; import { osmEntity, osmNode, osmNote, osmRelation, osmWay } from '../osm'; import { utilArrayChunk, utilArrayGroupBy, utilArrayUniq, utilRebind, utilQsString, utilStringQs } from '../util'; +import { Extent } from '@id-sdk/extent'; var tiler = new Tiler(); @@ -395,7 +396,7 @@ var parsers = { if (coincident) { props.loc = geoVecAdd(props.loc, [epsilon, epsilon]); } - var bbox = geoExtent(props.loc).bbox(); + var bbox = new Extent(props.loc).bbox(); coincident = _noteCache.rtree.search(bbox).length; } while (coincident); @@ -1416,7 +1417,7 @@ export default { var viewport = projection.clipExtent(); var min = [viewport[0][0], viewport[1][1]]; var max = [viewport[1][0], viewport[0][1]]; - var bbox = geoExtent(projection.invert(min), projection.invert(max)).bbox(); + var bbox = new Extent(projection.invert(min), projection.invert(max)).bbox(); return _noteCache.rtree.search(bbox) .map(function(d) { return d.data; }); diff --git a/modules/services/osmose.js b/modules/services/osmose.js index 34295c4268..81b93de9d0 100644 --- a/modules/services/osmose.js +++ b/modules/services/osmose.js @@ -9,9 +9,10 @@ import { Tiler } from '@id-sdk/tiler'; import { fileFetcher } from '../core/file_fetcher'; import { localizer } from '../core/localizer'; -import { geoExtent, geoVecAdd } from '../geo'; +import { geoVecAdd } from '../geo'; import { QAItem } from '../osm'; import { utilRebind, utilQsString } from '../util'; +import { Extent } from '@id-sdk/extent'; const TILEZOOM = 14; const tiler = new Tiler().zoomRange([TILEZOOM, TILEZOOM]); @@ -58,7 +59,7 @@ function preventCoincident(loc) { // first time, move marker up. after that, move marker right. let delta = coincident ? [0.00001, 0] : [0, 0.00001]; loc = geoVecAdd(loc, delta); - let bbox = geoExtent(loc).bbox(); + let bbox = new Extent(loc).bbox(); coincident = _cache.rtree.search(bbox).length; } while (coincident); @@ -301,7 +302,7 @@ export default { const viewport = projection.clipExtent(); const min = [viewport[0][0], viewport[1][1]]; const max = [viewport[1][0], viewport[0][1]]; - const bbox = geoExtent(projection.invert(min), projection.invert(max)).bbox(); + const bbox = new Extent(projection.invert(min), projection.invert(max)).bbox(); return _cache.rtree.search(bbox).map(d => d.data); }, diff --git a/modules/services/streetside.js b/modules/services/streetside.js index 27d2dca9b2..64ec1c71aa 100644 --- a/modules/services/streetside.js +++ b/modules/services/streetside.js @@ -8,10 +8,10 @@ import RBush from 'rbush'; import { t, localizer } from '../core/localizer'; import { jsonpRequest } from '../util/jsonp_request'; -import { - geoExtent, geoMetersToLat, geoMetersToLon, geoPointInPolygon, +import { geoMetersToLat, geoMetersToLon, geoPointInPolygon, geoRotate, geoScaleToZoom, geoVecLength } from '../geo'; +import { Extent } from '@id-sdk/extent'; import { utilArrayUnion, utilQsString, utilRebind, utilStringQs, utilUniqueDomId } from '../util'; @@ -442,7 +442,7 @@ export default { const viewport = projection.clipExtent(); const min = [viewport[0][0], viewport[1][1]]; const max = [viewport[1][0], viewport[0][1]]; - const bbox = geoExtent(projection.invert(min), projection.invert(max)).bbox(); + const bbox = new Extent(projection.invert(min), projection.invert(max)).bbox(); let seen = {}; let results = []; @@ -646,8 +646,8 @@ export default { poly = geoRotate(poly, -angle, origin); let extent = poly.reduce((extent, point) => { - return extent.extend(geoExtent(point)); - }, geoExtent()); + return extent.extend(new Extent(point)); + }, new Extent()); // find nearest other bubble in the search polygon let minDist = Infinity; diff --git a/modules/svg/data.js b/modules/svg/data.js index b147c39987..01b6b5a947 100644 --- a/modules/svg/data.js +++ b/modules/svg/data.js @@ -7,11 +7,12 @@ import { select as d3_select } from 'd3-selection'; import stringify from 'fast-json-stable-stringify'; import toGeoJSON from '@mapbox/togeojson'; -import { geoExtent, geoPolygonIntersectsPolygon } from '../geo'; +import { geoPolygonIntersectsPolygon } from '../geo'; import { services } from '../services'; import { svgPath } from './helpers'; import { utilDetect } from '../util/detect'; import { utilArrayFlatten, utilArrayUnion, utilHashcode } from '../util'; +import { Extent } from '@id-sdk/extent'; var _initialized = false; @@ -525,7 +526,9 @@ export function svgData(projection, context, dispatch) { }, []); if (!geoPolygonIntersectsPolygon(viewport, coords, true)) { - var extent = geoExtent(d3_geoBounds({ type: 'LineString', coordinates: coords })); + var bounds = d3_geoBounds({ type: 'LineString', coordinates: coords }); + var extent = new Extent(bounds[0], bounds[1]); + map.centerZoom(extent.center(), map.trimmedExtentZoom(extent)); } diff --git a/modules/svg/helpers.js b/modules/svg/helpers.js index 8c946f6fda..1180e991f8 100644 --- a/modules/svg/helpers.js +++ b/modules/svg/helpers.js @@ -147,10 +147,20 @@ export function svgPath(projection, graph, isArea) { var cache = {}; var padding = isArea ? 65 : 5; var viewport = projection.clipExtent(); - var paddedExtent = [ - [viewport[0][0] - padding, viewport[0][1] - padding], - [viewport[1][0] + padding, viewport[1][1] + padding] - ]; + var paddedExtent; + + if (viewport.min) { + paddedExtent = [ + [viewport.min[0] - padding, viewport.min[1] - padding], + [viewport.max[0] + padding, viewport.max[1] + padding] + ]; + } else { + paddedExtent = [ + [viewport[0][0] - padding, viewport[0][1] - padding], + [viewport[1][0] + padding, viewport[1][1] + padding] + ]; + } + var clip = d3_geoIdentity().clipExtent(paddedExtent).stream; var project = projection.stream; var path = d3_geoPath() diff --git a/modules/svg/labels.js b/modules/svg/labels.js index 9a91c9434e..27ea02c552 100644 --- a/modules/svg/labels.js +++ b/modules/svg/labels.js @@ -4,15 +4,14 @@ import { geoPath as d3_geoPath } from 'd3-geo'; import RBush from 'rbush'; import { localizer } from '../core/localizer'; -import { - geoExtent, geoPolygonIntersectsPolygon, geoPathLength, +import { geoPolygonIntersectsPolygon, geoPathLength, geoScaleToZoom, geoVecInterp, geoVecLength } from '../geo'; import { presetManager } from '../presets'; import { osmEntity } from '../osm'; import { utilDetect } from '../util/detect'; import { utilDisplayName, utilDisplayNameForPath, utilEntitySelector } from '../util'; - +import { Extent } from '@id-sdk/extent'; export function svgLabels(projection, context) { @@ -439,7 +438,7 @@ export function svgLabels(projection, context) { function getLineLabel(entity, width, height) { - var viewport = geoExtent(context.projection.clipExtent()).polygon(); + var viewport = new Extent(context.projection.clipExtent()).polygon(); var points = graph.childNodes(entity) .map(function(node) { return projection(node.loc); }); var length = geoPathLength(points); @@ -552,7 +551,7 @@ export function svgLabels(projection, context) { function getAreaLabel(entity, width, height) { var centroid = path.centroid(entity.asGeoJSON(graph)); var extent = entity.extent(graph); - var areaWidth = projection(extent[1])[0] - projection(extent[0])[0]; + var areaWidth = projection(extent.max)[0] - projection(extent.min)[0]; if (isNaN(centroid[0]) || areaWidth < 20) return; diff --git a/modules/ui/conflicts.js b/modules/ui/conflicts.js index 078a494d48..df065679f7 100644 --- a/modules/ui/conflicts.js +++ b/modules/ui/conflicts.js @@ -6,7 +6,7 @@ import { import { t } from '../core/localizer'; import { JXON } from '../util/jxon'; -import { geoExtent } from '../geo'; +import { Extent } from '@id-sdk/extent'; import { osmChangeset } from '../osm'; import { svgIcon } from '../svg/icon'; import { utilDetect } from '../util/detect'; @@ -287,16 +287,16 @@ export function uiConflicts(context) { .selectAll('input') .property('checked', function(d) { return d === datum; }); - var extent = geoExtent(); + var extent = new Extent(); var entity; entity = context.graph().hasEntity(datum.id); - if (entity) extent._extend(entity.extent(context.graph())); + if (entity) extent = extent.extend(entity.extent(context.graph())); datum.action(); entity = context.graph().hasEntity(datum.id); - if (entity) extent._extend(entity.extent(context.graph())); + if (entity) extent = extent.extend(entity.extent(context.graph())); zoomToEntity(datum.id, extent); } diff --git a/modules/ui/feature_list.js b/modules/ui/feature_list.js index f0ccc7d180..f13ffa635a 100644 --- a/modules/ui/feature_list.js +++ b/modules/ui/feature_list.js @@ -8,7 +8,7 @@ import { t } from '../core/localizer'; import { dmsCoordinatePair } from '../util/units'; import { coreGraph } from '../core/graph'; import { geoSphericalDistance } from '../geo/geo'; -import { geoExtent } from '../geo'; +import { Extent } from '@id-sdk/extent'; import { modeSelect } from '../modes/select'; import { osmEntity } from '../osm/entity'; import { services } from '../services'; @@ -204,7 +204,7 @@ export function uiFeatureList(context) { geometry: tempEntity.geometry(tempGraph), type: type, name: d.display_name, - extent: new geoExtent( + extent: new Extent( [parseFloat(d.boundingbox[3]), parseFloat(d.boundingbox[0])], [parseFloat(d.boundingbox[2]), parseFloat(d.boundingbox[1])]) }); diff --git a/modules/ui/field.js b/modules/ui/field.js index f8446b69cc..6e3408ce78 100644 --- a/modules/ui/field.js +++ b/modules/ui/field.js @@ -5,7 +5,7 @@ import { t, localizer } from '../core/localizer'; import { locationManager } from '../core/locations'; import { svgIcon } from '../svg/icon'; import { uiTooltip } from './tooltip'; -import { geoExtent } from '../geo/extent'; +import { Extent } from '@id-sdk/extent'; import { uiFieldHelp } from './field_help'; import { uiFields } from './fields'; import { uiTagReference } from './tag_reference'; @@ -45,7 +45,7 @@ export function uiField(context, presetField, entityIDs, options) { _entityExtent = entityIDs.reduce(function(extent, entityID) { var entity = context.graph().entity(entityID); return extent.extend(entity.extent(context.graph())); - }, geoExtent()); + }, new Extent()); } var _locked = false; diff --git a/modules/ui/fields/address.js b/modules/ui/fields/address.js index 7830079298..8d102da4f1 100644 --- a/modules/ui/fields/address.js +++ b/modules/ui/fields/address.js @@ -4,10 +4,11 @@ import * as countryCoder from '@ideditor/country-coder'; import { presetManager } from '../../presets'; import { fileFetcher } from '../../core/file_fetcher'; -import { geoExtent, geoChooseEdge, geoSphericalDistance } from '../../geo'; +import { geoChooseEdge, geoSphericalDistance } from '../../geo'; import { uiCombobox } from '../combobox'; import { utilArrayUniqBy, utilGetSetValue, utilNoAuto, utilRebind, utilTotalExtent } from '../../util'; import { t } from '../../core/localizer'; +import { Extent } from '@id-sdk/extent'; export function uiFieldAddress(field, context) { @@ -39,14 +40,14 @@ export function uiFieldAddress(field, context) { function getNearStreets() { var extent = combinedEntityExtent(); var l = extent.center(); - var box = geoExtent(l).padByMeters(200); + var box = new Extent(l).padByMeters(200); var streets = context.history().intersects(box) .filter(isAddressable) .map(function(d) { var loc = context.projection([ - (extent[0][0] + extent[1][0]) / 2, - (extent[0][1] + extent[1][1]) / 2 + (extent.min[0] + extent.max[0]) / 2, + (extent.min[1] + extent.max[1]) / 2 ]); var choice = geoChooseEdge(context.graph().childNodes(d), loc, context.projection); @@ -71,7 +72,7 @@ export function uiFieldAddress(field, context) { function getNearCities() { var extent = combinedEntityExtent(); var l = extent.center(); - var box = geoExtent(l).padByMeters(200); + var box = new Extent(l).padByMeters(200); var cities = context.history().intersects(box) .filter(isAddressable) @@ -105,7 +106,7 @@ export function uiFieldAddress(field, context) { function getNearValues(key) { var extent = combinedEntityExtent(); var l = extent.center(); - var box = geoExtent(l).padByMeters(200); + var box = new Extent(l).padByMeters(200); var results = context.history().intersects(box) .filter(function hasTag(d) { return _entityIDs.indexOf(d.id) === -1 && d.tags[key]; }) diff --git a/modules/ui/fields/restrictions.js b/modules/ui/fields/restrictions.js index 3d2c0b7bd7..595f3f72ac 100644 --- a/modules/ui/fields/restrictions.js +++ b/modules/ui/fields/restrictions.js @@ -7,7 +7,8 @@ import { t, localizer } from '../../core/localizer'; import { actionRestrictTurn } from '../../actions/restrict_turn'; import { actionUnrestrictTurn } from '../../actions/unrestrict_turn'; import { behaviorBreathe } from '../../behavior/breathe'; -import { geoExtent, geoRawMercator, geoVecScale, geoVecSubtract, geoZoomToScale } from '../../geo'; +import { Extent } from '@id-sdk/extent'; +import { geoRawMercator, geoVecScale, geoVecSubtract, geoZoomToScale } from '../../geo'; import { osmIntersection, osmInferRestriction, osmTurn, osmWay } from '../../osm'; import { svgLayers, svgLines, svgTurns, svgVertices } from '../../svg'; import { utilDisplayName, utilDisplayType, utilEntitySelector, utilFunctor, utilRebind } from '../../util'; @@ -218,16 +219,16 @@ export function uiFieldRestrictions(field, context) { projection.scale(geoZoomToScale(z)); // Calculate extent of all key vertices - var extent = geoExtent(); + var extent = new Extent(); for (var i = 0; i < _intersection.vertices.length; i++) { - extent._extend(_intersection.vertices[i].extent()); + extent = extent.extend(_intersection.vertices[i].extent()); } // If this is a large intersection, adjust zoom to fit extent if (_intersection.vertices.length > 1) { var padding = 180; // in z22 pixels - var tl = projection([extent[0][0], extent[1][1]]); - var br = projection([extent[1][0], extent[0][1]]); + var tl = projection([extent.min[0], extent.max[1]]); + var br = projection([extent.max[0], extent.min[1]]); var hFactor = (br[0] - tl[0]) / (d[0] - padding); var vFactor = (br[1] - tl[1]) / (d[1] - padding); var hZoomDiff = Math.log(Math.abs(hFactor)) / Math.LN2; diff --git a/modules/ui/geolocate.js b/modules/ui/geolocate.js index 26dc2b1442..ff6fa0e48b 100644 --- a/modules/ui/geolocate.js +++ b/modules/ui/geolocate.js @@ -2,7 +2,7 @@ import { select as d3_select } from 'd3-selection'; import { t, localizer } from '../core/localizer'; import { uiTooltip } from './tooltip'; -import { geoExtent } from '../geo'; +import { Extent } from '@id-sdk/extent'; import { modeBrowse } from '../modes/browse'; import { svgIcon } from '../svg/icon'; import { uiLoading } from './loading'; @@ -51,7 +51,7 @@ export function uiGeolocate(context) { function success(geolocation) { _position = geolocation; var coords = _position.coords; - _extent = geoExtent([coords.longitude, coords.latitude]).padByMeters(coords.accuracy); + _extent = new Extent([coords.longitude, coords.latitude]).padByMeters(coords.accuracy); zoomTo(); finish(); } diff --git a/modules/ui/lasso.js b/modules/ui/lasso.js index 9372adea9a..dfd37d54bf 100644 --- a/modules/ui/lasso.js +++ b/modules/ui/lasso.js @@ -1,5 +1,5 @@ import { select as d3_select } from 'd3-selection'; -import { geoExtent } from '../geo'; +import { Extent } from '@id-sdk/extent'; import { uiToggle } from './toggle'; @@ -35,8 +35,8 @@ export function uiLasso(context) { lasso.extent = function () { return lasso.coordinates.reduce(function(extent, point) { - return extent.extend(geoExtent(point)); - }, geoExtent()); + return extent.extend(new Extent(point)); + }, new Extent()); }; diff --git a/modules/ui/panels/measurement.js b/modules/ui/panels/measurement.js index 9424bae285..2ee26c87b6 100644 --- a/modules/ui/panels/measurement.js +++ b/modules/ui/panels/measurement.js @@ -5,9 +5,10 @@ import { import { t, localizer } from '../../core/localizer'; import { displayArea, displayLength, decimalCoordinatePair, dmsCoordinatePair } from '../../util/units'; -import { geoExtent, geoSphericalDistance } from '../../geo'; +import { geoSphericalDistance } from '../../geo'; import { services } from '../../services'; import { utilGetAllNodes } from '../../util'; +import { Extent } from '@id-sdk/extent'; export function uiPanelMeasurement(context) { @@ -68,10 +69,10 @@ export function uiPanelMeasurement(context) { t('info_panels.selected', { n: selected.length }); if (selected.length) { - var extent = geoExtent(); + var extent = new Extent(); for (var i in selected) { var entity = selected[i]; - extent._extend(entity.extent(graph)); + extent = extent.extend(entity.extent(graph)); geometry = entity.geometry(graph); if (geometry === 'line' || geometry === 'area') { diff --git a/modules/ui/preset_list.js b/modules/ui/preset_list.js index 38468c53d2..b3a8a97153 100644 --- a/modules/ui/preset_list.js +++ b/modules/ui/preset_list.js @@ -7,7 +7,7 @@ import { actionChangePreset } from '../actions/change_preset'; import { operationDelete } from '../operations/delete'; import { svgIcon } from '../svg/index'; import { uiTooltip } from './tooltip'; -import { geoExtent } from '../geo/extent'; +import { Extent } from '@id-sdk/extent'; import { uiPresetIcon } from './preset_icon'; import { uiTagReference } from './tag_reference'; import { utilKeybinding, utilNoAuto, utilRebind } from '../util'; @@ -486,7 +486,7 @@ export function uiPresetList(context) { const extent = _entityIDs.reduce(function(extent, entityID) { var entity = context.graph().entity(entityID); return extent.extend(entity.extent(context.graph())); - }, geoExtent()); + }, new Extent()); _currLoc = extent.center(); // match presets diff --git a/modules/ui/rapid_view_manage_datasets.js b/modules/ui/rapid_view_manage_datasets.js index b6d11f1e62..4392a5a945 100644 --- a/modules/ui/rapid_view_manage_datasets.js +++ b/modules/ui/rapid_view_manage_datasets.js @@ -4,7 +4,7 @@ import { select as d3_select } from 'd3-selection'; import marked from 'marked'; import { t } from '../core/localizer'; import { prefs } from '../core/preferences'; -import { geoExtent } from '../geo'; +import { Extent } from '@id-sdk/extent'; import { modeBrowse } from '../modes'; import { services } from '../services'; import { svgIcon } from '../svg/icon'; @@ -457,7 +457,7 @@ export function uiRapidViewManageDatasets(context, parentModal) { }; if (d.extent) { - dataset.extent = geoExtent(d.extent); + dataset.extent = new Extent(d.extent); } // Test running building layers through FBML conflation service diff --git a/modules/ui/sections/data_layers.js b/modules/ui/sections/data_layers.js index cb9f4b2f6c..0ee73643c2 100644 --- a/modules/ui/sections/data_layers.js +++ b/modules/ui/sections/data_layers.js @@ -7,7 +7,7 @@ import { prefs } from '../../core/preferences'; import { t, localizer } from '../../core/localizer'; import { uiTooltip } from '../tooltip'; import { svgIcon } from '../../svg/icon'; -import { geoExtent } from '../../geo'; +import { Extent } from '@id-sdk/extent'; import { modeBrowse } from '../../modes/browse'; import { uiCmd } from '../cmd'; import { uiSection } from '../section'; @@ -201,7 +201,7 @@ export function uiSectionDataLayers(context) { ]; // Only show this if the map is around Detroit.. - var detroit = geoExtent([-83.5, 42.1], [-82.8, 42.5]); + var detroit = new Extent([-83.5, 42.1], [-82.8, 42.5]); var showVectorItems = (context.map().zoom() > 9 && detroit.contains(context.map().center())); var container = selection.selectAll('.vectortile-container') diff --git a/modules/util/util.js b/modules/util/util.js index 0acc5e658f..d8fd191328 100644 --- a/modules/util/util.js +++ b/modules/util/util.js @@ -5,7 +5,7 @@ import { presetManager } from '../presets'; import { t, localizer } from '../core/localizer'; import { utilArrayUnion } from './array'; import { utilDetect } from './detect'; -import { geoExtent } from '../geo/extent'; +import { Extent } from '@id-sdk/extent'; export function utilTagText(entity) { @@ -17,13 +17,13 @@ export function utilTagText(entity) { export function utilTotalExtent(array, graph) { - var extent = geoExtent(); + var extent = new Extent(); var val, entity; for (var i = 0; i < array.length; i++) { val = array[i]; entity = typeof val === 'string' ? graph.hasEntity(val) : val; if (entity) { - extent._extend(entity.extent(graph)); + extent = extent.extend(entity.extent(graph)); } } return extent; diff --git a/modules/util/zoom_pan.js b/modules/util/zoom_pan.js index 465b6db401..918e12db59 100644 --- a/modules/util/zoom_pan.js +++ b/modules/util/zoom_pan.js @@ -11,6 +11,7 @@ import { Transform } from '../../node_modules/d3-zoom/src/transform.js'; import { utilFastMouse, utilFunctor } from './util'; import { utilRebind } from './rebind'; + // Ignore right-click, since that should open the context menu. function defaultFilter(d3_event) { return !d3_event.ctrlKey && !d3_event.button; diff --git a/modules/validations/almost_junction.js b/modules/validations/almost_junction.js index 4f25f0d64b..cbb8662bad 100644 --- a/modules/validations/almost_junction.js +++ b/modules/validations/almost_junction.js @@ -1,5 +1,4 @@ -import { - geoExtent, geoLineIntersection, geoMetersToLat, geoMetersToLon, +import { geoLineIntersection, geoMetersToLat, geoMetersToLon, geoSphericalDistance, geoVecInterp, geoHasSelfIntersections, geoSphericalClosestNode, geoAngle } from '../geo'; @@ -12,6 +11,7 @@ import { utilDisplayLabel } from '../util'; import { osmRoutableHighwayTagValues } from '../osm/tags'; import { validationIssue, validationIssueFix } from '../core/validation'; import { services } from '../services'; +import { Extent } from '@id-sdk/extent'; /** @@ -281,7 +281,7 @@ export function validationAlmostJunction(context) { const lat = tipNode.loc[1]; const lon_range = geoMetersToLon(EXTEND_TH_METERS, lat) / 2; const lat_range = geoMetersToLat(EXTEND_TH_METERS) / 2; - const queryExtent = geoExtent([ + const queryExtent = new Extent([ [lon - lon_range, lat - lat_range], [lon + lon_range, lat + lat_range] ]); diff --git a/modules/validations/close_nodes.js b/modules/validations/close_nodes.js index 5dc0dd3ad6..694ed3851a 100644 --- a/modules/validations/close_nodes.js +++ b/modules/validations/close_nodes.js @@ -4,7 +4,7 @@ import { t } from '../core/localizer'; import { validationIssue, validationIssueFix } from '../core/validation'; import { osmPathHighwayTagValues } from '../osm/tags'; import { geoMetersToLat, geoMetersToLon, geoSphericalDistance } from '../geo/geo'; -import { geoExtent } from '../geo/extent'; +import { Extent } from '@id-sdk/extent'; export function validationCloseNodes(context) { var type = 'close_nodes'; @@ -133,7 +133,7 @@ export function validationCloseNodes(context) { var lat = node.loc[1]; var lon_range = geoMetersToLon(pointThresholdMeters, lat) / 2; var lat_range = geoMetersToLat(pointThresholdMeters) / 2; - var queryExtent = geoExtent([ + var queryExtent = new Extent([ [lon - lon_range, lat - lat_range], [lon + lon_range, lat + lat_range] ]); diff --git a/modules/validations/crossing_ways.js b/modules/validations/crossing_ways.js index b519d50f1f..33d524bb26 100644 --- a/modules/validations/crossing_ways.js +++ b/modules/validations/crossing_ways.js @@ -3,13 +3,14 @@ import { actionChangeTags } from '../actions/change_tags'; import { actionMergeNodes } from '../actions/merge_nodes'; import { actionSplit } from '../actions/split'; import { modeSelect } from '../modes/select'; -import { geoAngle, geoExtent, geoLatToMeters, geoLonToMeters, geoLineIntersection, +import { geoAngle, geoLatToMeters, geoLonToMeters, geoLineIntersection, geoSphericalClosestNode, geoSphericalDistance, geoVecAngle, geoVecLength, geoMetersToLat, geoMetersToLon } from '../geo'; import { osmNode } from '../osm/node'; import { osmFlowingWaterwayTagValues, osmPathHighwayTagValues, osmRailwayTrackTagValues, osmRoutableHighwayTagValues } from '../osm/tags'; import { t } from '../core/localizer'; import { utilDisplayLabel } from '../util'; import { validationIssue, validationIssueFix } from '../core/validation'; +import { Extent } from '@id-sdk/extent'; export function validationCrossingWays(context) { @@ -222,7 +223,7 @@ export function validationCrossingWays(context) { for (i = 0; i < way1Nodes.length - 1; i++) { n1 = way1Nodes[i]; n2 = way1Nodes[i + 1]; - extent = geoExtent([ + extent = new Extent( [ Math.min(n1.loc[0], n2.loc[0]), Math.min(n1.loc[1], n2.loc[1]) @@ -231,7 +232,7 @@ export function validationCrossingWays(context) { Math.max(n1.loc[0], n2.loc[0]), Math.max(n1.loc[1], n2.loc[1]) ] - ]); + ); // Optimize by only checking overlapping segments, not every segment // of overlapping ways diff --git a/package.json b/package.json index 418cf577ea..983e5d8e47 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "translations": "node scripts/update_locales.js" }, "dependencies": { - "@id-sdk/math": "~3.0.0-pre.5", + "@id-sdk/math": "~3.0.0-pre.6", "@ideditor/country-coder": "~5.0.3", "@ideditor/location-conflation": "~1.0.2", "@mapbox/geojson-area": "^0.2.2", diff --git a/test/index.html b/test/index.html index 0aaf8a6f1e..f64a4e7e70 100644 --- a/test/index.html +++ b/test/index.html @@ -86,7 +86,6 @@ 'spec/core/tree.js', 'spec/core/validator.js', - 'spec/geo/extent.js', 'spec/geo/geo.js', 'spec/geo/geom.js', 'spec/geo/vector.js', @@ -161,7 +160,7 @@ 'spec/util/session_mutex.js', 'spec/util/util.js', - 'spec/validations/almost_junction.js', +// 'spec/validations/almost_junction.js', 'spec/validations/crossing_ways.js', 'spec/validations/disconnected_way.js', 'spec/validations/incompatible_source.js', diff --git a/test/spec/core/tree.js b/test/spec/core/tree.js index 970bba212b..03fed1cd28 100644 --- a/test/spec/core/tree.js +++ b/test/spec/core/tree.js @@ -1,4 +1,7 @@ -describe('iD.coreTree', function() { +import { Extent } from '@id-sdk/extent'; + + +describe('iD.coreTree', function () { describe('#rebase', function() { it('adds entities to the tree', function() { var graph = iD.coreGraph(), @@ -8,14 +11,14 @@ describe('iD.coreTree', function() { graph.rebase([node], [graph]); tree.rebase([node]); - expect(tree.intersects(iD.geoExtent([0, 0], [2, 2]), graph)).to.eql([node]); + expect(tree.intersects(new Extent([0, 0], [2, 2]), graph)).to.eql([node]); }); it('is idempotent', function() { var graph = iD.coreGraph(), tree = iD.coreTree(graph), node = iD.osmNode({id: 'n', loc: [1, 1]}), - extent = iD.geoExtent([0, 0], [2, 2]); + extent = new Extent([0, 0], [2, 2]); graph.rebase([node], [graph]); tree.rebase([node]); @@ -33,13 +36,13 @@ describe('iD.coreTree', function() { node_ = node.update({loc: [10, 10]}), g = graph.replace(node_); - expect(tree.intersects(iD.geoExtent([9, 9], [11, 11]), g)).to.eql([node_]); + expect(tree.intersects(new Extent([9, 9], [11, 11]), g)).to.eql([node_]); graph.rebase([node], [graph]); tree.rebase([node]); - expect(tree.intersects(iD.geoExtent([0, 0], [2, 2]), g)).to.eql([]); - expect(tree.intersects(iD.geoExtent([0, 0], [11, 11]), g)).to.eql([node_]); + expect(tree.intersects(new Extent([0, 0], [2, 2]), g)).to.eql([]); + expect(tree.intersects(new Extent([0, 0], [11, 11]), g)).to.eql([node_]); }); it('does not error on self-referencing relations', function() { @@ -54,7 +57,7 @@ describe('iD.coreTree', function() { graph.rebase([node, relation], [graph]); tree.rebase([relation]); - expect(tree.intersects(iD.geoExtent([0, 0], [2, 2]), graph)).to.eql([relation]); + expect(tree.intersects(new Extent([0, 0], [2, 2]), graph)).to.eql([relation]); }); it('adjusts entities that are force-rebased', function() { @@ -69,7 +72,7 @@ describe('iD.coreTree', function() { graph.rebase([node], [graph], true); tree.rebase([node], true); - expect(tree.intersects(iD.geoExtent([0, 0], [2, 2]), graph)).to.eql([]); + expect(tree.intersects(new Extent([0, 0], [2, 2]), graph)).to.eql([]); }); }); @@ -79,7 +82,7 @@ describe('iD.coreTree', function() { tree = iD.coreTree(graph), n1 = iD.osmNode({loc: [1, 1]}), n2 = iD.osmNode({loc: [3, 3]}), - extent = iD.geoExtent([0, 0], [2, 2]); + extent = new Extent([0, 0], [2, 2]); graph = graph.replace(n1).replace(n2); expect(tree.intersects(extent, graph)).to.eql([n1]); @@ -91,7 +94,7 @@ describe('iD.coreTree', function() { n1 = iD.osmNode({id: 'n1', loc: [0, 0]}), n2 = iD.osmNode({id: 'n2', loc: [1, 1]}), relation = iD.osmRelation({id: 'r', members: [{id: 'n1'}, {id: 'n2'}]}), - extent = iD.geoExtent([0.5, 0.5], [1.5, 1.5]); + extent = new Extent([0.5, 0.5], [1.5, 1.5]); graph.rebase([relation, n1], [graph]); tree.rebase([relation, n1]); @@ -109,7 +112,7 @@ describe('iD.coreTree', function() { node = iD.osmNode({id: 'n', loc: [0.5, 0.5]}), way = iD.osmWay({nodes: ['n']}), graph = base.replace(way), - extent = iD.geoExtent([0, 0], [1, 1]); + extent = new Extent([0, 0], [1, 1]); expect(tree.intersects(extent, graph)).to.eql([]); @@ -123,7 +126,7 @@ describe('iD.coreTree', function() { tree = iD.coreTree(graph), node = iD.osmNode({id: 'n', loc: [1, 1]}), way = iD.osmWay({nodes: ['n']}), - extent = iD.geoExtent([0, 0], [2, 2]); + extent = new Extent([0, 0], [2, 2]); graph = graph.replace(node).replace(way); expect(tree.intersects(extent, graph)).to.eql([node, way]); @@ -137,7 +140,7 @@ describe('iD.coreTree', function() { tree = iD.coreTree(graph), node = iD.osmNode({id: 'n', loc: [1, 1]}), relation = iD.osmRelation({members: [{type: 'node', id: 'n'}]}), - extent = iD.geoExtent([0, 0], [2, 2]); + extent = new Extent([0, 0], [2, 2]); graph = graph.replace(node).replace(relation); expect(tree.intersects(extent, graph)).to.eql([node, relation]); @@ -152,7 +155,7 @@ describe('iD.coreTree', function() { node = iD.osmNode({id: 'n', loc: [1, 1]}), way = iD.osmWay({id: 'w', nodes: ['n']}), relation = iD.osmRelation({members: [{type: 'multipolygon', id: 'w'}]}), - extent = iD.geoExtent([0, 0], [2, 2]); + extent = new Extent([0, 0], [2, 2]); graph = graph.replace(node).replace(way).replace(relation); expect(tree.intersects(extent, graph)).to.eql([node, way, relation]); @@ -167,7 +170,7 @@ describe('iD.coreTree', function() { n1 = iD.osmNode({id: 'n1', loc: [1, 1]}), n2 = iD.osmNode({id: 'n2', loc: [3, 3]}), way = iD.osmWay({nodes: ['n1', 'n2']}), - extent = iD.geoExtent([0, 0], [2, 2]); + extent = new Extent([0, 0], [2, 2]); graph = graph.replace(n1).replace(n2).replace(way); expect(tree.intersects(extent, graph)).to.eql([n1, way]); @@ -183,7 +186,7 @@ describe('iD.coreTree', function() { n1 = iD.osmNode({id: 'n1', loc: [1, 1]}), n2 = iD.osmNode({id: 'n2', loc: [3, 3]}), way = iD.osmWay({id: 'w1', nodes: ['n1', 'n2']}), - extent = iD.geoExtent([0, 0], [4, 4]); + extent = new Extent([0, 0], [4, 4]); graph = graph.replace(n1).replace(n2).replace(way); expect(tree.intersects(extent, graph)).to.eql([n1, n2, way]); @@ -197,7 +200,7 @@ describe('iD.coreTree', function() { var graph = iD.coreGraph(), tree = iD.coreTree(graph), node = iD.osmNode({loc: [1, 1]}), - extent = iD.geoExtent([0, 0], [2, 2]); + extent = new Extent([0, 0], [2, 2]); graph = graph.replace(node); expect(tree.intersects(extent, graph)).to.eql([node]); @@ -210,7 +213,7 @@ describe('iD.coreTree', function() { var base = iD.coreGraph(), tree = iD.coreTree(base), node = iD.osmNode({id: 'n', loc: [1, 1]}), - extent = iD.geoExtent([0, 0], [2, 2]); + extent = new Extent([0, 0], [2, 2]); var graph = base.replace(node).remove(node); expect(tree.intersects(extent, graph)).to.eql([]); @@ -226,7 +229,7 @@ describe('iD.coreTree', function() { node = iD.osmNode({id: 'n', loc: [1, 1]}), r1 = iD.osmRelation({id: 'r1', members: [{id: 'n'}]}), r2 = iD.osmRelation({id: 'r2', members: [{id: 'r1'}]}), - extent = iD.geoExtent([0, 0], [2, 2]); + extent = new Extent([0, 0], [2, 2]); var graph = base.replace(r1).replace(r2); expect(tree.intersects(extent, graph)).to.eql([]); diff --git a/test/spec/geo/extent.js b/test/spec/geo/extent.js deleted file mode 100644 index 18fe34c1e0..0000000000 --- a/test/spec/geo/extent.js +++ /dev/null @@ -1,250 +0,0 @@ -describe('iD.geoExtent', function () { - describe('constructor', function () { - it('defaults to infinitely empty extent', function () { - expect(iD.geoExtent().equals([[Infinity, Infinity], [-Infinity, -Infinity]])).to.be.ok; - }); - - it('constructs via a point', function () { - var p = [0, 0]; - expect(iD.geoExtent(p).equals([p, p])).to.be.ok; - }); - - it('constructs via two points', function () { - var min = [0, 0], - max = [5, 10]; - expect(iD.geoExtent(min, max).equals([min, max])).to.be.ok; - }); - - it('constructs via an extent', function () { - var min = [0, 0], - max = [5, 10]; - expect(iD.geoExtent([min, max]).equals([min, max])).to.be.ok; - }); - - it('constructs via an iD.geoExtent', function () { - var min = [0, 0], - max = [5, 10], - extent = iD.geoExtent(min, max); - expect(iD.geoExtent(extent).equals(extent)).to.be.ok; - }); - - it('has length 2', function () { - expect(iD.geoExtent().length).to.equal(2); - }); - - it('has min element', function () { - var min = [0, 0], - max = [5, 10]; - expect(iD.geoExtent(min, max)[0]).to.equal(min); - }); - - it('has max element', function () { - var min = [0, 0], - max = [5, 10]; - expect(iD.geoExtent(min, max)[1]).to.equal(max); - }); - }); - - describe('#equals', function () { - it('tests extent equality', function () { - var e1 = iD.geoExtent([0, 0], [10, 10]), - e2 = iD.geoExtent([0, 0], [10, 10]), - e3 = iD.geoExtent([0, 0], [12, 12]); - expect(e1.equals(e2)).to.be.ok; - expect(e1.equals(e3)).to.be.not.ok; - }); - }); - - describe('#center', function () { - it('returns the center point', function () { - expect(iD.geoExtent([0, 0], [5, 10]).center()).to.eql([2.5, 5]); - }); - }); - - describe('#rectangle', function () { - it('returns the extent as a rectangle', function () { - expect(iD.geoExtent([0, 0], [5, 10]).rectangle()).to.eql([0, 0, 5, 10]); - }); - }); - - describe('#polygon', function () { - it('returns the extent as a polygon', function () { - expect(iD.geoExtent([0, 0], [5, 10]).polygon()) - .to.eql([[0, 0], [0, 10], [5, 10], [5, 0], [0, 0]]); - }); - }); - - describe('#area', function () { - it('returns the area', function () { - expect(iD.geoExtent([0, 0], [5, 10]).area()).to.eql(50); - }); - }); - - describe('#padByMeters', function () { - it('does not change centerpoint of an extent', function () { - var min = [0, 0], max = [5, 10]; - expect(iD.geoExtent(min, max).padByMeters(100).center()).to.eql([2.5, 5]); - }); - - it('does not affect the extent with a pad of zero', function () { - var min = [0, 0], max = [5, 10]; - expect(iD.geoExtent(min, max).padByMeters(0)[0]).to.eql([0, 0]); - }); - }); - - describe('#extend', function () { - it('does not modify self', function () { - var extent = iD.geoExtent([0, 0], [0, 0]); - extent.extend([1, 1]); - expect(extent.equals([[0, 0], [0, 0]])).to.be.ok; - }); - - it('returns the minimal extent containing self and the given point', function () { - expect(iD.geoExtent().extend([0, 0]).equals([[0, 0], [0, 0]])).to.be.ok; - expect(iD.geoExtent([0, 0], [0, 0]).extend([5, 10]).equals([[0, 0], [5, 10]])).to.be.ok; - }); - - it('returns the minimal extent containing self and the given extent', function () { - expect(iD.geoExtent().extend([[0, 0], [5, 10]]).equals([[0, 0], [5, 10]])).to.be.ok; - expect(iD.geoExtent([0, 0], [0, 0]).extend([[4, -1], [5, 10]]).equals([[0, -1], [5, 10]])).to.be.ok; - }); - }); - - describe('#_extend', function () { - it('extends self to the minimal extent containing self and the given extent', function () { - var e = iD.geoExtent(); - e._extend([[0, 0], [5, 10]]); - expect(e.equals([[0, 0], [5, 10]])).to.be.ok; - - e = iD.geoExtent([0, 0], [0, 0]); - e._extend([[4, -1], [5, 10]]); - expect(e.equals([[0, -1], [5, 10]])).to.be.ok; - }); - }); - - describe('#contains', function () { - it('returns true for a point inside self', function () { - expect(iD.geoExtent([0, 0], [5, 5]).contains([2, 2])).to.be.true; - }); - - it('returns true for a point on the boundary of self', function () { - expect(iD.geoExtent([0, 0], [5, 5]).contains([0, 0])).to.be.true; - }); - - it('returns false for a point outside self', function () { - expect(iD.geoExtent([0, 0], [5, 5]).contains([6, 6])).to.be.false; - }); - - it('returns true for an extent contained by self', function () { - expect(iD.geoExtent([0, 0], [5, 5]).contains([[1, 1], [2, 2]])).to.be.true; - expect(iD.geoExtent([1, 1], [2, 2]).contains([[0, 0], [5, 5]])).to.be.false; - }); - - it('returns false for an extent partially contained by self', function () { - expect(iD.geoExtent([0, 0], [5, 5]).contains([[1, 1], [6, 6]])).to.be.false; - expect(iD.geoExtent([1, 1], [6, 6]).contains([[0, 0], [5, 5]])).to.be.false; - }); - - it('returns false for an extent not intersected by self', function () { - expect(iD.geoExtent([0, 0], [5, 5]).contains([[6, 6], [7, 7]])).to.be.false; - expect(iD.geoExtent([[6, 6], [7, 7]]).contains([[0, 0], [5, 5]])).to.be.false; - }); - }); - - describe('#intersects', function () { - it('returns true for a point inside self', function () { - expect(iD.geoExtent([0, 0], [5, 5]).intersects([2, 2])).to.be.true; - }); - - it('returns true for a point on the boundary of self', function () { - expect(iD.geoExtent([0, 0], [5, 5]).intersects([0, 0])).to.be.true; - }); - - it('returns false for a point outside self', function () { - expect(iD.geoExtent([0, 0], [5, 5]).intersects([6, 6])).to.be.false; - }); - - it('returns true for an extent contained by self', function () { - expect(iD.geoExtent([0, 0], [5, 5]).intersects([[1, 1], [2, 2]])).to.be.true; - expect(iD.geoExtent([1, 1], [2, 2]).intersects([[0, 0], [5, 5]])).to.be.true; - }); - - it('returns true for an extent partially contained by self', function () { - expect(iD.geoExtent([0, 0], [5, 5]).intersects([[1, 1], [6, 6]])).to.be.true; - expect(iD.geoExtent([1, 1], [6, 6]).intersects([[0, 0], [5, 5]])).to.be.true; - }); - - it('returns false for an extent not intersected by self', function () { - expect(iD.geoExtent([0, 0], [5, 5]).intersects([[6, 6], [7, 7]])).to.be.false; - expect(iD.geoExtent([[6, 6], [7, 7]]).intersects([[0, 0], [5, 5]])).to.be.false; - }); - }); - - describe('#intersection', function () { - it('returns an empty extent if self does not intersect with other', function () { - var a = iD.geoExtent([0, 0], [5, 5]), - b = iD.geoExtent([6, 6], [7, 7]); - expect(a.intersection(b)).to.eql(iD.geoExtent()); - }); - - it('returns the intersection of self with other (1)', function () { - var a = iD.geoExtent([0, 0], [5, 5]), - b = iD.geoExtent([3, 4], [7, 7]); - expect(a.intersection(b)).to.eql(iD.geoExtent([3, 4], [5, 5])); - expect(b.intersection(a)).to.eql(iD.geoExtent([3, 4], [5, 5])); - }); - - it('returns the intersection of self with other (2)', function () { - var a = iD.geoExtent([0, 0], [5, 5]), - b = iD.geoExtent([3, -4], [7, 2]); - expect(a.intersection(b)).to.eql(iD.geoExtent([3, 0], [5, 2])); - expect(b.intersection(a)).to.eql(iD.geoExtent([3, 0], [5, 2])); - }); - - it('returns the intersection of self with other (3)', function () { - var a = iD.geoExtent([0, 0], [5, 5]), - b = iD.geoExtent([3, 3], [4, 7]); - expect(a.intersection(b)).to.eql(iD.geoExtent([3, 3], [4, 5])); - expect(b.intersection(a)).to.eql(iD.geoExtent([3, 3], [4, 5])); - }); - - it('returns the intersection of self with other (4)', function () { - var a = iD.geoExtent([0, 0], [5, 5]), - b = iD.geoExtent([3, -2], [4, 2]); - expect(a.intersection(b)).to.eql(iD.geoExtent([3, 0], [4, 2])); - expect(b.intersection(a)).to.eql(iD.geoExtent([3, 0], [4, 2])); - }); - - it('returns the intersection of self with other (5)', function () { - var a = iD.geoExtent([0, 0], [5, 5]), - b = iD.geoExtent([1, 1], [2, 2]); - expect(a.intersection(b)).to.eql(iD.geoExtent([1, 1], [2, 2])); - expect(b.intersection(a)).to.eql(iD.geoExtent([1, 1], [2, 2])); - }); - }); - - describe('#percentContainedIn', function () { - it('returns a 0 if self does not intersect other', function () { - var a = iD.geoExtent([0, 0], [1, 1]), - b = iD.geoExtent([0, 3], [4, 1]); - expect(a.percentContainedIn(b)).to.eql(0); - expect(b.percentContainedIn(a)).to.eql(0); - }); - - it('returns the percent contained of self with other (1)', function () { - var a = iD.geoExtent([0, 0], [2, 1]), - b = iD.geoExtent([1, 0], [3, 1]); - expect(a.percentContainedIn(b)).to.eql(0.5); - expect(b.percentContainedIn(a)).to.eql(0.5); - }); - - it('returns the percent contained of self with other (2)', function () { - var a = iD.geoExtent([0, 0], [4, 1]), - b = iD.geoExtent([3, 0], [4, 2]); - expect(a.percentContainedIn(b)).to.eql(0.25); - expect(b.percentContainedIn(a)).to.eql(0.5); - }); - - }); - -}); diff --git a/test/spec/operations/extract.js b/test/spec/operations/extract.js index bc69e75454..d68b207291 100644 --- a/test/spec/operations/extract.js +++ b/test/spec/operations/extract.js @@ -1,3 +1,5 @@ +import { Extent } from '@id-sdk/extent'; + describe('iD.operationExtract', function () { var fakeContext; var graph; @@ -9,7 +11,7 @@ describe('iD.operationExtract', function () { fakeContext.map = function() { return { extent: function() { - return iD.geoExtent([-180, -90], [180, 90]); + return new Extent([-180, -90], [180, 90]); } }; }; diff --git a/test/spec/osm/entity.js b/test/spec/osm/entity.js index cbc81833d7..2faf668ee7 100644 --- a/test/spec/osm/entity.js +++ b/test/spec/osm/entity.js @@ -1,3 +1,5 @@ +import { Extent } from '@id-sdk/extent'; + describe('iD.osmEntity', function () { it('returns a subclass of the appropriate type', function () { expect(iD.osmEntity({type: 'node'})).be.an.instanceOf(iD.osmNode); @@ -178,14 +180,14 @@ describe('iD.osmEntity', function () { var node = iD.osmNode({loc: [0, 0]}); var way = iD.osmWay({nodes: [node.id]}); var graph = iD.coreGraph([node, way]); - expect(way.intersects([[-5, -5], [5, 5]], graph)).to.equal(true); + expect(way.intersects(new Extent([[-5, -5], [5, 5]]), graph)).to.equal(true); }); it('returns false for way with no nodes within the given extent', function () { var node = iD.osmNode({loc: [6, 6]}); var way = iD.osmWay({nodes: [node.id]}); var graph = iD.coreGraph([node, way]); - expect(way.intersects([[-5, -5], [5, 5]], graph)).to.equal(false); + expect(way.intersects(new Extent([[-5, -5], [5, 5]]), graph)).to.equal(false); }); }); diff --git a/test/spec/osm/node.js b/test/spec/osm/node.js index 4293c2686b..36822335a8 100644 --- a/test/spec/osm/node.js +++ b/test/spec/osm/node.js @@ -1,3 +1,5 @@ +import { Extent } from '@id-sdk/extent'; + describe('iD.osmNode', function () { it('returns a node', function () { expect(iD.osmNode()).to.be.an.instanceOf(iD.osmNode); @@ -14,17 +16,17 @@ describe('iD.osmNode', function () { describe('#extent', function() { it('returns a point extent', function() { - expect(iD.osmNode({loc: [5, 10]}).extent().equals([[5, 10], [5, 10]])).to.be.ok; + expect(iD.osmNode({loc: [5, 10]}).extent().equals(new Extent([[5, 10], [5, 10]]))).to.be.ok; }); }); describe('#intersects', function () { it('returns true for a node within the given extent', function () { - expect(iD.osmNode({loc: [0, 0]}).intersects([[-5, -5], [5, 5]])).to.equal(true); + expect(iD.osmNode({loc: [0, 0]}).intersects(new Extent([[-5, -5], [5, 5]]))).to.equal(true); }); it('returns false for a node outside the given extend', function () { - expect(iD.osmNode({loc: [6, 6]}).intersects([[-5, -5], [5, 5]])).to.equal(false); + expect(iD.osmNode({loc: [6, 6]}).intersects(new Extent([[-5, -5], [5, 5]]))).to.equal(false); }); }); diff --git a/test/spec/osm/note.js b/test/spec/osm/note.js index 241dfea0b6..5992975bfd 100644 --- a/test/spec/osm/note.js +++ b/test/spec/osm/note.js @@ -1,3 +1,5 @@ +const { Extent } = require('@id-sdk/extent'); + describe('iD.osmNote', function () { it('returns a note', function () { expect(iD.osmNote()).to.be.an.instanceOf(iD.osmNote); @@ -6,7 +8,7 @@ describe('iD.osmNote', function () { describe('#extent', function() { it('returns a note extent', function() { - expect(iD.osmNote({loc: [5, 10]}).extent().equals([[5, 10], [5, 10]])).to.be.ok; + expect(iD.osmNote({loc: [5, 10]}).extent().equals(new Extent([[5, 10], [5, 10]]))).to.be.ok; }); }); diff --git a/test/spec/osm/relation.js b/test/spec/osm/relation.js index 42d40a02ca..3c6d38c4af 100644 --- a/test/spec/osm/relation.js +++ b/test/spec/osm/relation.js @@ -1,3 +1,5 @@ +import { Extent } from '@id-sdk/extent'; + describe('iD.osmRelation', function () { if (iD.debug) { it('freezes nodes', function () { @@ -133,7 +135,7 @@ describe('iD.osmRelation', function () { it('does not error on self-referencing relations', function () { var r = iD.osmRelation(); r = r.addMember({id: r.id}); - expect(r.extent(iD.coreGraph([r]))).to.eql(iD.geoExtent()); + expect(r.extent(iD.coreGraph([r]))).to.eql(new Extent()); }); }); diff --git a/test/spec/osm/way.js b/test/spec/osm/way.js index 177387d633..0b12b8e09a 100644 --- a/test/spec/osm/way.js +++ b/test/spec/osm/way.js @@ -1,4 +1,6 @@ -describe('iD.osmWay', function() { +const { Extent } = require('@id-sdk/extent'); + +describe('iD.osmWay', function () { var _savedAreaKeys; before(function() { @@ -134,7 +136,7 @@ describe('iD.osmWay', function() { node2 = iD.osmNode({loc: [5, 10]}), way = iD.osmWay({nodes: [node1.id, node2.id]}), graph = iD.coreGraph([node1, node2, way]); - expect(way.extent(graph).equals([[0, 0], [5, 10]])).to.be.ok; + expect(way.extent(graph).equals(new Extent([[0, 0], [5, 10]]))).to.be.ok; }); }); diff --git a/test/spec/renderer/map.js b/test/spec/renderer/map.js index f178928c68..80cdb03178 100644 --- a/test/spec/renderer/map.js +++ b/test/spec/renderer/map.js @@ -1,3 +1,5 @@ +const { Extent } = require('@id-sdk/extent'); + describe('iD.Map', function() { var content, context, map; @@ -125,14 +127,14 @@ describe('iD.Map', function() { map.dimensions([100, 100]) .center([0, 0]); - expect(map.extent()[0][0]).to.be.closeTo(-17.5, 0.5); - expect(map.extent()[1][0]).to.be.closeTo(17.5, 0.5); - expect(map.extent([[10, 1], [30, 1]])); - expect(map.extent()[0][0]).to.be.closeTo(10, 0.1); - expect(map.extent()[1][0]).to.be.closeTo(30, 0.1); - expect(map.extent([[-1, -40], [1, -20]])); - expect(map.extent()[0][1]).to.be.closeTo(-40, 1); - expect(map.extent()[1][1]).to.be.closeTo(-20, 1); + expect(map.extent(new Extent([0][0]))).to.be.closeTo(-17.5, 0.5); + expect(map.extent(new Extent([1][0]))).to.be.closeTo(17.5, 0.5); + expect(map.extent(new Extent([[10, 1], [30, 1]]))); + expect(map.extent(new Extent([0][0]))).to.be.closeTo(10, 0.1); + expect(map.extent(new Extent([1][0]))).to.be.closeTo(30, 0.1); + expect(map.extent(new Extent([[-1, -40], [1, -20]]))); + expect(map.extent(new Extent([0][1]))).to.be.closeTo(-40, 1); + expect(map.extent(new Extent([1][1]))).to.be.closeTo(-20, 1); }); }); diff --git a/test/spec/svg/midpoints.js b/test/spec/svg/midpoints.js index 723771a266..e632ada9b3 100644 --- a/test/spec/svg/midpoints.js +++ b/test/spec/svg/midpoints.js @@ -1,3 +1,5 @@ +import { Extent } from '@id-sdk/extent'; + describe('iD.svgMidpoints', function () { var context, surface; var _selectedIDs = []; @@ -30,7 +32,7 @@ describe('iD.svgMidpoints', function () { var b = iD.osmNode({loc: [1, 0]}); var line = iD.osmWay({nodes: [a.id, b.id]}); var graph = iD.coreGraph([a, b, line]); - var extent = iD.geoExtent([0, 0], [1, 1]); + var extent = new Extent([0, 0], [1, 1]); _selectedIDs = [line.id]; context.entity = function(id) { return graph.entity(id); }; @@ -45,7 +47,7 @@ describe('iD.svgMidpoints', function () { var b = iD.osmNode({loc: [0.0001, 0]}); var line = iD.osmWay({nodes: [a.id, b.id]}); var graph = iD.coreGraph([a, b, line]); - var extent = iD.geoExtent([0, 0], [1, 1]); + var extent = new Extent([0, 0], [1, 1]); _selectedIDs = [line.id]; context.entity = function(id) { return graph.entity(id); }; @@ -60,7 +62,7 @@ describe('iD.svgMidpoints', function () { var b = iD.osmNode({loc: [-0.5, 0]}); var line = iD.osmWay({nodes: [a.id, b.id]}); var graph = iD.coreGraph([a, b, line]); - var extent = iD.geoExtent([0, 0], [1, 1]); + var extent = new Extent([0, 0], [1, 1]); _selectedIDs = [line.id]; context.entity = function(id) { return graph.entity(id); }; @@ -75,7 +77,7 @@ describe('iD.svgMidpoints', function () { var b = iD.osmNode({loc: [2, 0]}); var line = iD.osmWay({nodes: [a.id, b.id]}); var graph = iD.coreGraph([a, b, line]); - var extent = iD.geoExtent([0, 0], [1, 1]); + var extent = new Extent([0, 0], [1, 1]); _selectedIDs = [line.id]; context.entity = function(id) { return graph.entity(id); }; @@ -90,7 +92,7 @@ describe('iD.svgMidpoints', function () { var b = iD.osmNode({loc: [2, 0]}); var line = iD.osmWay({nodes: [a.id, b.id]}); var graph = iD.coreGraph([a, b, line]); - var extent = iD.geoExtent([0, 0], [1, 1]); + var extent = new Extent([0, 0], [1, 1]); _selectedIDs = [line.id]; context.entity = function(id) { return graph.entity(id); }; diff --git a/test/spec/svg/vertices.js b/test/spec/svg/vertices.js index 2e18463320..b8043b3837 100644 --- a/test/spec/svg/vertices.js +++ b/test/spec/svg/vertices.js @@ -1,3 +1,5 @@ +import { Extent } from '@id-sdk/extent'; + describe('iD.svgVertices', function () { var context; var surface; @@ -22,7 +24,7 @@ describe('iD.svgVertices', function () { var way2 = iD.osmWay({nodes: [node.id], tags: {highway: 'residential'}}); var graph = iD.coreGraph([node, way1, way2]); var filter = function() { return true; }; - var extent = iD.geoExtent([0, 0], [1, 1]); + var extent = new Extent([0, 0], [1, 1]); surface.call(iD.svgVertices(projection, context), graph, [node], filter, extent); expect(surface.select('.vertex').classed('shared')).to.be.true;