-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathcombine_ways.js
More file actions
92 lines (82 loc) · 4.56 KB
/
combine_ways.js
File metadata and controls
92 lines (82 loc) · 4.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/**
* @jest-environment jsdom
*/
import {toBeDeepCloseTo} from 'jest-matcher-deep-close-to';
expect.extend({toBeDeepCloseTo});
import { TextEncoder } from 'node:util';
global.TextEncoder = TextEncoder;
import { Shape } from 'three';
import { BuildingShapeUtils } from '../src/extras/BuildingShapeUtils.js';
// import { JSDOM } from 'jsdom';
test('Test no combining necessary. one open way', () => {
var way1 = '<way id="1"><nd ref="1"/><nd ref="2"/><nd ref="3"/><nd ref="4"/></way>';
let parser = new window.DOMParser();
let xml1 = parser.parseFromString(way1, 'text/xml').getElementsByTagName('way')[0];
let result = BuildingShapeUtils.combineWays([xml1]);
expect(result.length).toBe(0);
});
test('Test combining 2 ways 1->2', () => {
var way1 = '<way id="1"><nd ref="1"/><nd ref="2"/><nd ref="3"/></way>';
var way2 = '<way id="2"><nd ref="3"/><nd ref="4"/><nd ref="1"/></way>';
var way3 = '<way id="1"><nd ref="1"/><nd ref="2"/><nd ref="3"/><nd ref="4"/><nd ref="1"/></way>';
let parser = new window.DOMParser();
let xml1 = parser.parseFromString(way1, 'text/xml').getElementsByTagName('way')[0];
let xml2 = parser.parseFromString(way2, 'text/xml').getElementsByTagName('way')[0];
let result = BuildingShapeUtils.combineWays([xml1, xml2]);
expect(result.length).toBe(1);
let expected = parser.parseFromString(way3, 'text/xml');
expect(result[0].outerHTML).toBe(way3);
});
test('Test combining 2 ways 2->1', () => {
var way2 = '<way id="1"><nd ref="1"/><nd ref="2"/><nd ref="3"/></way>';
var way1 = '<way id="2"><nd ref="3"/><nd ref="4"/><nd ref="1"/></way>';
var way3 = '<way id="2"><nd ref="3"/><nd ref="4"/><nd ref="1"/><nd ref="2"/><nd ref="3"/></way>';
let parser = new window.DOMParser();
let xml1 = parser.parseFromString(way1, 'text/xml').getElementsByTagName('way')[0];
let xml2 = parser.parseFromString(way2, 'text/xml').getElementsByTagName('way')[0];
let result = BuildingShapeUtils.combineWays([xml1, xml2]);
expect(result.length).toBe(1);
let expected = parser.parseFromString(way3, 'text/xml');
expect(result[0].outerHTML).toBe(way3);
});
test('Test combining 2 unaligned ways', () => {
var way1 = '<way id="1"><nd ref="1"/><nd ref="2"/><nd ref="3"/></way>';
var way2 = '<way id="2"><nd ref="1"/><nd ref="4"/><nd ref="3"/></way>';
var way3 = '<way id="1"><nd ref="1"/><nd ref="2"/><nd ref="3"/><nd ref="4"/><nd ref="1"/></way>';
let parser = new window.DOMParser();
let xml1 = parser.parseFromString(way1, 'text/xml').getElementsByTagName('way')[0];
let xml2 = parser.parseFromString(way2, 'text/xml').getElementsByTagName('way')[0];
let result = BuildingShapeUtils.combineWays([xml1, xml2]);
expect(result.length).toBe(1);
let expected = parser.parseFromString(way3, 'text/xml');
expect(result[0].outerHTML).toBe(way3);
});
test('Test combining 3 ways 1->2->3', () => {
var way1 = '<way id="1"><nd ref="1"/><nd ref="2"/><nd ref="3"/></way>';
var way2 = '<way id="2"><nd ref="3"/><nd ref="4"/><nd ref="5"/></way>';
var way3 = '<way id="3"><nd ref="5"/><nd ref="6"/><nd ref="1"/></way>';
var way4 = '<way id="1"><nd ref="1"/><nd ref="2"/><nd ref="3"/><nd ref="4"/><nd ref="5"/><nd ref="6"/><nd ref="1"/></way>';
let parser = new window.DOMParser();
let xml1 = parser.parseFromString(way1, 'text/xml').getElementsByTagName('way')[0];
let xml2 = parser.parseFromString(way2, 'text/xml').getElementsByTagName('way')[0];
let xml3 = parser.parseFromString(way3, 'text/xml').getElementsByTagName('way')[0];
let result = BuildingShapeUtils.combineWays([xml1, xml2, xml3]);
expect(result.length).toBe(1);
let expected = parser.parseFromString(way4, 'text/xml');
expect(result[0].outerHTML).toBe(way3);
});
test('Test combining 4 ways', () => {
var way1 = '<way id="1"><nd ref="1"/><nd ref="2"/><nd ref="3"/></way>';
var way2 = '<way id="2"><nd ref="3"/><nd ref="4"/><nd ref="5"/></way>';
var way3 = '<way id="3"><nd ref="6"/><nd ref="5"/></way>';
var way4 = '<way id="4"><nd ref="6"/><nd ref="1"/><nd ref="1"/></way>';
var way5 = '<way id="1"><nd ref="1"/><nd ref="2"/><nd ref="3"/><nd ref="4"/><nd ref="5"/><nd ref="6"/><nd ref="1"/></way>';
let parser = new window.DOMParser();
let xml1 = parser.parseFromString(way1, 'text/xml').getElementsByTagName('way')[0];
let xml2 = parser.parseFromString(way2, 'text/xml').getElementsByTagName('way')[0];
let xml3 = parser.parseFromString(way3, 'text/xml').getElementsByTagName('way')[0];
let result = BuildingShapeUtils.combineWays([xml1, xml2, xml3]);
expect(result.length).toBe(1);
let expected = parser.parseFromString(way4, 'text/xml');
expect(result[0].outerHTML).toBe(way3);
});