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