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

more legible geo-types debug output (WKT-ish) #1302

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

michaelkirk
Copy link
Member

@michaelkirk michaelkirk commented Jan 16, 2025

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

FIXES #564

I've wanted this for a long time! Inevitably for any project using geo I end up pulling in some other crate to produce debug output (usually wkt). The writing portion of wkt is pretty short (parsing is a little trickier) which is why I opted to copy the logic rather than relying on the wkt crate or something.

Note: Most of the output is valid WKT, but not all of it is.
For example, there is no RECT or TRIANGLE type in standard WKT.

And there are certain invalid representations you can make in geo that
are not valid WKT, e.g. a polygon with interiors but no exterior. I'm not sure if it's valid WKT, but we need to print something meaningful, in this case: POLYGON(EMPTY,(1 2,2 4)).

@michaelkirk michaelkirk force-pushed the mkirk/debug-wkt branch 2 times, most recently from 429674b to 9688830 Compare January 16, 2025 22:37
FIXES #564

Note: Most of the output is valid WKT, but not all of it is.
For example, there is no RECT or TRIANGLE type in standard WKT.

And there are certain invalid representations you can make in geo that
are not valid WKT, but for a debug output format we still need to print
*something*

e.g. a polygon with interiors but no exterior: `POLYGON(EMPTY,(1 2,2 4))`
#[cfg(feature = "std")]
#[cfg(test)]
mod tests {
use super::*;
Copy link
Member Author

Choose a reason for hiding this comment

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

The tests are pretty comprehensive, and the best place to see what's what.


let rect = Rect::new((3, 4), (1, 2));
// output is always (min, max)
assert_eq!("RECT(1 2,3 4)", format!("{rect:?}"));
Copy link
Member Author

Choose a reason for hiding this comment

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

Here's an example of output that's not actually WKT, but I think it's still intuitive.

@urschrei
Copy link
Member

urschrei commented Jan 16, 2025

I think "don't let the perfect be the enemy of the good" is the right approach here w/r/t/ validity. If it's easy to get 95 % of debug output straight into TestBuilder (etc), and the other 5 % requires some light search and replace, that's still a huge improvement.

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.

Write custom, more succinct, debug output for all geometries in geo-types
2 participants