@bluedot-innovation/models 3.0.3 → 3.0.4-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1 -0
- package/__tests__/geofeature/polygon/polygon.spec.js +42 -18
- package/helpers.js +9 -5
- package/models/Polygon.js +3 -4
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -86,25 +86,49 @@ describe('Polygon', () => {
|
|
|
86
86
|
})
|
|
87
87
|
})
|
|
88
88
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
89
|
+
describe('For any given vertex, if any of the next 2 vertices are the same, it should error', (done) => {
|
|
90
|
+
it('next vertice is the same', () => {
|
|
91
|
+
polygon.vertices = [{
|
|
92
|
+
"latitude": -37.81902680201739,
|
|
93
|
+
"longitude": 144.9821037054062
|
|
94
|
+
}, {
|
|
95
|
+
"latitude": -37.81902680201739,
|
|
96
|
+
"longitude": 144.9821037054062
|
|
97
|
+
}, {
|
|
98
|
+
"latitude": -36.81902680201739,
|
|
99
|
+
"longitude": 143.9821037054062
|
|
100
|
+
}, {
|
|
101
|
+
"latitude": -37.23968786929315,
|
|
102
|
+
"longitude": 144.1216155433654
|
|
103
|
+
}]
|
|
103
104
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
105
|
+
let Polygon = new PolygonModel(polygon)
|
|
106
|
+
Polygon.validate((err, res) => {
|
|
107
|
+
assert.match(err, /For any given vertex, the next 2 vertices cannot match that vertex./i)
|
|
108
|
+
done()
|
|
109
|
+
})
|
|
110
|
+
})
|
|
111
|
+
|
|
112
|
+
it('the one after next is the same', () => {
|
|
113
|
+
polygon.vertices = [{
|
|
114
|
+
"latitude": -37.81902680201739,
|
|
115
|
+
"longitude": 144.9821037054062
|
|
116
|
+
}, {
|
|
117
|
+
"latitude": -36.81902680201739,
|
|
118
|
+
"longitude": 143.9821037054062
|
|
119
|
+
}, {
|
|
120
|
+
"latitude": -37.81902680201739,
|
|
121
|
+
"longitude": 144.9821037054062
|
|
122
|
+
}, {
|
|
123
|
+
"latitude": -37.2396878692931,
|
|
124
|
+
"longitude": 144.1216155433654
|
|
125
|
+
}]
|
|
126
|
+
|
|
127
|
+
let Polygon = new PolygonModel(polygon)
|
|
128
|
+
Polygon.validate((err, res) => {
|
|
129
|
+
assert.match(err, /For any given vertex, the next 2 vertices cannot match that vertex./i)
|
|
130
|
+
done()
|
|
131
|
+
})
|
|
108
132
|
})
|
|
109
133
|
})
|
|
110
134
|
})
|
package/helpers.js
CHANGED
|
@@ -21,20 +21,24 @@ helpers.threeOrMoreVertices = function(vertices) {
|
|
|
21
21
|
return vertices.length >= 3;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
helpers.
|
|
24
|
+
helpers.notSameThreeInARow = function(list) {
|
|
25
25
|
const cleanList = clean(list)
|
|
26
|
-
let
|
|
26
|
+
let hasSame = false;
|
|
27
27
|
|
|
28
28
|
for (var i = 0; i < cleanList.length; i++) {
|
|
29
29
|
const itemA = cleanList[i]
|
|
30
30
|
const itemB = cleanList[i - 1]
|
|
31
|
+
const itemC = cleanList[i - 2]
|
|
31
32
|
const isSame = equal(itemA, itemB);
|
|
32
|
-
if (
|
|
33
|
-
|
|
33
|
+
if (equal(itemA, itemB)) {
|
|
34
|
+
hasSame = true;
|
|
35
|
+
}
|
|
36
|
+
if (equal(itemA, itemC)) {
|
|
37
|
+
hasSame = true;
|
|
34
38
|
}
|
|
35
39
|
}
|
|
36
40
|
|
|
37
|
-
return !
|
|
41
|
+
return !hasSame;
|
|
38
42
|
}
|
|
39
43
|
|
|
40
44
|
helpers.validateCustomData = function (data) {
|
package/models/Polygon.js
CHANGED
|
@@ -14,10 +14,9 @@ const schema = {
|
|
|
14
14
|
validate: [{
|
|
15
15
|
validator: helpers.threeOrMoreVertices,
|
|
16
16
|
msg: 'A polygon must have 3 or more vertices.'
|
|
17
|
-
},
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
msg: 'A polygon cannot have 2 vertices in a row the same.'
|
|
17
|
+
}, {
|
|
18
|
+
validator: helpers.notSameThreeInARow,
|
|
19
|
+
msg: 'For any given vertex, the next 2 vertices cannot match that vertex.'
|
|
21
20
|
}]
|
|
22
21
|
}
|
|
23
22
|
}
|
package/package.json
CHANGED