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

Idea: Implement constraints on geometry types #56

Open
frewsxcv opened this issue Aug 7, 2016 · 5 comments
Open

Idea: Implement constraints on geometry types #56

frewsxcv opened this issue Aug 7, 2016 · 5 comments

Comments

@frewsxcv
Copy link
Member

frewsxcv commented Aug 7, 2016

Examples:

  • LineString: panics if fewer than two points
  • Polygon: panics if any rings has fewer than three points
  • Polygon should check if first+last points are the same?
  • Polygon should ensure interiors are inside exterior? Maybe not this is one as it might be expensive.
@TeXitoi
Copy link
Contributor

TeXitoi commented Aug 7, 2016

Checks that the inners don't intersect.

Checks that multi don't intersect.

@TeXitoi
Copy link
Contributor

TeXitoi commented Aug 7, 2016

Maybe that can be an algorithm "check" or something like that. ie optional.

@urschrei
Copy link
Member

urschrei commented Aug 9, 2016

Shapely will allow you to construct invalid Polygons (rings that cross each other, and touch at more than one point), but raises exceptions when they're used, presumably for performance reasons. Maybe a Valid trait that returns a bool, which could be checked by any methods implemented on the type.
How would the more straightforward constructors look? Something like

impl<T> LineString
where T: Float {
    pub fn new(v: Vec<T>) -> Result(LineString, _) {
        // Check that the vec contains at least two elements?
        // I have no idea what happens next
    }
}

?
(I've never written a "validating" constructor before, so I have no idea what I'm doing, really – if anyone's got some examples that would be great)

@frewsxcv
Copy link
Member Author

frewsxcv commented Aug 9, 2016

One example in std is CString::new which will fail if the bytes contain a null character (\0)

@frewsxcv
Copy link
Member Author

Opened an issue similar to this: #127

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants