Skip to content
This repository has been archived by the owner on Jul 19, 2023. It is now read-only.

Make rtree construction optional #21

Merged
merged 10 commits into from
Jan 29, 2018
Merged

Make rtree construction optional #21

merged 10 commits into from
Jan 29, 2018

Conversation

karenzshea
Copy link
Contributor

@karenzshea karenzshea commented Oct 2, 2017

Closes #19

To do:

  • Put RTree generation into a separate method of Database, rather than part of compact()
  • Add checks into annotateRouteFromLonLats() for RTree exists, return null or error if it doesn't
  • Add tests
  • Get review

Copy link
Contributor

@daniel-j-h daniel-j-h left a 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;
Copy link
Contributor

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

@@ -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;
Copy link
Contributor

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.

{
coordinates = parsedCoords->BooleanValue();
} else return Nan::ThrowTypeError("Coordinates value should be a boolean"); // todo check what kind of error to throw
}
Copy link
Contributor

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

Copy link
Contributor Author

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.

Copy link
Contributor

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.

if (parsedCoords->IsBoolean())
{
coordinates = parsedCoords->BooleanValue();
} else return Nan::ThrowTypeError("Coordinates value should be a boolean"); // todo check what kind of error to throw
Copy link
Contributor

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;
Copy link
Contributor

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()
Copy link
Contributor

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

Copy link
Contributor

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();
Copy link
Contributor

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

Copy link
Contributor Author

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

Copy link
Contributor

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 👍

@karenzshea karenzshea requested a review from danpat October 5, 2017 15:33
@karenzshea
Copy link
Contributor Author

@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.

@karenzshea
Copy link
Contributor Author

👋 @danpat Could you make time to review this today?

Copy link
Collaborator

@danpat danpat left a 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.

}
else
{
return Nan::ThrowSyntaxError("Coordinates value should be a boolean");
Copy link
Contributor

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 )

}
catch (const RouteAnnotator::RtreeError &e)
{
std::cerr << e.what() << std::endl;
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

😨

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');
Copy link
Contributor

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.

@quiqua
Copy link

quiqua commented Jan 11, 2018

Any chance this might land in master soon?
Is there something I could help with?

@karenzshea
Copy link
Contributor Author

@quiqua hello:) I've pushed some outstanding changes and once tests are passing, I'll merge and publish a release.

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