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

Add comments to BoolOps implementation. #1102

Merged
merged 7 commits into from
Jan 23, 2024
Merged

Conversation

andriyDev
Copy link
Contributor

  • I agree to follow the project's code of conduct.
  • I added an entry to CHANGES.md if knowledge of this change could be valuable to users.

This part of the code relies on a lot of assumptions that are not obviously until you really dig into the code, and have a lot of components that are not really clear (what's the difference between a Ring and a Snake?).

I've taken a stab at documenting these things and adding a few more inline comments to hopefully make it more clear to future readers.

There are a couple parts I still don't really understand, which I've marked as TODOs. Hopefully with a review, someone else might have more insight and we can document this even better. I will also likely expand the scope of comments as I make more progress (so far this is just assembly.rs, but I may try to capture more of the BoolOps).

@rmanoka
Copy link
Contributor

rmanoka commented Oct 29, 2023

Thanks @andriyDev ; the poor docs in this impl. is primarily my fault. We built this impl. incrementally, trying to fix up the floating point precision issues. I somewhat gave-up midway, as I couldn't figure how to provably fix the Martinez-Rueda family of algorithms to work with f64/f32.

That said, the Assembly module, iirc, does not have floating point precision issues as it doesn't actually need to break any segments. In fact, I think, we can even get this module to work without using GeoFloat at all (only GeoNum).

I'll do my best to review this in the next week or two.

@andriyDev
Copy link
Contributor Author

Hey no blame! The only way to make the code better is to work together :)

As far floating point issues, I had been working on my own Martinez-Rueda implementation and had also been struggling heavily with floating point issues myself. I've got an idea for why those are happening so I'll create a separate issue.

@andriyDev
Copy link
Contributor Author

I rebased onto main, and I added more comments for the bool_ops folder.

There are many changes we could make to simplify the code, but I think just documenting it is the first step.

In addition, this isn't the whole story - the main thing that's missing now is documenting CrossingsIter which mostly means going through Sweep with a fine-toothed comb.

idx: usize,
/// The region of this edge when the piece is going in the same direction as
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm pretty sure this is wrong. I can sorta understand the intent, but it doesn't make sense to me exactly what the check below means.

Copy link
Member

Choose a reason for hiding this comment

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

@rmanoka Can you shed any light on this?

@frewsxcv
Copy link
Member

@andriyDev This is still marked as draft. Is that intentional or is this ready for review?

@andriyDev
Copy link
Contributor Author

I'm happy to call this ready for review. More comments can always be another PR :)

@andriyDev andriyDev marked this pull request as ready for review December 19, 2023 04:10
@@ -85,14 +98,15 @@ impl<T: GeoFloat> RegionAssembly<T> {
parent_snake_idx = Some(
iter.prev_active(d)
.map(|(_, seg)| seg.snake_idx.get())
// TODO
Copy link
Member

Choose a reason for hiding this comment

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

Can you remove these TODOs?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can, but these TODOs really need an explanation. They make no sense to me. I tried to remove these defaults as well and tests started to fail, so clearly they are necessary but I don't have a logical reason how.

Copy link
Member

Choose a reason for hiding this comment

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

@rmanoka Do you recall why this .unwrap_or(0) is here?

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think the number here matters. If the expression is not Some(), then the "snake" will complete to an exterior ring, which doesn't need a parent idx. I tried verifying by setting random numbers inside .unwrap_or(), and tests seem to pass.

Copy link
Member

Choose a reason for hiding this comment

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

@andriyDev Are you OK with this explanation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, sorry, I'd lost track of this. I will update the comment tonight.

As an aside, I'd much prefer this case to be handled another way (if the id is unused we shouldn't need to unwrap it). But that's not the point of this PR, that kind of change should be another PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've added the explanation to the comments. I believe this is ready to go then (unless there are other concerns). :)

@urschrei
Copy link
Member

urschrei commented Jan 10, 2024

I'd really like to see this merged in order to facilitate further investigation into RegionAssembly's tendency to panic (see #1104 for a possible avenue to investigate). I think there's only one minor question left to be resolved!

@andriyDev
Copy link
Contributor Author

andriyDev commented Jan 10, 2024

I'd really like to see this merged in order to facilitate further investigation into RegionAssembly's tendency to panic (see #1104 for a possible avenue to investigate). I think there's only one minor question left to be resolved!

I would be shocked if this code is "responsible" for the panic. The RegionAssembly is fairly straightforward. What's more likely in my mind is that bad data is coming in from Proc or Spec in boolean ops since those are much more complex IMO. But that's just my speculation haha.

Regardless we (mostly I) should push this through to make progress on that.

@urschrei
Copy link
Member

Regardless we (mostly I) should push this through to make progress on that

Either that or outright replacement with your Martinez-Rueda implementation, but that's all a separate discussion.

@andriyDev
Copy link
Contributor Author

Either that or outright replacement with your Martinez-Rueda implementation, but that's all a separate discussion.

To be clear, mine is also riddled with panics LMAO. Maybe one day I'll find the "smoking gun".

Copy link
Member

@frewsxcv frewsxcv left a comment

Choose a reason for hiding this comment

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

@andriyDev thank you so much for adding these comments!

@frewsxcv frewsxcv enabled auto-merge January 23, 2024 00:27
@frewsxcv frewsxcv added this pull request to the merge queue Jan 23, 2024
Merged via the queue into georust:main with commit 4456a9d Jan 23, 2024
15 checks passed
@andriyDev andriyDev deleted the comments branch February 3, 2024 18:01
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.

4 participants