mapcomplete/test/Logic/ExtraFunctions.spec.ts

121 lines
4.7 KiB
TypeScript
Raw Permalink Normal View History

2023-07-15 18:55:03 +02:00
import { ExtraFuncParams, ExtraFunctions } from "../../src/Logic/ExtraFunctions"
import { OsmFeature } from "../../src/Models/OsmFeature"
import { describe, expect, it } from "vitest"
import { Feature } from "geojson"
describe("OverlapFunc", () => {
it("should give doors on the edge", () => {
const door: OsmFeature = {
2022-09-08 21:40:48 +02:00
type: "Feature",
id: "node/9909268725",
properties: {
automatic_door: "no",
door: "hinged",
indoor: "door",
"kerb:height": "0 cm",
2022-09-08 21:40:48 +02:00
width: "1",
id: "node/9909268725",
},
2022-09-08 21:40:48 +02:00
geometry: {
type: "Point",
coordinates: [4.3494436, 50.8657928],
},
}
2023-05-16 03:27:49 +02:00
const hermanTeirlinck: Feature = {
2022-09-08 21:40:48 +02:00
type: "Feature",
id: "way/444059131",
properties: {
timestamp: "2022-07-27T15:15:01Z",
version: 27,
changeset: 124146283,
user: "Pieter Vander Vennet",
uid: 3818858,
"addr:city": "Bruxelles - Brussel",
"addr:housenumber": "88",
"addr:postcode": "1000",
"addr:street": "Avenue du Port - Havenlaan",
2022-09-08 21:40:48 +02:00
building: "government",
"building:levels": "5",
2022-09-08 21:40:48 +02:00
name: "Herman Teirlinckgebouw",
operator: "Vlaamse overheid",
wikidata: "Q47457146",
wikipedia: "nl:Herman Teirlinckgebouw",
id: "way/444059131",
_backend: "https://www.openstreetmap.org",
_lat: "50.86622355",
_lon: "4.3501212",
_layer: "walls_and_buildings",
_length: "380.5933566256343",
"_length:km": "0.4",
"_now:date": "2022-07-29",
"_now:datetime": "2022-07-29 14:19:25",
"_loaded:date": "2022-07-29",
"_loaded:datetime": "2022-07-29 14:19:25",
"_last_edit:contributor": "Pieter Vander Vennet",
"_last_edit:contributor:uid": 3818858,
"_last_edit:changeset": 124146283,
"_last_edit:timestamp": "2022-07-27T15:15:01Z",
2022-09-08 21:40:48 +02:00
_version_number: 27,
"_geometry:type": "Polygon",
2022-09-08 21:40:48 +02:00
_surface: "7461.252251355437",
"_surface:ha": "0.7",
2022-09-08 21:40:48 +02:00
_country: "be",
},
2022-09-08 21:40:48 +02:00
geometry: {
type: "Polygon",
coordinates: [
[
2022-09-08 21:40:48 +02:00
[4.3493369, 50.8658274],
[4.3493393, 50.8658266],
[4.3494436, 50.8657928],
[4.3495272, 50.8657658],
[4.349623, 50.8657348],
[4.3497442, 50.8656956],
[4.3498441, 50.8656632],
[4.3500768, 50.8655878],
[4.3501619, 50.8656934],
[4.3502113, 50.8657551],
[4.3502729, 50.8658321],
[4.3503063, 50.8658737],
[4.3503397, 50.8659153],
[4.3504159, 50.8660101],
[4.3504177, 50.8660123],
[4.3504354, 50.8660345],
[4.3505348, 50.8661584],
[4.3504935, 50.866172],
[4.3506286, 50.8663405],
[4.3506701, 50.8663271],
[4.3508563, 50.8665592],
[4.3509055, 50.8666206],
[4.3506278, 50.8667104],
[4.3504502, 50.8667675],
[4.3503132, 50.8668115],
[4.3502162, 50.8668427],
[4.3501645, 50.8668593],
[4.3499296, 50.8665664],
[4.3498821, 50.8665073],
[4.3498383, 50.8664527],
[4.3498126, 50.8664207],
[4.3497459, 50.8663376],
[4.3497227, 50.8663086],
[4.3496517, 50.8662201],
[4.3495158, 50.8660507],
[4.3493369, 50.8658274],
],
],
},
}
const params: ExtraFuncParams = {
2023-04-07 03:54:11 +02:00
getFeatureById: () => undefined,
2023-05-17 13:16:43 +02:00
getFeaturesWithin: () => [[door]],
}
2023-05-16 03:27:49 +02:00
const helpers = ExtraFunctions.constructHelpers(params)
2023-05-16 03:27:49 +02:00
const overlap = helpers.overlapWith(hermanTeirlinck)("*")
console.log(JSON.stringify(overlap))
2023-02-03 04:48:32 +01:00
expect(overlap[0].feat == door).toBe(true)
})
2022-09-08 21:40:48 +02:00
})