@@ -14,76 +14,43 @@ import { BuildingShapeUtils } from '../src/extras/BuildingShapeUtils.js';
1414// import { JSDOM } from 'jsdom';
1515
1616test ( 'Test no combining necessary. one open way' , ( ) => {
17- var way1 = '<way id="1"><nd ref="1"/><nd ref="2"/><nd ref="3"/><nd ref="4"/></way>' ;
17+ var way = '<way id="1"><nd ref="1"/><nd ref="2"/><nd ref="3"/><nd ref="4"/></way>' ;
1818 let parser = new window . DOMParser ( ) ;
19- let xml1 = parser . parseFromString ( way1 , 'text/xml' ) . getElementsByTagName ( 'way' ) [ 0 ] ;
20- let result = BuildingShapeUtils . combineWays ( [ xml1 ] ) ;
19+ let xml = parser . parseFromString ( way , 'text/xml' ) . getElementsByTagName ( 'way' ) [ 0 ] ;
20+ let result = BuildingShapeUtils . combineWays ( [ xml ] ) ;
2121 expect ( result . length ) . toBe ( 0 ) ;
2222} ) ;
2323
24- test ( 'Test combining 2 ways 1->2' , ( ) => {
25- var way1 = '<way id="1"><nd ref="1"/><nd ref="2"/></way>' ;
26- var way2 = '<way id="2"><nd ref="2"/><nd ref="3"/></way>' ;
27- var way3 = '<way id="3"><nd ref="3"/><nd ref="1"/></way>' ;
28- let parser = new window . DOMParser ( ) ;
29- let xml1 = parser . parseFromString ( way1 , 'text/xml' ) . getElementsByTagName ( 'way' ) [ 0 ] ;
30- let xml2 = parser . parseFromString ( way2 , 'text/xml' ) . getElementsByTagName ( 'way' ) [ 0 ] ;
31- let xml3 = parser . parseFromString ( way3 , 'text/xml' ) . getElementsByTagName ( 'way' ) [ 0 ] ;
32- let result = BuildingShapeUtils . combineWays ( [ xml1 , xml2 , xml3 ] ) ;
33- // Expect one closed way with 3 unique nodes.
34- expect ( result . length ) . toBe ( 1 ) ;
35- expect ( BuildingShapeUtils . isClosed ( result [ 0 ] ) ) . toBe ( true ) ;
36- expect ( result [ 0 ] . getElementsByTagName ( 'nd' ) . length ) . toBe ( 4 ) ;
37- expect ( BuildingShapeUtils . isSelfIntersecting ( result [ 0 ] ) ) . toBe ( false ) ;
38- } ) ;
39-
40- test ( 'Test combining 3 ways 2->1->3' , ( ) => {
41- var way1 = '<way id="1"><nd ref="1"/><nd ref="2"/></way>' ;
42- var way2 = '<way id="2"><nd ref="3"/><nd ref="1"/></way>' ;
43- var way3 = '<way id="3"><nd ref="2"/><nd ref="3"/></way>' ;
44- let parser = new window . DOMParser ( ) ;
45- let xml1 = parser . parseFromString ( way1 , 'text/xml' ) . getElementsByTagName ( 'way' ) [ 0 ] ;
46- let xml2 = parser . parseFromString ( way2 , 'text/xml' ) . getElementsByTagName ( 'way' ) [ 0 ] ;
47- let xml3 = parser . parseFromString ( way3 , 'text/xml' ) . getElementsByTagName ( 'way' ) [ 0 ] ;
48- let result = BuildingShapeUtils . combineWays ( [ xml1 , xml2 , xml3 ] ) ;
49- expect ( result . length ) . toBe ( 1 ) ;
50- expect ( BuildingShapeUtils . isClosed ( result [ 0 ] ) ) . toBe ( true ) ;
51- expect ( BuildingShapeUtils . isSelfIntersecting ( result [ 0 ] ) ) . toBe ( false ) ;
52- expect ( result [ 0 ] . getElementsByTagName ( 'nd' ) . length ) . toBe ( 4 ) ;
53- } ) ;
54-
55- test ( 'Test combining 2 unaligned ways' , ( ) => {
56- var way1 = '<way id="1"><nd ref="1"/><nd ref="2"/></way>' ;
57- var way2 = '<way id="2"><nd ref="3"/><nd ref="2"/></way>' ;
58- var way3 = '<way id="3"><nd ref="3"/><nd ref="1"/></way>' ;
59- let parser = new window . DOMParser ( ) ;
60- let xml1 = parser . parseFromString ( way1 , 'text/xml' ) . getElementsByTagName ( 'way' ) [ 0 ] ;
61- let xml2 = parser . parseFromString ( way2 , 'text/xml' ) . getElementsByTagName ( 'way' ) [ 0 ] ;
62- let xml3 = parser . parseFromString ( way3 , 'text/xml' ) . getElementsByTagName ( 'way' ) [ 0 ] ;
63- let result = BuildingShapeUtils . combineWays ( [ xml1 , xml2 , xml3 ] ) ;
64- expect ( result . length ) . toBe ( 1 ) ;
65- expect ( BuildingShapeUtils . isClosed ( result [ 0 ] ) ) . toBe ( true ) ;
66- expect ( BuildingShapeUtils . isSelfIntersecting ( result [ 0 ] ) ) . toBe ( false ) ;
67- expect ( result [ 0 ] . getElementsByTagName ( 'nd' ) . length ) . toBe ( 4 ) ;
68- } ) ;
69-
70- test ( 'Test combining 3 ways 1->2->3' , ( ) => {
71- var way1 = '<way id="1"><nd ref="1"/><nd ref="2"/></way>' ;
72- var way2 = '<way id="2"><nd ref="1"/><nd ref="3"/></way>' ;
73- var way3 = '<way id="3"><nd ref="2"/><nd ref="3"/></way>' ;
74- let parser = new window . DOMParser ( ) ;
75- let xml1 = parser . parseFromString ( way1 , 'text/xml' ) . getElementsByTagName ( 'way' ) [ 0 ] ;
76- let xml2 = parser . parseFromString ( way2 , 'text/xml' ) . getElementsByTagName ( 'way' ) [ 0 ] ;
77- let xml3 = parser . parseFromString ( way3 , 'text/xml' ) . getElementsByTagName ( 'way' ) [ 0 ] ;
78- let result = BuildingShapeUtils . combineWays ( [ xml1 , xml2 , xml3 ] ) ;
79- expect ( result . length ) . toBe ( 1 ) ;
80- expect ( BuildingShapeUtils . isClosed ( result [ 0 ] ) ) . toBe ( true ) ;
81- expect ( BuildingShapeUtils . isSelfIntersecting ( result [ 0 ] ) ) . toBe ( false ) ;
82- expect ( result [ 0 ] . getElementsByTagName ( 'nd' ) . length ) . toBe ( 4 ) ;
83- } ) ;
84-
8524describe ( 'Combine Ways' , ( ) => {
8625 test . each ( [
26+ [
27+ [
28+ '<way id="1"><nd ref="1"/><nd ref="2"/></way>' ,
29+ '<way id="2"><nd ref="2"/><nd ref="3"/></way>' ,
30+ '<way id="3"><nd ref="3"/><nd ref="1"/></way>' ,
31+ ] , 1 , 4 , 'Test combining 3 ways 1->2->3' ,
32+ ] ,
33+ [
34+ [
35+ '<way id="1"><nd ref="1"/><nd ref="2"/></way>' ,
36+ '<way id="2"><nd ref="3"/><nd ref="1"/></way>' ,
37+ '<way id="3"><nd ref="2"/><nd ref="3"/></way>' ,
38+ ] , 1 , 4 , 'Test combining 3 ways 2->1->3' ,
39+ ] ,
40+ [
41+ [
42+ '<way id="1"><nd ref="1"/><nd ref="2"/></way>' ,
43+ '<way id="2"><nd ref="3"/><nd ref="2"/></way>' ,
44+ '<way id="3"><nd ref="3"/><nd ref="1"/></way>' ,
45+ ] , 1 , 4 , 'Test combining tip to tip' ,
46+ ] ,
47+ [
48+ [
49+ '<way id="1"><nd ref="1"/><nd ref="2"/></way>' ,
50+ '<way id="2"><nd ref="1"/><nd ref="3"/></way>' ,
51+ '<way id="3"><nd ref="2"/><nd ref="3"/></way>' ,
52+ ] , 1 , 4 , 'Test combining tail to tail' ,
53+ ] ,
8754 [
8855 [
8956 '<way id="1"><nd ref="1"/><nd ref="2"/></way>' ,
0 commit comments