| 15 | #define DegreeToRadians(d) ((d) * M_PI / 180.0) |
| 16 | |
| 17 | SIValue AR_TOPOINT(SIValue *argv, int argc, void *private_data) { |
| 18 | SIValue map = argv[0]; |
| 19 | SIType t = SI_TYPE(map); |
| 20 | |
| 21 | if(t == T_NULL) return SI_NullVal(); |
| 22 | |
| 23 | // expecting input to be a map |
| 24 | // point({latitude: 32.0705767, longitude: 34.8185946}) |
| 25 | ASSERT(t == T_MAP); |
| 26 | |
| 27 | uint key_count = Map_KeyCount(map); |
| 28 | if(key_count != 2) { |
| 29 | ErrorCtx_RaiseRuntimeException("A point map should have 2 elements, latitude and longitude"); |
| 30 | return SI_NullVal(); |
| 31 | } |
| 32 | |
| 33 | SIValue latitude; |
| 34 | SIValue longitude; |
| 35 | |
| 36 | // make sure lat is present in map |
| 37 | if(!MAP_GET(map, "latitude", latitude)) { |
| 38 | ErrorCtx_RaiseRuntimeException("Did not find 'latitude' value in point map"); |
| 39 | return SI_NullVal(); |
| 40 | } |
| 41 | // make sure lon is present in map |
| 42 | if(!MAP_GET(map, "longitude", longitude)) { |
| 43 | ErrorCtx_RaiseRuntimeException("Did not find 'longitude' value in point map"); |
| 44 | return SI_NullVal(); |
| 45 | } |
| 46 | // validate lat, lon types |
| 47 | if(!(SI_NUMERIC & SI_TYPE(latitude) && SI_NUMERIC & SI_TYPE(longitude))) { |
| 48 | ErrorCtx_RaiseRuntimeException("'latitude' and 'longitude' values in point map were not both valid numerics"); |
| 49 | return SI_NullVal(); |
| 50 | } |
| 51 | |
| 52 | // validate latitude is in range [-90,90] |
| 53 | if(SI_GET_NUMERIC(latitude) > 90 || SI_GET_NUMERIC(latitude) < -90) { |
| 54 | ErrorCtx_RaiseRuntimeException("latitude should be within the -90 to 90 range"); |
| 55 | return SI_NullVal(); |
| 56 | } |
| 57 | |
| 58 | // validate longitude is in range [-180,180] |
| 59 | if(SI_GET_NUMERIC(longitude) > 180 || SI_GET_NUMERIC(longitude) < -180) { |
| 60 | ErrorCtx_RaiseRuntimeException("longitude should be within the -180 to 180 range"); |
| 61 | return SI_NullVal(); |
| 62 | } |
| 63 | |
| 64 | return SI_Point(SI_GET_NUMERIC(latitude), SI_GET_NUMERIC(longitude)); |
| 65 | } |
| 66 | |
| 67 | SIValue AR_DISTANCE(SIValue *argv, int argc, void *private_data) { |
| 68 | // compute distance between two points |
nothing calls this directly
no test coverage detected