There is an unsaved comment in progress. You will lose your changes if you continue. Are you sure you want to reopen the work item?
New Zealand Map Grid reprojection errors due to inline modification of array in Zpoly1()
I was having a problem re-projecting polygons into New Zealand Map Grid. The end-points of polygons should be identical. However, when I passed the polygon coordinates into the Projections library, the end coordinates would always be different.
I discovered that the reprojection was going wrong in the OnForward method of the NewZealandMapGrid class.
There is a global array called _bf which is declared as readonly. However, when the array of coordinates was getting passed into the Proj.Zpoly1 static method, the array was getting modified, causing subsequent transformations to be incorrect.
It looks to me like the problem is that the _bf nested array is declared using object literal syntax, whcih makes it an array of reference types. This is bypassing the readonly declaration of the array, and consequently assignments to copies of the values
which take place inside the Proj.Zpoly1 are actually altering the array inside this method.
I made a shallow local copy of the _bf values, and this fixed the problem.