feat: Custom viewshed polygon reconstructor - #67
Conversation
60f7aac to
d343bc7
Compare
At higher angle counts a traditional polygon unioning of all the polar segments suffers from O(N²). For example, even in Rust a 3600 angled viewshed takes ~20s to create its GeoJSON. And many minutes in browser JS. Therefore we have to design an entirely new algorithm that takes advantage of the fact that we are only ever adding new pieces to the growing viewshed in a very specific way. Namely we only ever add polar segments, that are always contained within the arc of a single angle, onto the _side_ of a polygon. This returns polygon reconstruction to a ~200ms for 3600 angled viewsheds.
d343bc7 to
ac0d147
Compare
|
Benchmark viewshed is now pixel-perfect with the existing one. Though note that the file size is slightly smaller due to a tidier algorithm. |
ryan-berger
left a comment
There was a problem hiding this comment.
I'm going to leave this for some changes responses, and dig into the algorithm a lot heavier tomorrow
Adds the following lints: unreachable_pub = "warn" redundant_pub_crate = "allow" This enforces the practice of explicitly defining visibility. Therefore, if a symbol isn't truly public to the outside world then it should be qualified with `pub(crate)`, `pub(super)`, etc. This is slightly more verbose but helps reasoning about API surfaces and also safeguards against unexpected symbols becoming public when parent visibility is changed.
aab2a56 to
7db051b
Compare
| } | ||
|
|
||
| /// Join a final polygon to either itself or a starting polygon. | ||
| fn join_final_polygon( |
There was a problem hiding this comment.
This code is nearly identical to join_segment in the next.rs.
The only difference I can see is how maybe_joining_polygon is constructed, and maybe base_polygon?
To me this says that there is some incorrect abstraction here. There should be a function that does finds the start/end pair you are looking for, only referencing its parameters and not behind a &mut self
There was a problem hiding this comment.
Now that we have the openings iterator, these functions look quite different now.
There was a problem hiding this comment.
Things have changed and I think this isn't a problem anymore
And other review improvemnts
And other improvements from review.
7db051b to
dfec260
Compare
ryan-berger
left a comment
There was a problem hiding this comment.
Less comments, but getting close
This prepares for compiling this code to WASM.
Successfully used in the browser.


At higher angle counts a traditional polygon unioning of all the polar segments suffers from O(N²). For example, even in Rust a 3600 angled viewshed takes ~20s to create its GeoJSON. And many minutes in browser JS.
Therefore we have to design an entirely new algorithm that takes advantage of the fact that we are only ever adding new pieces to the growing viewshed in a very specific way. Namely we only ever add polar segments, that are always contained within the arc of a single angle, onto the side of a polygon. This returns polygon reconstruction to
200ms80ms for 3600 angled viewsheds. There's actually huuuuge amount of room for speeding up this approach, but seeing as its already so much faster than the old method, this is good enough for now.TODO:
Apologies, this is rather big PR to review. Most of the changes are hidden in collapsed file views in the Github Diff view.