Require radiuses for bearings in nodejs bindings
This commit is contained in:
parent
f883555a42
commit
64bcc9235f
@ -111,7 +111,8 @@ var osrm = new OSRM('network.osrm');
|
||||
var options = {
|
||||
coordinates: [[13.388860,52.517037]],
|
||||
number: 3,
|
||||
bearings: [[0,20]]
|
||||
bearings: [[0,20]],
|
||||
radiuses: [null]
|
||||
};
|
||||
osrm.nearest(options, function(err, response) {
|
||||
console.log(response.waypoints); // array of Waypoint objects
|
||||
|
@ -522,6 +522,11 @@ inline bool argumentsToParameter(const Napi::CallbackInfo &args,
|
||||
if (bearings.IsEmpty())
|
||||
return false;
|
||||
|
||||
if (!obj.Has("radiuses")) {
|
||||
ThrowError(args.Env(), "Bearings must be accompanied with radiuses");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!bearings.IsArray())
|
||||
{
|
||||
ThrowError(args.Env(), "Bearings must be an array of arrays of numbers");
|
||||
|
@ -349,7 +349,8 @@ Napi::Value Engine::route(const Napi::CallbackInfo &info)
|
||||
* var options = {
|
||||
* coordinates: [[13.388860,52.517037]],
|
||||
* number: 3,
|
||||
* bearings: [[0,20]]
|
||||
* bearings: [[0,20]],
|
||||
* radiuses: [null]
|
||||
* };
|
||||
* osrm.nearest(options, function(err, response) {
|
||||
* console.log(response.waypoints); // array of Waypoint objects
|
||||
|
@ -424,6 +424,7 @@ test('route: integer bearing values no longer supported', function(assert) {
|
||||
var options = {
|
||||
coordinates: two_test_coordinates,
|
||||
bearings: [200, 250],
|
||||
radiuses: [null],
|
||||
};
|
||||
assert.throws(function() { osrm.route(options, function(err, route) {}); },
|
||||
/Bearing must be an array of \[bearing, range\] or null/);
|
||||
@ -435,6 +436,7 @@ test('route: valid bearing values', function(assert) {
|
||||
var options = {
|
||||
coordinates: two_test_coordinates,
|
||||
bearings: [[200, 180], [250, 180]],
|
||||
radiuses: [null, null],
|
||||
};
|
||||
osrm.route(options, function(err, route) {
|
||||
assert.ifError(err);
|
||||
@ -448,38 +450,49 @@ test('route: valid bearing values', function(assert) {
|
||||
});
|
||||
|
||||
test('route: invalid bearing values', function(assert) {
|
||||
assert.plan(6);
|
||||
assert.plan(7);
|
||||
var osrm = new OSRM(monaco_path);
|
||||
assert.throws(function() { osrm.route({
|
||||
coordinates: two_test_coordinates,
|
||||
bearings: [[400, 180], [-250, 180]],
|
||||
radiuses: [null, null],
|
||||
}, function(err, route) {}) },
|
||||
/Bearing values need to be in range 0..360, 0..180/);
|
||||
assert.throws(function() { osrm.route({
|
||||
coordinates: two_test_coordinates,
|
||||
bearings: [[200], [250, 180]],
|
||||
radiuses: [null, null],
|
||||
}, function(err, route) {}) },
|
||||
/Bearing must be an array of/);
|
||||
assert.throws(function() { osrm.route({
|
||||
coordinates: two_test_coordinates,
|
||||
bearings: [[400, 109], [100, 720]],
|
||||
radiuses: [null, null],
|
||||
}, function(err, route) {}) },
|
||||
/Bearing values need to be in range 0..360, 0..180/);
|
||||
assert.throws(function() { osrm.route({
|
||||
coordinates: two_test_coordinates,
|
||||
bearings: 400,
|
||||
radiuses: [null],
|
||||
}, function(err, route) {}) },
|
||||
/Bearings must be an array of arrays of numbers/);
|
||||
assert.throws(function() { osrm.route({
|
||||
coordinates: two_test_coordinates,
|
||||
bearings: [[100, 100]],
|
||||
radiuses: [null, null],
|
||||
}, function(err, route) {}) },
|
||||
/Bearings array must have the same length as coordinates array/);
|
||||
assert.throws(function() { osrm.route({
|
||||
coordinates: two_test_coordinates,
|
||||
bearings: [Infinity, Infinity],
|
||||
radiuses: [null, null],
|
||||
}, function(err, route) {}) },
|
||||
/Bearing must be an array of \[bearing, range\] or null/);
|
||||
assert.throws(function() { osrm.route({
|
||||
coordinates: two_test_coordinates,
|
||||
bearings: [[0, 180], [0, 180]],
|
||||
}, function(err, route) {}) },
|
||||
/Bearings must be accompanied with radiuses/);
|
||||
});
|
||||
|
||||
test('route: routes Monaco with hints', function(assert) {
|
||||
|
Loading…
Reference in New Issue
Block a user