view client/tests/unit/geo/geo.spec.js @ 5590:826e67e959c9 surveysperbottleneckid

For BN Overview display id for all doubles
author Thomas Junk <thomas.junk@intevation.de>
date Tue, 05 Apr 2022 13:02:13 +0200
parents 0c5cbbafbd94
children
line wrap: on
line source

/* This is Free Software under GNU Affero General Public License v >= 3.0
 * without warranty, see README.md and license for details.
 *
 * SPDX-License-Identifier: AGPL-3.0-or-later
 * License-Filename: LICENSES/AGPL-3.0.txt
 *
 * Copyright (C) 2018 by via donau
 *   – Österreichische Wasserstraßen-Gesellschaft mbH
 * Software engineering by Intevation GmbH
 *
 * Author(s):
 * Thomas Junk <thomas.junk@intevation.de>
 */
import { prepareProfile } from "../../../src/application/lib/geo";

const geoJSON = JSON.parse(`{
	"type": "Feature",
	"geometry": {
		"type": "MultiLineString",
		"coordinates": [
			[
				[17.216391563415527, 48.0245195664277, 123],
				[17.216777801513672, 48.024720482272315, 124]
			],
			[
				[17.218494415283203, 48.02540933065123, 125],
				[17.219438552856445, 48.02586855778941, 126],
				[17.220726013183594, 48.02647128719908, 127],
				[17.221627235412598, 48.026987906797494, 128],
				[17.222957611083984, 48.02759062311748, 129],
				[17.223901748657227, 48.0280785311666, 130],
				[17.224159240722656, 48.02819333238926, 131]
			],
			[
				[17.225961685180664, 48.02891083423718, 132],
				[17.227892875671383, 48.02997271864036, 133]
			]
		]
	},
	"properties": {}
}`);

test("prepare diagram", () => {
  const coordinates = geoJSON.geometry.coordinates;
  const firstSegment = coordinates[0];
  const lastSegment = coordinates[coordinates.length - 1];
  const startPoint = firstSegment[0];
  const endPoint = lastSegment[lastSegment.length - 1];
  const result = prepareProfile({ geoJSON, startPoint, endPoint });
  const alts = result.points.reduce((o, n) => {
    let y = n.map(e => {
      return e.y;
    });
    o = o.concat(y);
    return o;
  }, []);
  const growing = values => {
    let first = values[0].x;
    for (let v of values) {
      if (first > v.x) return false;
    }
    return true;
  };
  const minAlt = Math.min(...alts);
  const maxAlt = Math.max(...alts);
  expect(result.minAlt).toBe(minAlt);
  expect(result.maxAlt).toBe(maxAlt);
  expect(growing(result.points[0])).toBe(true);
  expect(result.lengthPolyLine == 1051.5361933142963).toBe(true);
});