@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 CHANGED
@@ -1,5 +1,6 @@
1
1
  ## 3.0.3
2
2
  - `BoundingBox` - disallow same values for `northEast` and `southWest`
3
+ - `Polygon` - disallow vertices to have same values twice in a row
3
4
 
4
5
  ## 3.0.2
5
6
  - Remove `_id`'s on the actions and filters (for real this time)
@@ -86,25 +86,49 @@ describe('Polygon', () => {
86
86
  })
87
87
  })
88
88
 
89
- it('when 2 vertices in a row are the same, it should error', (done) => {
90
- polygon.vertices = [{
91
- "latitude": -37.81902680201739,
92
- "longitude": 144.9821037054062
93
- }, {
94
- "latitude": -37.8196878692931,
95
- "longitude": 144.9816155433654
96
- }, {
97
- "latitude": -37.8196878692931,
98
- "longitude": 144.9816155433654
99
- }, {
100
- "latitude": -37.2396878692931,
101
- "longitude": 144.1216155433654
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
- let Polygon = new PolygonModel(polygon)
105
- Polygon.validate((err, res) => {
106
- assert.match(err, /A polygon cannot have 2 vertices in a row the same/i)
107
- done()
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.notSameTwoInARow = function(list) {
24
+ helpers.notSameThreeInARow = function(list) {
25
25
  const cleanList = clean(list)
26
- let twoInARow = false;
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 (isSame) {
33
- twoInARow = true;
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 !twoInARow;
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
- validator: helpers.notSameTwoInARow,
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bluedot-innovation/models",
3
- "version": "3.0.3",
3
+ "version": "3.0.4-alpha.1",
4
4
  "main": "Models.js",
5
5
  "scripts": {
6
6
  "lint": "./node_modules/.bin/eslint -c .eslintrc.js ./models/*.js ./__tests__/**/*.js ./__tests__/**/**/*.js ./schemas/*.js",