MCPcopy Create free account
hub / github.com/Project-OSRM/osrm-backend / argumentsToTileParameters

Function argumentsToTileParameters

include/nodejs/node_osrm_support.hpp:1217–1275  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1215}
1216
1217inline tile_parameters_ptr argumentsToTileParameters(const Napi::CallbackInfo &args,
1218 bool /*unused*/)
1219{
1220 tile_parameters_ptr params = std::make_unique<osrm::TileParameters>();
1221
1222 if (args.Length() < 2)
1223 {
1224 ThrowTypeError(args.Env(), "Coordinate object and callback required");
1225 return tile_parameters_ptr();
1226 }
1227
1228 if (!args[0].IsArray())
1229 {
1230 ThrowTypeError(args.Env(), "Parameter must be an array [x, y, z]");
1231 return tile_parameters_ptr();
1232 }
1233
1234 Napi::Array array = args[0].As<Napi::Array>();
1235
1236 if (array.Length() != 3)
1237 {
1238 ThrowTypeError(args.Env(), "Parameter must be an array [x, y, z]");
1239 return tile_parameters_ptr();
1240 }
1241
1242 Napi::Value x = array.Get(static_cast<uint32_t>(0));
1243 Napi::Value y = array.Get(static_cast<uint32_t>(1));
1244 Napi::Value z = array.Get(static_cast<uint32_t>(2));
1245 if (x.IsEmpty() || y.IsEmpty() || z.IsEmpty())
1246 return tile_parameters_ptr();
1247
1248 if (!IsUnsignedInteger(x) && !x.IsUndefined())
1249 {
1250 ThrowError(args.Env(), "Tile x coordinate must be unsigned interger");
1251 return tile_parameters_ptr();
1252 }
1253 if (!IsUnsignedInteger(y) && !y.IsUndefined())
1254 {
1255 ThrowError(args.Env(), "Tile y coordinate must be unsigned interger");
1256 return tile_parameters_ptr();
1257 }
1258 if (!IsUnsignedInteger(z) && !z.IsUndefined())
1259 {
1260 ThrowError(args.Env(), "Tile z coordinate must be unsigned interger");
1261 return tile_parameters_ptr();
1262 }
1263
1264 params->x = x.ToNumber().Uint32Value();
1265 params->y = y.ToNumber().Uint32Value();
1266 params->z = z.ToNumber().Uint32Value();
1267
1268 if (!params->IsValid())
1269 {
1270 ThrowError(args.Env(), "Invalid tile coordinates");
1271 return tile_parameters_ptr();
1272 }
1273
1274 return params;

Callers

nothing calls this directly

Calls 6

ThrowTypeErrorFunction · 0.85
IsUnsignedIntegerFunction · 0.85
ThrowErrorFunction · 0.85
IsEmptyMethod · 0.80
GetMethod · 0.45
IsValidMethod · 0.45

Tested by

no test coverage detected