[Ethereum] How to i create an array that contains multiple tuples in solidity

contract-designgo-ethereumsolidity

I am trying to create a smart contract that will store an array containing GPS coordinates such as:

X=[(31.332,54.213),(32.013,54.312), (33.124,56.2134),(34.123, 57.789), (34.789,59.654),(31.332,54.213)] 

The goal of this is to create a polygon and compare incoming gps coordinates whether inside or outside this polygon(point in polygon problem). I haven't been able to find any decent solution on how to create this array of a list of lat and long coordinates. Everyone suggests using strucs but they seem to be creating a new data type. I was thinking of nesting the strucs for each vertex into one array, but I can't find a way of doing it. Thanks in advance.

Best Answer

I created this just for you:

contract omega {
mapping (uint => uint[3]) public GPS;

function omega(uint[] coords) public{
    uint x = uint(coords.length)/uint(3);
    uint cont = 0;
    for(uint r = 0; r<x;r++){
        setXYZ(r,coords[cont],coords[cont+1],coords[cont+2]);
        cont+=2;
    }
}

function setXYZ(uint index, uint _x,uint _y,uint _z) public{
    setX(index,_x);
    setY(index,_y);
    setZ(index,_z);
}

function setX(uint index,uint _value){
    GPS[index][0] = _value;
}
function setY(uint index,uint _value){
    GPS[index][1] = _value;
}
function setZ(uint index,uint _value){
    GPS[index][2] = _value;
}
}

I hope it helps you :). Have a good day