In our C++ code we have the following:
arraySize = regionsvertices.size();
double* arr = new double[arraySize];
int k = 0;
for (double i : regionsvertices) {
arr[k++] = i;
}
return arr;
The related C# code looks like this:
var regionsPtr = region_growing_algorithm(
pointsArr,
simpleShape.points.Length / 3,
simpleShape.faces,
simpleShape.faces.Length / 3,
filename);
var arrayLength = get_array_size();
var regions = new double[arrayLength];
Marshal.Copy(regionsPtr, regions, 0, arrayLength);
return new JsonResult
{
Data = regions
};
And in TypeScript we do:
$.ajax({
type: "POST",
url: "/ShapeDetection/RegionGrowing",
data: {
points: points,
faces: faces
},
success: function (result) {
console.log("result from RegionGrowing", result.Data);
},
dataType: "json"
});
The problem is that we get in result.Data numerical values which are integers but not double values. Somehow the numbers do not get converted correctly.
Can you show us what we are doing wrong?
2
Answers
It seems that the original values which we get in the C++ section of the code are integers, so there is nothing wrong with the conversion. It is however strange that these values do not have a decimal part, so this requires further investigation.
By using JSON.parse, you explicitly convert the received JSON data into JavaScript objects, which should maintain the double precision. This can help ensure that the numbers are treated as doubles on the client side, regardless of how they were serialized on the server side.