-
Notifications
You must be signed in to change notification settings - Fork 16
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 approach looks good so far!
src/database.cpp
Outdated
@@ -1,10 +1,19 @@ | |||
#include "database.hpp" | |||
|
|||
Database::Database() | |||
{ | |||
createRTree = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can set this already in the initializer list like you do below for the second constructor
src/nodejs_bindings.hpp
Outdated
@@ -34,6 +34,7 @@ class Annotator final : public Nan::ObjectWrap | |||
static Nan::Persistent<v8::Function> &constructor(); | |||
|
|||
/* Wrapping Annotator; both database and annotator do not provide default ctor: wrap in ptr */ | |||
bool createRTree; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe = false;
here, too. Otherwise this member attribute is uninitialized until you write to it.
src/nodejs_bindings.cpp
Outdated
{ | ||
coordinates = parsedCoords->BooleanValue(); | ||
} else return Nan::ThrowTypeError("Coordinates value should be a boolean"); // todo check what kind of error to throw | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there's an else branch missing here for the IsEmpty check - if Get fails the object key isn't there
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I think it would be OK to let the default behavior here stay, which is that we would effectively ignore an empty options object.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But it also allows for the mistake where the user accidentally spells the option's key wrong
new Annotator({'coordinate': true})
new Annotator({'coordinates': true})
if the key really should be coordinates
and is false
by default the first line ^ does not set it to true
but also does not error out.
src/nodejs_bindings.cpp
Outdated
if (parsedCoords->IsBoolean()) | ||
{ | ||
coordinates = parsedCoords->BooleanValue(); | ||
} else return Nan::ThrowTypeError("Coordinates value should be a boolean"); // todo check what kind of error to throw |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you're done with this changeset don't forget to clang-format
src/database.cpp
Outdated
void Database::compact() | ||
Database::Database() | ||
{ | ||
createRTree = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can set this already in the initializer list like you do below in the second constructor
src/database.cpp
Outdated
rtree = | ||
} | ||
|
||
void Database::build_rtree() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this function can be marked const
(also in header) because it does not modify the Database classes member attributes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See below, can't be marked as const :(
* Builds the RTree. Needs to be called after | ||
* all OSM data parsing has been added. | ||
*/ | ||
void build_rtree(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be marked const I think
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It ends up modifying the rtree
member of the Database object
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah sorry, you're right 👍
@danpat can you have a look at this today? Would be much appreciated! Also, let me know if you have ideas for more tests to add. |
👋 @danpat Could you make time to review this today? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes look good to me, this is a useful change when folks don't want to do a coordinate lookup.
@karenzshea can you do a quick memory profile with/without the rtree and see what kind of memory savings it creates? I never measured it when I initially built this, it'd be interesting to see just what % of the total belonged to the rtree.
src/nodejs_bindings.cpp
Outdated
} | ||
else | ||
{ | ||
return Nan::ThrowSyntaxError("Coordinates value should be a boolean"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be a type error - we're expecting a bool but it is not a bool
syntax error e.g. is v8 expecting each open parenthesis (
to be closed again )
but v8 was unable to find )
src/nodejs_bindings.cpp
Outdated
} | ||
catch (const RouteAnnotator::RtreeError &e) | ||
{ | ||
std::cerr << e.what() << std::endl; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The printing to cerr here needs to be removed; in the Node.js bindings you should not print to stdout; you're running inside v8, so using the Javascript-bound error features is all you are allowed to do here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😨
test/load.test.js
Outdated
var coords = [[-120.1872774,48.4715898],[-120.1882910,48.4725110]]; | ||
coordsFalse.annotateRouteFromLonLats(coords, (err) => { | ||
t.equals(err.toString(), 'Error: Annotator not created with coordinates support'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here and below - can we simply check for error if we check for the exact string then we have to keep it in sync in case the Node bindings slightly change the error message string.
Any chance this might land in master soon? |
45947fd
to
633655c
Compare
@quiqua hello:) I've pushed some outstanding changes and once tests are passing, I'll merge and publish a release. |
1c0a123
to
cfb9b68
Compare
cfb9b68
to
7a08403
Compare
Closes #19
To do:
Database
, rather than part ofcompact()
annotateRouteFromLonLats()
for RTree exists, return null or error if it doesn't