Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove duplicate positions from polylines. #2196

Merged
merged 4 commits into from
Oct 16, 2014
Merged

Conversation

bagnell
Copy link
Contributor

@bagnell bagnell commented Oct 14, 2014

For #898.

@@ -151,7 +153,8 @@ define([
}
//>>includeEnd('debug');

if (this._loop && value.length > 2 && !Cartesian3.equals(value[0], value[value.length - 1])) {
value = PolylinePipeline.removeDuplicates(value);
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't we keep the passed in value and return it in the getter? The version with positions removed should be private. It's generally a bad idea to have a getter that doesn't return the value assigned by the setter.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree with @mramato. Perhaps modify PolylinePipeline.removeDuplicates (it's private) so it also returns a boolean if duplicates were removed. If they were, keep both the original and new version (as long as we need it to make the WebGL buffers). If no duplicates were removed, removeDuplicates doesn't even need to create a new array. Check other uses of the function to see if they were depending on it.

@bagnell
Copy link
Contributor Author

bagnell commented Oct 15, 2014

@mramato This is ready for another look.

@pjcozzi The polyline depends on a new array for polyline loops. It will push the first position on the back of the array.

@pjcozzi
Copy link
Contributor

pjcozzi commented Oct 15, 2014

@pjcozzi The polyline depends on a new array for polyline loops. It will push the first position on the back of the array.

Then just explicitly copy the array. I'm not sure that we should rely on that as a side effect of the cleanup function (even if I wrote it that way), especially if the common case is no duplicates and no loop and we therefore don't need to copy it.

@bagnell
Copy link
Contributor Author

bagnell commented Oct 16, 2014

@pjcozzi This is ready for another look.

var v1;

var containsDuplicates = false;
for (i = 1; i < length; ++i) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's optimize this by saving the index of the first duplicate and using that to start the loop below.

Copy link
Contributor

Choose a reason for hiding this comment

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

This could replace containsDuplicates by initializing it to -1.

@bagnell
Copy link
Contributor Author

bagnell commented Oct 16, 2014

@pjcozzi This is ready for another review.

@pjcozzi
Copy link
Contributor

pjcozzi commented Oct 16, 2014

Thanks.

Can you post a note to the forum: https://groups.google.com/forum/?fromgroups#!topic/cesium-dev/WrrR7fFFvVo

And probably update CHANGES.md in master.

pjcozzi added a commit that referenced this pull request Oct 16, 2014
Remove duplicate positions from polylines.
@pjcozzi pjcozzi merged commit 4e5e21c into master Oct 16, 2014
@pjcozzi pjcozzi deleted the polylineDuplicates branch October 16, 2014 21:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants