From d93bebcdd99e969eb0010154bf805da6178e828e Mon Sep 17 00:00:00 2001 From: Bouillaguet Quentin Date: Fri, 15 Sep 2023 15:59:44 +0200 Subject: [PATCH] test(LAZPArser): add unit test --- test/unit/lazparser.js | 52 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 test/unit/lazparser.js diff --git a/test/unit/lazparser.js b/test/unit/lazparser.js new file mode 100644 index 0000000000..7326454f87 --- /dev/null +++ b/test/unit/lazparser.js @@ -0,0 +1,52 @@ +import assert from 'assert'; +import { HttpsProxyAgent } from 'https-proxy-agent'; +import LAZParser from 'Parser/LAZParser'; +import Fetcher from 'Provider/Fetcher'; + +describe('LAZParser', function () { + let lazChunk; + let parser; + + before(async function () { + const networkOptions = process.env.HTTPS_PROXY ? { + agent: new HttpsProxyAgent(process.env.HTTPS_PROXY), + headers: { range: 'bytes=79462688-80225945' }, + } : { + headers: { range: 'bytes=79462688-80225945' }, + }; + const url = 'https://s3.amazonaws.com/hobu-lidar/autzen-classified.copc.laz'; + lazChunk = await Fetcher.arrayBuffer(url, networkOptions); + parser = LAZParser.parseChunk({ + baseUrl: './node_modules/laz-perf/lib', + }); + }); + + it('parses a laz file to a THREE.BufferGeometry', async function () { + const min = [635577.79, 848882.15, 406.14]; + const max = [639003.73, 853537.66, 615.26]; + + const header = { + pointDataRecordFormat: 7, + pointDataRecordLength: 36, + scale: [0.01, 0.01, 0.01], + offset: [637290.75, 851209.9, 510.7], + }; + const bufferGeometry = await parser(lazChunk, { + in: { + pointCount: 61201, + header, + eb: [], + }, + out: {}, + }); + + const epsilon = 0.1; + + assert.ok(bufferGeometry.boundingBox.min.x + epsilon >= min[0]); + assert.ok(bufferGeometry.boundingBox.min.y + epsilon >= min[1]); + assert.ok(bufferGeometry.boundingBox.min.z + epsilon >= min[2]); + assert.ok(bufferGeometry.boundingBox.max.x - epsilon <= max[0]); + assert.ok(bufferGeometry.boundingBox.max.y - epsilon <= max[1]); + assert.ok(bufferGeometry.boundingBox.max.z - epsilon <= max[2]); + }); +});