Skip to content

Commit

Permalink
Fix tests failure and the check logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Bruce committed May 8, 2018
1 parent 17b4e83 commit 2042704
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 42 deletions.
23 changes: 15 additions & 8 deletions tests/wicket-gmap3-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ describe('Standard WKT Test Cases: ', function() {
new google.maps.LatLng(10, 30),
new google.maps.LatLng(40, 40),
new google.maps.LatLng(40, 20),
new google.maps.LatLng(20, 10)
new google.maps.LatLng(20, 10),
new google.maps.LatLng(10, 30)
]
]
}),
Expand Down Expand Up @@ -175,12 +176,14 @@ describe('Standard WKT Test Cases: ', function() {
new google.maps.LatLng(10, 35),
new google.maps.LatLng(45, 45),
new google.maps.LatLng(40, 15),
new google.maps.LatLng(20, 10)
new google.maps.LatLng(20, 10),
new google.maps.LatLng(10, 35)
],
[ // Order in inner rings is reversed
new google.maps.LatLng(30, 21),
new google.maps.LatLng(35, 35),
new google.maps.LatLng(20, 30)
new google.maps.LatLng(20, 30),
new google.maps.LatLng(30, 21)
]
]
}),
Expand Down Expand Up @@ -360,7 +363,8 @@ describe('Standard WKT Test Cases: ', function() {
[
new google.maps.LatLng(20, 30),
new google.maps.LatLng(40, 45),
new google.maps.LatLng(40, 10)
new google.maps.LatLng(40, 10),
new google.maps.LatLng(20, 30)
]
]
}),
Expand All @@ -371,7 +375,8 @@ describe('Standard WKT Test Cases: ', function() {
new google.maps.LatLng(5, 15),
new google.maps.LatLng(10, 40),
new google.maps.LatLng(20, 10),
new google.maps.LatLng(10, 5)
new google.maps.LatLng(10, 5),
new google.maps.LatLng(5, 15)
]
]
})
Expand Down Expand Up @@ -461,7 +466,8 @@ describe('Standard WKT Test Cases: ', function() {
[
new google.maps.LatLng(40, 40),
new google.maps.LatLng(45, 20),
new google.maps.LatLng(30, 45)
new google.maps.LatLng(30, 45),
new google.maps.LatLng(40, 40)
]
]
}),
Expand All @@ -473,13 +479,14 @@ describe('Standard WKT Test Cases: ', function() {
new google.maps.LatLng(30, 10),
new google.maps.LatLng(10, 10),
new google.maps.LatLng(5, 30),
new google.maps.LatLng(20, 45)
new google.maps.LatLng(20, 45),
new google.maps.LatLng(35, 20)
],
[
new google.maps.LatLng(20, 30),
new google.maps.LatLng(15, 20),
new google.maps.LatLng(25, 20),

new google.maps.LatLng(20, 30)
]
]
})
Expand Down
43 changes: 9 additions & 34 deletions wicket-gmap3.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@
* @return {google.maps.Polygon}
*/
polygon: function (config, component) {
var j, k, c, rings, verts;
var j, k, c, rings, verts, outerClockwise;

var polygonIsClockwise = function (coords) {
var area = 0,
Expand Down Expand Up @@ -188,10 +188,13 @@

} // eo for each vertex

if (j !== 0) {
// Orient inner rings correctly
if (polygonIsClockwise(c[j]) && this.type == 'polygon') {
verts.reverse();
if (j === 0) {
outerClockwise = polygonIsClockwise(c[j]);
} else {
// Note that the points forming the inner path are wound in the
// opposite direction to those in the outer path, to form the hole
if (polygonIsClockwise(c[j]) === outerClockwise && this.type == 'polygon') {
verts.reverse();
}
}

Expand Down Expand Up @@ -336,19 +339,8 @@
return false;
}

if (l === 2) {
// If clockwise*clockwise or counter*counter, i.e.
// (-1)*(-1) or (1)*(1), then result would be positive
if (sign(obj.getPaths().getAt(0)) * sign(obj.getPaths().getAt(1)) < 0) {
return false; // Most likely single polygon with 1 hole
}

return true;
}

// Must be longer than 3 polygons at this point...
areas = obj.getPaths().getArray().map(function (k) {
return sign(k) / Math.abs(sign(k)); // Unit normalization (outputs 1 or -1)
return sign(k) > 0 ? 1 : -1; // Unit normalization (outputs 1 or -1)
});

// If two clockwise or two counter-clockwise rings are found
Expand All @@ -359,7 +351,6 @@
}

return false;

}());
}

Expand All @@ -380,22 +371,6 @@
x: tmp.getAt(0).lng(),
y: tmp.getAt(0).lat()
});

if (i % 2 !== 0) { // In inner rings, coordinates are reversed...
verts.reverse();
}
}

if (obj.getPaths().length > 1 && i > 0) {
// If this and the last ring have the same signs...
if (sign(obj.getPaths().getAt(i)) > 0 && sign(obj.getPaths().getAt(i - 1)) > 0 ||
sign(obj.getPaths().getAt(i)) < 0 && sign(obj.getPaths().getAt(i - 1)) < 0 /*&& !multiFlag*/ ) {
// ...They must both be inner rings (or both be outer rings, in a multipolygon)
verts = [verts]; // Wrap multipolygons once more (collection)
} else {
verts.reverse();
}

}

rings.push(verts);
Expand Down

0 comments on commit 2042704

Please sign in to comment.