In my Angular application, I have an array that refers to the coordinates of the polygon. For instance:
[[-1,0], [0,1], [1,0], [0,-1], [-1,0]]
The important thing here is that the first and last points are repeated and actually refer to the same array of length 2 lengths. This is the result of the plugin that I am using. However, arrays are created several times in such a way that the first and last points with the same value are not the same reference.
At some point in my Angular application, I need to create a new polygon with the same coordinates as the original, only turned upside down. My first attempt:
var newCoords = angular.copy(polygon.coordinates);
for (var i = 0; i < newCoords.length; i++) {
newCoords[i].reverse();
}
However, in cases where the first and last coordinates have the same link, I hit one of two reversible points.
I realized that I was angular.copy()creating a deep copy of what was being transmitted, and I should not experience this problem. It’s clear that this is wrong, so why? Is there a way to make a really deep copy of the coordinate array that eliminates this odd link mapping? At the moment, I managed to get around this, adding even angular.copy(newCoords[i])before reverse().
source
share