Skip to content
This repository has been archived by the owner on Jun 8, 2024. It is now read-only.

fixed-start-and-end-trip #296

Merged
merged 2 commits into from
Feb 14, 2017
Merged

Conversation

ghoshkaj
Copy link
Member

@ghoshkaj ghoshkaj commented Feb 9, 2017

Addresses #294

@ghoshkaj ghoshkaj force-pushed the trip-with-fixed-start-and-end-points branch from 02dec87 to d5069de Compare February 13, 2017 12:20
@ghoshkaj
Copy link
Member Author

@freenerd would you please review this? I especially want your opinion on the way I've handled the errors coming from osrm-backend. I ended up using a simple equals message, instead of an error assertion because I couldn't get any of the error assertions to work with this kind of osrm-backend error: https://github.com/Project-OSRM/node-osrm/pull/296/files#diff-f2f7b3e695a783f368903f577c8f8036R207

Copy link
Member

@freenerd freenerd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good to me

docs/api.md Outdated

**Parameters**

- `options` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** Object literal containing parameters for the trip query.
- `options.roundtrip` **\[[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)]** Return route is a roundtrip. (optional, default `true`)
- `options.source` **\[[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)]** Return route starts at `any` or `first` coordinate. Can also be `first`. (optional, default `any`)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

first is in here double

docs/api.md Outdated

**Parameters**

- `options` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** Object literal containing parameters for the trip query.
- `options.roundtrip` **\[[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)]** Return route is a roundtrip. (optional, default `true`)
- `options.source` **\[[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)]** Return route starts at `any` or `first` coordinate. Can also be `first`. (optional, default `any`)
- `options.destination` **\[[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)]** Return route ends at `any` or `last` coordinate. Can also be `last`. (optional, default `any`)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

last is in here double

docs/api.md Outdated
- `options.steps` **\[[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)]** Return route steps for each route. (optional, default `false`)
- `options.annotations` **\[[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)]** Return annotations for each route leg. (optional, default `false`)
- `options.geometries` **\[[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)]** Returned route geometry format (influences overview
and per step). Can also be `geojson`. (optional, default `polyline`)
- `options.overview` **\[[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)]** Add overview geometry either `full`, `simplified` (optional, default `simplified`)
- `callback` **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)**

**Fixing Start and End Points**

It is possible to explicitely set the start or end coordinate of the trip. When source is set to `first`, the first coordinate is used as start coordinate of the trip in the output. When destination is set to `last`, the last coordinate will be used as destination of the trip in the returned output. If you specify `any`, any of the coordinates can be used as the first or last coordinate in the output.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

explicitly

| false | first | last | **yes** |
| false | first | any | no |
| false | any | last | no |
| false | any | any | no |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are our plans wrt. supporting the currently unsupported combinations? Is this getting checked for in code?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@daniel-j-h it gets checked for in the code and a NotImplemented error is returned if it is an unsupported combination.

docs/api.md Outdated
[13.374481201171875, 52.506191342034576]
],
source: first,
destination: last,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is first and last? Does this work or should it be "first" and "last"?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh you're right. Changed these to strings.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe run your example locally to check if it works? :)

@@ -733,6 +733,74 @@ argumentsToTripParameter(const Nan::FunctionCallbackInfo<v8::Value> &args,
return trip_parameters_ptr();
}

if (obj->Has(Nan::New("roundtrip").ToLocalChecked()))
{
auto roundtrip = obj->Get(Nan::New("roundtrip").ToLocalChecked());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here and below: what you can do instead of Has()+Get() is the following:

auto maybeRoundtrip = Nan::Get(..);
if (maybeRoundtrip.empty() || !maybeRoundtrip.ToLocalChecked()->IsBoolean) error();

Nan::Get returns you a Maybe type similar to boost::optional<T>.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to change it to the Get pattern but can't figure it out right now. But I'm going to leave this pattern as is for now as it is the pattern is used by the rest of the file. In a different PR, I can go through and convert all of them in one go.

return trip_parameters_ptr();
}

std::string source_str = *v8::String::Utf8Value(source);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you check for the ptr not being a nullptr?

Also please use Nan's string functions which are portable:
https://github.com/nodejs/nan/blob/master/doc/v8_misc.md

const Nan::Utf8String utf8str(source);
std::string s{*utf8str, *utf8str + utfstr.length()};

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again I tried to implement this but didn't manage to get it to work, but I'll leave this for now, as the pattern here is different from elsewhere in the rest of the file. This can be addressed in a refactor PR that changes the rest of the file as well.

@ghoshkaj ghoshkaj removed the request for review from chaupow February 13, 2017 15:05
@ghoshkaj ghoshkaj force-pushed the trip-with-fixed-start-and-end-points branch from 7ce81c2 to ed6c5c8 Compare February 13, 2017 16:15
@ghoshkaj ghoshkaj force-pushed the trip-with-fixed-start-and-end-points branch from ed6c5c8 to acd22ed Compare February 14, 2017 15:42
@springmeyer
Copy link

Looks like circle is failing with:

In file included from /Users/distiller/node-osrm/deps/osrm-backend-Debug/src/extractor/extraction_containers.cpp:12:
In file included from /Users/distiller/node-osrm/deps/osrm-backend-Debug/include/util/name_table.hpp:4:
/Users/distiller/node-osrm/deps/osrm-backend-Debug/include/util/indexed_data.hpp:93:82: error: invalid use of non-static data member 'offset'
        BOOST_ASSERT(data_offset <= std::numeric_limits<decltype(BlockReference::offset)>::max());
                                                                 ~~~~~~~~~~~~~~~~^~~~~~
/Users/distiller/node-osrm/mason_packages/headers/boost/1.63.0/include/boost/assert.hpp:53:45: note: expanded from macro 'BOOST_ASSERT'
#define BOOST_ASSERT(expr) (BOOST_LIKELY(!!(expr))? ((void)0): ::boost::assertion_failed(#expr, BOOST_CURRENT_FUNCTION, __FILE__, __LINE__))
                                            ^~~~
/Users/distiller/node-osrm/mason_packages/headers/boost/1.63.0/include/boost/config/compiler/clang.hpp:62:42: note: expanded from macro 'BOOST_LIKELY'
#define BOOST_LIKELY(x) __builtin_expect(x, 1)
                                         ^
/Users/distiller/node-osrm/deps/osrm-backend-Debug/include/util/indexed_data.hpp:270:32: note: in instantiation of function template specialization 'osrm::util::VariableGroupBlock<16, boost::basic_string_ref<char, std::__1::char_traits<char> > >::WriteBlockReference<unsigned long long, stxxl::vector_iterator<unsigned int, stxxl::RC, unsigned long long, long long, 2097152, stxxl::lru_pager<8>, 4> >' requested here
            data_size += block.WriteBlockReference(out, data_size, curr, next);
                               ^
/Users/distiller/node-osrm/deps/osrm-backend-Debug/src/extractor/extraction_containers.cpp:182:18: note: in instantiation of function template specialization 'osrm::util::IndexedData<osrm::util::VariableGroupBlock<16, boost::basic_string_ref<char, std::__1::char_traits<char> > > >::write<stxxl::vector_iterator<unsigned int, stxxl::RC, unsigned long long, long long, 2097152, stxxl::lru_pager<8>, 4>, stxxl::vector_iterator<unsigned char, stxxl::RC, unsigned long long, long long, 2097152, stxxl::lru_pager<8>, 4> >' requested here
    indexed_data.write(file, name_offsets.begin(), name_offsets.end(), name_char_data.begin());
                 ^
In file included from /Users/distiller/node-osrm/deps/osrm-backend-Debug/src/extractor/extraction_containers.cpp:12:
In file included from /Users/distiller/node-osrm/deps/osrm-backend-Debug/include/util/name_table.hpp:4:
/Users/distiller/node-osrm/deps/osrm-backend-Debug/include/util/indexed_data.hpp:96:70: error: invalid use of non-static data member 'offset'
        BlockReference refernce{static_cast<decltype(BlockReference::offset)>(data_offset), 0};
                                                     ~~~~~~~~~~~~~~~~^~~~~~
2 errors generated.

Per chat we are discussing disabling circle since we are still using travis OS X, but we should still address ^^. I think this is happening because we still use xcode: 7.3 on circle. The error would likely go away if we used xcode: 8.2 on circle. I think xcode 8 is needed for the kind of C++14 support osrm-backend uses. The actionable thing would be to add a check in osrm-backend to assert on the minimum xcode/osx version (perhaps cmake has an easy way to do this).

@ghoshkaj ghoshkaj merged commit 2cb902c into master Feb 14, 2017
@ghoshkaj ghoshkaj deleted the trip-with-fixed-start-and-end-points branch February 14, 2017 21:29
@springmeyer
Copy link

The error would likely go away if we used xcode: 8.2 on circle.

It did. Let's discuss next actions at Project-OSRM/osrm-backend#3719

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants