Skip to content

Commit 1527c64

Browse files
committed
test(Feature2Mesh): add test to calculate the difference with and without proj4.
1 parent 53a42a6 commit 1527c64

File tree

4 files changed

+229
-0
lines changed

4 files changed

+229
-0
lines changed

test/data/geojson/map.geojson.json

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"type": "FeatureCollection",
3+
"features": [
4+
{
5+
"type": "Feature",
6+
"properties": {},
7+
"geometry": {
8+
"type": "Polygon",
9+
"coordinates": [
10+
[
11+
[
12+
4.193944931030273,
13+
48.11528236584
14+
],
15+
[
16+
4.20201301574707,
17+
48.11528236584
18+
],
19+
[
20+
4.20201301574707,
21+
48.120611313681046
22+
],
23+
[
24+
4.193944931030273,
25+
48.120611313681046
26+
],
27+
[
28+
4.193944931030273,
29+
48.11528236584
30+
]
31+
]
32+
]
33+
}
34+
}
35+
]
36+
}
+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"type": "FeatureCollection",
3+
"features": [
4+
{
5+
"type": "Feature",
6+
"properties": {},
7+
"geometry": {
8+
"type": "Polygon",
9+
"coordinates": [
10+
[
11+
[
12+
4.1,
13+
48.1
14+
],
15+
[
16+
4.3,
17+
48.1
18+
],
19+
[
20+
4.3,
21+
48.3
22+
],
23+
[
24+
4.1,
25+
48.3
26+
],
27+
[
28+
4.1,
29+
48.1
30+
]
31+
]
32+
]
33+
}
34+
}
35+
]
36+
}
+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"type": "FeatureCollection",
3+
"features": [
4+
{
5+
"type": "Feature",
6+
"properties": {},
7+
"geometry": {
8+
"type": "Polygon",
9+
"coordinates": [
10+
[
11+
[
12+
4.193944931030273,
13+
48.11528236584
14+
],
15+
[
16+
4.194,
17+
48.11528236584
18+
],
19+
[
20+
4.194,
21+
48.116
22+
],
23+
[
24+
4.193944931030273,
25+
48.116
26+
],
27+
[
28+
4.193944931030273,
29+
48.11528236584
30+
]
31+
]
32+
]
33+
}
34+
}
35+
]
36+
}
+121
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
import * as THREE from 'three';
2+
import assert from 'assert';
3+
import GlobeView from 'Core/Prefab/GlobeView';
4+
import FeatureGeometryLayer from 'Layer/FeatureGeometryLayer';
5+
import FileSource from 'Source/FileSource';
6+
import HttpsProxyAgent from 'https-proxy-agent';
7+
import Extent from 'Core/Geographic/Extent';
8+
import Coordinates from 'Core/Geographic/Coordinates';
9+
import OBB from 'Renderer/OBB';
10+
import TileMesh from 'Core/TileMesh';
11+
import Renderer from './bootstrap';
12+
13+
const geojson_big = require('../data/geojson/map_big.geojson.json');
14+
const geojson_a = require('../data/geojson/map.geojson.json');
15+
const geojson_small = require('../data/geojson/map_small.geojson.json');
16+
17+
const files = [geojson_small, geojson_a, geojson_big];
18+
const errors = [3e-4, 5e-2, 35];
19+
const sizes = [70, 600, 20000];
20+
21+
files.forEach((geojson, i) => {
22+
describe(`Feature2Mesh, difference between proj4 and without proj4, for ${sizes[i]} meters extent dimension `, function () {
23+
const renderer = new Renderer();
24+
const max_error = errors[i];
25+
26+
const placement = { coord: new Coordinates('EPSG:4326', 4.2, 48.2), range: 2000 };
27+
const viewer = new GlobeView(renderer.domElement, placement, { renderer });
28+
29+
const source = new FileSource({
30+
fetchedData: geojson,
31+
crs: 'EPSG:4326',
32+
format: 'application/json',
33+
networkOptions: process.env.HTTPS_PROXY ? { agent: new HttpsProxyAgent(process.env.HTTPS_PROXY) } : {},
34+
});
35+
36+
const source2 = new FileSource(source);
37+
38+
const layerProj4 = new FeatureGeometryLayer('proj4', {
39+
source,
40+
accurate: true,
41+
zoom: { min: 9 },
42+
});
43+
44+
const layerNoProj4 = new FeatureGeometryLayer('layerNoProj4', {
45+
source: source2,
46+
accurate: false,
47+
zoom: { min: 9 },
48+
});
49+
50+
const context = {
51+
camera: viewer.camera,
52+
engine: viewer.mainLoop.gfxEngine,
53+
scheduler: viewer.mainLoop.scheduler,
54+
geometryLayer: layerProj4,
55+
view: viewer,
56+
};
57+
58+
const extent = new Extent('EPSG:4326', 4.1, 4.3, 48.1, 48.3);
59+
const geom = new THREE.BufferGeometry();
60+
geom.OBB = new OBB(new THREE.Vector3(), new THREE.Vector3(1, 1, 1));
61+
const tile = new TileMesh(geom, new THREE.Material(), viewer.tileLayer, extent, 9);
62+
tile.parent = {};
63+
64+
viewer.addLayer(layerProj4);
65+
viewer.addLayer(layerNoProj4);
66+
67+
it('update proj4', function (done) {
68+
layerProj4.whenReady.then(() => {
69+
tile.visible = true;
70+
layerProj4.update(context, layerProj4, tile)
71+
.then(() => {
72+
assert.equal(layerProj4.object3d.children.length, 1);
73+
done();
74+
});
75+
});
76+
});
77+
78+
it('update without proj4', function (done) {
79+
layerNoProj4.whenReady.then(() => {
80+
tile.visible = true;
81+
context.layer = layerNoProj4;
82+
layerNoProj4.update(context, layerNoProj4, tile)
83+
.then(() => {
84+
assert.equal(layerNoProj4.object3d.children.length, 1);
85+
done();
86+
});
87+
});
88+
});
89+
90+
it(`parsing error without proj4 should be inferior to ${max_error} meter`, function (done) {
91+
Promise.all([layerNoProj4.whenReady, layerProj4.whenReady]).then(() => {
92+
const meshNoProj4 = layerNoProj4.object3d.children[0].meshesCollection.children[0];
93+
const mesh = layerProj4.object3d.children[0].meshesCollection.children[0];
94+
const array = mesh.geometry.attributes.position.array;
95+
const arrayNoProj4 = meshNoProj4.geometry.attributes.position.array;
96+
const vectorNoProj4 = new THREE.Vector3();
97+
const vectorProj4 = new THREE.Vector3();
98+
let error = 0;
99+
100+
for (var i = array.length - 3; i >= 0; i -= 3) {
101+
// transform proj4 vertex to final projection
102+
vectorProj4.fromArray(array, i);
103+
vectorProj4.applyMatrix4(mesh.matrixWorld);
104+
105+
// transform proj4 vertex to final projection
106+
vectorNoProj4.fromArray(arrayNoProj4, i);
107+
vectorNoProj4.applyMatrix4(meshNoProj4.matrixWorld);
108+
109+
// compute diff between proj4 vertex and no proj4 vertex
110+
const distance = vectorProj4.distanceTo(vectorNoProj4);
111+
error += distance;
112+
}
113+
114+
error /= (array.length / 3);
115+
116+
assert.ok(error < max_error);
117+
done();
118+
});
119+
});
120+
});
121+
});

0 commit comments

Comments
 (0)