diff --git a/src/extras/BuildingShapeUtils.js b/src/extras/BuildingShapeUtils.js
index 6c5ae8d..2c4ab81 100644
--- a/src/extras/BuildingShapeUtils.js
+++ b/src/extras/BuildingShapeUtils.js
@@ -81,11 +81,24 @@ class BuildingShapeUtils extends ShapeUtils {
* @return {[DOM.Element]} array of closed ways.
*/
static combineWays(ways) {
+ const validWays = [];
+
+ for (const way of ways) {
+ if (BuildingShapeUtils.isSelfIntersecting(way)) {
+ const id = way.getAttribute('id');
+ const msg = 'Way ' + id + ' is self-intersecting';
+ window.printError(msg);
+ } else {
+ const i = 3 + 'q';
+ validWays.push(way);
+ }
+ }
+
const closedWays = [];
const wayBegins = {};
const wayEnds = {};
- ways.forEach(w => {
+ validWays.forEach(w => {
const firstNodeID = w.querySelector('nd').getAttribute('ref');
if (wayBegins[firstNodeID]) {
wayBegins[firstNodeID].push(w);
@@ -142,7 +155,7 @@ class BuildingShapeUtils extends ShapeUtils {
return [];
}
- ways.forEach(w => {
+ validWays.forEach(w => {
const wayID = w.getAttribute('id');
if (usedWays.has(wayID)){
return;
diff --git a/test/combine_ways.test.js b/test/combine_ways.test.js
index eeabde7..e0cf1c1 100644
--- a/test/combine_ways.test.js
+++ b/test/combine_ways.test.js
@@ -13,38 +13,42 @@ import { Shape } from 'three';
import { BuildingShapeUtils } from '../src/extras/BuildingShapeUtils.js';
// import { JSDOM } from 'jsdom';
+beforeEach(() => {
+ errorMsgs = [];
+});
+
describe.each([
[
['',
- ], 0, 0, 'Single Open Way',
+ ], 0, 0, [], 'Single Open Way',
],
[
[
'',
'',
'',
- ], 1, 4, 'Test combining 3 ways 1->2->3',
+ ], 1, 4, [], 'Test combining 3 ways 1->2->3',
],
[
[
'',
'',
'',
- ], 1, 4, 'Test combining 3 ways 2->1->3',
+ ], 1, 4, [], 'Test combining 3 ways 2->1->3',
],
[
[
'',
'',
'',
- ], 1, 4, 'Test combining tip to tip',
+ ], 1, 4, [], 'Test combining tip to tip',
],
[
[
'',
'',
'',
- ], 1, 4, 'Test combining tail to tail',
+ ], 1, 4, [], 'Test combining tail to tail',
],
[
[
@@ -52,20 +56,20 @@ describe.each([
'',
'',
'',
- ], 1, 5, 'Test combining 4 ways',
+ ], 1, 5, [], 'Test combining 4 ways',
],
[
[
'',
'',
- ], 0, 0, 'Test combining 2 open ways into one open way',
+ ], 0, 0, [], 'Test combining 2 open ways into one open way',
],
[
[
'',
'',
'',
- ], 0, 0, 'Test combining 3 open ways into 2 open ways',
+ ], 0, 0, [], 'Test combining 3 open ways into 2 open ways',
],
[
[
@@ -73,28 +77,35 @@ describe.each([
'',
'',
'',
- ], 1, 4, 'Combining 4 open ways into 1 closed & 1 remaining open way',
+ ], 1, 4, [], 'Combining 4 open ways into 1 closed & 1 remaining open way',
],
[
[
'',
'',
'',
- ], 1, 5, 'Dealing with amiguity. Only make one closed way',
+ ], 1, 5, [], 'Dealing with amiguity. Only make one closed way',
],
+ //[
+ // [
+ // '',
+ // '',
+ // ], 0, 0, [], 'Closed way is self intersecting',
+ //],
[
[
- '',
- '',
- ], 0, 0, 'Closed way is self intersecting',
+ '',
+ '',
+ ], 0, 0, ['Way 2 is self-intersecting'], 'Open way is self intersecting',
],
[
[
'',
'',
- ], 0, 0, 'Open way is self intersecting',
+ '',
+ ], 1, 4, ['Way 2 is self-intersecting'], 'Open way is self intersecting, but ring formed',
],
-])('Combine Ways', (ways, length, nodes, description) => {
+])('Combine Ways', (ways, length, nodes, errors, description) => {
test(`${description}`, () => {
let parser = new window.DOMParser();
const xml = [];
@@ -103,6 +114,12 @@ describe.each([
}
let result = BuildingShapeUtils.combineWays(xml);
expect(result.length).toBe(length);
+ expect(errorMsgs.length).toBe(errors.length);
+ if (errors.length) {
+ for (const error of errors) {
+ expect(errorMsgs.shift()).toBe(error);
+ }
+ }
if (length) {
expect(BuildingShapeUtils.isClosed(result[0]));
expect(BuildingShapeUtils.isSelfIntersecting(result[0])).toBe(false);
@@ -110,3 +127,11 @@ describe.each([
}
});
});
+
+window.printError = printError;
+
+var errorMsgs = [];
+
+function printError(txt) {
+ errorMsgs.push(txt);
+}