Skip to content

Commit 64bcc92

Browse files
committed
Require radiuses for bearings in nodejs bindings
1 parent f883555 commit 64bcc92

File tree

4 files changed

+23
-3
lines changed

4 files changed

+23
-3
lines changed

docs/nodejs/api.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ var osrm = new OSRM('network.osrm');
111111
var options = {
112112
coordinates: [[13.388860,52.517037]],
113113
number: 3,
114-
bearings: [[0,20]]
114+
bearings: [[0,20]],
115+
radiuses: [null]
115116
};
116117
osrm.nearest(options, function(err, response) {
117118
console.log(response.waypoints); // array of Waypoint objects

include/nodejs/node_osrm_support.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,11 @@ inline bool argumentsToParameter(const Napi::CallbackInfo &args,
522522
if (bearings.IsEmpty())
523523
return false;
524524

525+
if (!obj.Has("radiuses")) {
526+
ThrowError(args.Env(), "Bearings must be accompanied with radiuses");
527+
return false;
528+
}
529+
525530
if (!bearings.IsArray())
526531
{
527532
ThrowError(args.Env(), "Bearings must be an array of arrays of numbers");

src/nodejs/node_osrm.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,8 @@ Napi::Value Engine::route(const Napi::CallbackInfo &info)
349349
* var options = {
350350
* coordinates: [[13.388860,52.517037]],
351351
* number: 3,
352-
* bearings: [[0,20]]
352+
* bearings: [[0,20]],
353+
* radiuses: [null]
353354
* };
354355
* osrm.nearest(options, function(err, response) {
355356
* console.log(response.waypoints); // array of Waypoint objects

test/nodejs/route.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,7 @@ test('route: integer bearing values no longer supported', function(assert) {
424424
var options = {
425425
coordinates: two_test_coordinates,
426426
bearings: [200, 250],
427+
radiuses: [null],
427428
};
428429
assert.throws(function() { osrm.route(options, function(err, route) {}); },
429430
/Bearing must be an array of \[bearing, range\] or null/);
@@ -435,6 +436,7 @@ test('route: valid bearing values', function(assert) {
435436
var options = {
436437
coordinates: two_test_coordinates,
437438
bearings: [[200, 180], [250, 180]],
439+
radiuses: [null, null],
438440
};
439441
osrm.route(options, function(err, route) {
440442
assert.ifError(err);
@@ -448,38 +450,49 @@ test('route: valid bearing values', function(assert) {
448450
});
449451

450452
test('route: invalid bearing values', function(assert) {
451-
assert.plan(6);
453+
assert.plan(7);
452454
var osrm = new OSRM(monaco_path);
453455
assert.throws(function() { osrm.route({
454456
coordinates: two_test_coordinates,
455457
bearings: [[400, 180], [-250, 180]],
458+
radiuses: [null, null],
456459
}, function(err, route) {}) },
457460
/Bearing values need to be in range 0..360, 0..180/);
458461
assert.throws(function() { osrm.route({
459462
coordinates: two_test_coordinates,
460463
bearings: [[200], [250, 180]],
464+
radiuses: [null, null],
461465
}, function(err, route) {}) },
462466
/Bearing must be an array of/);
463467
assert.throws(function() { osrm.route({
464468
coordinates: two_test_coordinates,
465469
bearings: [[400, 109], [100, 720]],
470+
radiuses: [null, null],
466471
}, function(err, route) {}) },
467472
/Bearing values need to be in range 0..360, 0..180/);
468473
assert.throws(function() { osrm.route({
469474
coordinates: two_test_coordinates,
470475
bearings: 400,
476+
radiuses: [null],
471477
}, function(err, route) {}) },
472478
/Bearings must be an array of arrays of numbers/);
473479
assert.throws(function() { osrm.route({
474480
coordinates: two_test_coordinates,
475481
bearings: [[100, 100]],
482+
radiuses: [null, null],
476483
}, function(err, route) {}) },
477484
/Bearings array must have the same length as coordinates array/);
478485
assert.throws(function() { osrm.route({
479486
coordinates: two_test_coordinates,
480487
bearings: [Infinity, Infinity],
488+
radiuses: [null, null],
481489
}, function(err, route) {}) },
482490
/Bearing must be an array of \[bearing, range\] or null/);
491+
assert.throws(function() { osrm.route({
492+
coordinates: two_test_coordinates,
493+
bearings: [[0, 180], [0, 180]],
494+
}, function(err, route) {}) },
495+
/Bearings must be accompanied with radiuses/);
483496
});
484497

485498
test('route: routes Monaco with hints', function(assert) {

0 commit comments

Comments
 (0)