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

Separate constructors for different dimensions of coordinates #130

Open
frewsxcv opened this issue Jul 15, 2020 · 0 comments
Open

Separate constructors for different dimensions of coordinates #130

frewsxcv opened this issue Jul 15, 2020 · 0 comments
Labels

Comments

@frewsxcv
Copy link
Member

frewsxcv commented Jul 15, 2020

Have separate constructors if the caller wants to assume their data is a certain dimension. The hope is that the new constructors will be more performant since each coordinate doesn't require heap allocations. I'm not tied to these method names.

enum GeoJson<C> {
    Geometry(Geometry<C>),
    Feature(Feature<C>),
    FeatureCollection(FeatureCollection<C>),
}

impl<C> GeoJson<C> {
    /// Parse a string into `GeoJson`
    pub fn from_str(s: &str) -> Result<GeoJson<Vec<f32>>, Error> { ... }

    /// Parse a string into `GeoJson`. Coordinates are assumed to have two dimensions.
    /// If a non-two-dimensional coordinate is encountered, an error will be returned.
    pub fn from_str_2d(s: &str) -> Result<GeoJson<(f32, f32)>, Error> { ... }

    /// Parse a string into `GeoJson`. Coordinates are assumed to have three dimensions.
    /// If a non-three-dimensional coordinate is encountered, an error will be returned.
    pub fn from_str_3d(s: &str) -> Result<GeoJson<(f32, f32, f32)>, Error> { ... }
}

enum Value<C> {
    Point(C),
    MultiPoint(Vec<C>),
    ...
}
@frewsxcv frewsxcv changed the title Idea: Separate constructors for different dimensions of coordinates Separate constructors for different dimensions of coordinates Jul 15, 2020
@frewsxcv frewsxcv added the idea label Jul 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant