Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Math/extent conversion #272

Merged
merged 11 commits into from
Aug 2, 2021
Merged
6 changes: 4 additions & 2 deletions modules/behavior/lasso.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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' &&
Expand Down
9 changes: 5 additions & 4 deletions modules/behavior/paste.js
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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 = [];

Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions modules/core/rapid_context.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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');
}
};
Expand Down
6 changes: 3 additions & 3 deletions modules/core/validation/models.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { geoExtent } from '../../geo';
import { Extent } from '@id-sdk/extent';
import { t } from '../../core/localizer';

export function validationIssue(attrs) {
Expand Down Expand Up @@ -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;
};
Expand Down
4 changes: 2 additions & 2 deletions modules/core/validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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
Expand Down
146 changes: 0 additions & 146 deletions modules/geo/extent.js

This file was deleted.

6 changes: 3 additions & 3 deletions modules/geo/geom.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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) {
Expand Down
3 changes: 0 additions & 3 deletions modules/geo/index.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
1 change: 1 addition & 0 deletions modules/geo/raw_mercator.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Extent } from '@id-sdk/extent';
import {
geoMercatorRaw as d3_geoMercatorRaw,
geoTransform as d3_geoTransform
Expand Down
13 changes: 7 additions & 6 deletions modules/modes/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
}

Expand Down
9 changes: 5 additions & 4 deletions modules/modes/select_data.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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));
};

Expand All @@ -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()
Expand Down
8 changes: 5 additions & 3 deletions modules/operations/paste.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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 = [];

Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions modules/osm/changeset.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { osmEntity } from './entity';
import { geoExtent } from '../geo';
import { Extent } from '@id-sdk/extent';


export function osmChangeset() {
Expand All @@ -21,7 +21,7 @@ Object.assign(osmChangeset.prototype, {


extent: function() {
return new geoExtent();
return new new Extent();
},


Expand Down
Loading