-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Conversation
@@ -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); |
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.
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.
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 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.
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. |
@pjcozzi This is ready for another look. |
var v1; | ||
|
||
var containsDuplicates = false; | ||
for (i = 1; i < length; ++i) { |
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.
Let's optimize this by saving the index of the first duplicate and using that to start the loop below.
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 could replace containsDuplicates
by initializing it to -1
.
@pjcozzi This is ready for another review. |
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. |
Remove duplicate positions from polylines.
For #898.