@vim3d/geojson 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,24 @@
1
+ Copyright (c) 2013, Dan Lynch
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions are met:
6
+ * Redistributions of source code must retain the above copyright
7
+ notice, this list of conditions and the following disclaimer.
8
+ * Redistributions in binary form must reproduce the above copyright
9
+ notice, this list of conditions and the following disclaimer in the
10
+ documentation and/or other materials provided with the distribution.
11
+ * Neither the name of the <organization> nor the
12
+ names of its contributors may be used to endorse or promote products
13
+ derived from this software without specific prior written permission.
14
+
15
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18
+ DISCLAIMED. IN NO EVENT SHALL Dan Lynch BE LIABLE FOR ANY
19
+ DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22
+ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package/README.md CHANGED
@@ -1,3 +1,14 @@
1
- # Temporary Holding Version
1
+ # @vim3d/geojson
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Load GeoJSON for Vim3D scenes at load time and resample it so heavy city and
4
+ neighborhood boundaries stay light enough to render. GeoJSON is fetched by the
5
+ host when a scene loads; it is never bundled or committed.
6
+
7
+ ```ts
8
+ import { simplifyLine } from '@vim3d/geojson';
9
+
10
+ const light = simplifyLine(ring, 0.0001);
11
+ ```
12
+
13
+ `simplifyLine` is Douglas-Peucker simplification with no dependencies. It keeps
14
+ the first and last positions and any elevation values.
package/esm/index.js ADDED
@@ -0,0 +1,38 @@
1
+ export const name = '@vim3d/geojson';
2
+ function perpendicularDistanceSq(p, a, b) {
3
+ const dx = b[0] - a[0];
4
+ const dy = b[1] - a[1];
5
+ const lengthSq = dx * dx + dy * dy;
6
+ let t = lengthSq === 0 ? 0 : ((p[0] - a[0]) * dx + (p[1] - a[1]) * dy) / lengthSq;
7
+ t = Math.max(0, Math.min(1, t));
8
+ const x = a[0] + t * dx - p[0];
9
+ const y = a[1] + t * dy - p[1];
10
+ return x * x + y * y;
11
+ }
12
+ /** Douglas-Peucker simplification; keeps the first and last positions. */
13
+ export function simplifyLine(points, tolerance) {
14
+ if (points.length <= 2 || !(tolerance > 0))
15
+ return points.slice();
16
+ const toleranceSq = tolerance * tolerance;
17
+ const keep = new Uint8Array(points.length);
18
+ keep[0] = 1;
19
+ keep[points.length - 1] = 1;
20
+ const stack = [[0, points.length - 1]];
21
+ while (stack.length) {
22
+ const [first, last] = stack.pop();
23
+ let maxSq = 0;
24
+ let index = -1;
25
+ for (let i = first + 1; i < last; i++) {
26
+ const d = perpendicularDistanceSq(points[i], points[first], points[last]);
27
+ if (d > maxSq) {
28
+ maxSq = d;
29
+ index = i;
30
+ }
31
+ }
32
+ if (index !== -1 && maxSq > toleranceSq) {
33
+ keep[index] = 1;
34
+ stack.push([first, index], [index, last]);
35
+ }
36
+ }
37
+ return points.filter((_, i) => keep[i] === 1);
38
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "module"
3
+ }
package/index.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ export declare const name = "@vim3d/geojson";
2
+ export type Position = [number, number] | [number, number, number];
3
+ /** Douglas-Peucker simplification; keeps the first and last positions. */
4
+ export declare function simplifyLine<T extends Position>(points: readonly T[], tolerance: number): T[];
package/index.js ADDED
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.name = void 0;
4
+ exports.simplifyLine = simplifyLine;
5
+ exports.name = '@vim3d/geojson';
6
+ function perpendicularDistanceSq(p, a, b) {
7
+ const dx = b[0] - a[0];
8
+ const dy = b[1] - a[1];
9
+ const lengthSq = dx * dx + dy * dy;
10
+ let t = lengthSq === 0 ? 0 : ((p[0] - a[0]) * dx + (p[1] - a[1]) * dy) / lengthSq;
11
+ t = Math.max(0, Math.min(1, t));
12
+ const x = a[0] + t * dx - p[0];
13
+ const y = a[1] + t * dy - p[1];
14
+ return x * x + y * y;
15
+ }
16
+ /** Douglas-Peucker simplification; keeps the first and last positions. */
17
+ function simplifyLine(points, tolerance) {
18
+ if (points.length <= 2 || !(tolerance > 0))
19
+ return points.slice();
20
+ const toleranceSq = tolerance * tolerance;
21
+ const keep = new Uint8Array(points.length);
22
+ keep[0] = 1;
23
+ keep[points.length - 1] = 1;
24
+ const stack = [[0, points.length - 1]];
25
+ while (stack.length) {
26
+ const [first, last] = stack.pop();
27
+ let maxSq = 0;
28
+ let index = -1;
29
+ for (let i = first + 1; i < last; i++) {
30
+ const d = perpendicularDistanceSq(points[i], points[first], points[last]);
31
+ if (d > maxSq) {
32
+ maxSq = d;
33
+ index = i;
34
+ }
35
+ }
36
+ if (index !== -1 && maxSq > toleranceSq) {
37
+ keep[index] = 1;
38
+ stack.push([first, index], [index, last]);
39
+ }
40
+ }
41
+ return points.filter((_, i) => keep[i] === 1);
42
+ }
package/package.json CHANGED
@@ -1,6 +1,36 @@
1
1
  {
2
2
  "name": "@vim3d/geojson",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.2.0",
4
+ "description": "Fetch GeoJSON at load time and resample it for Vim3D scenes.",
5
+ "author": "Dan Lynch <pyramation@gmail.com>",
6
+ "homepage": "https://github.com/pyramation/vim3d/tree/master/js/packages/geojson",
7
+ "license": "BSD-3-Clause",
8
+ "main": "index.js",
9
+ "module": "esm/index.js",
10
+ "types": "index.d.ts",
11
+ "sideEffects": false,
12
+ "publishConfig": {
13
+ "access": "public",
14
+ "directory": "dist"
15
+ },
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "https://github.com/pyramation/vim3d"
19
+ },
20
+ "bugs": {
21
+ "url": "https://github.com/pyramation/vim3d/issues"
22
+ },
23
+ "scripts": {
24
+ "clean": "makage clean",
25
+ "prepack": "npm run build",
26
+ "build": "makage build && cp scripts/esm-package.json dist/esm/package.json",
27
+ "build:dev": "makage build --dev && cp scripts/esm-package.json dist/esm/package.json",
28
+ "lint": "eslint . --fix",
29
+ "test": "jest",
30
+ "test:watch": "jest --watch"
31
+ },
32
+ "devDependencies": {
33
+ "makage": "^0.8.0"
34
+ },
35
+ "gitHead": "b641c4ae556dd92d80d858cfe02d7e47f5af89bb"
36
+ }