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

Implement 3D and Measure support for geo-types only #797

Closed
wants to merge 9 commits into from

Commits on Apr 21, 2022

  1. Implement 3D and Measure support for geo-types only

    This PR includes georust#772 and georust#812
    
    ---
    
    This PR focuses on `geo-types` only. This is a part of georust#742.
    
    This PR changes the underlying geo-type data structures to support 3D data and measurement values (M and Z values). The PR attempts to cause relatively minor disruptions to the existing users (see breaking changes below). My knowledge of the actual geo algorithms is limited, so please ping me for any specific algo change.
    
    ## geo-types restructuring
    All geo type structs have been renamed from `Foo<T>(...)` to `Foo<T, Z=NoValue, M=NoValue>(...)`, and several type aliases were added:
    
    ```rust
    // old
    pub struct LineString<T: CoordNum>(pub Vec<Coordinate<T>>);
    
    // new
    pub struct LineString<T: CoordNum, Z: ZCoord=NoValue, M: Measure=NoValue>(pub Vec<Coordinate<T, Z, M>>);
    
    pub type LineStringM<T, M=T> = LineString<T, NoValue, M>;
    pub type LineString3D<T> = LineString<T, T, NoValue>;
    pub type LineString3DM<T, M=T> = LineString<T, T, M>;
    ```
    
    ## NoValue magic
    `NoValue` is an empty struct that behaves just like a number. It supports all math and comparison operations. This means that a `Z` or `M` value can be manipulated without checking if it is actually there.  This code works for Z and M being either a number or a NoValue:
    
    ```rust
    pub struct NoValue;
    
    impl<T: CoordNum, Z: ZCoord, M: Measure> Sub for Coordinate<T, Z, M> {
        type Output = Self;
    
        fn sub(self, rhs: Self) -> Self {
            coord! {
                x: self.x - rhs.x,
                y: self.y - rhs.y,
                z: self.z - rhs.z,
                m: self.m - rhs.m,
            }
        }
    }
    ```
    
    ## Variant algorithm implementations
    Function implementations can keep just the original 2D `<T>` variant, or add support for 3D `<Z>` and/or the Measure `<M>`. The above example works for all combinations of objects. This function only works for 2D objects with and without the Measure.
    
    ```rust
    impl<T: CoordNum, M: Measure> Line<T, NoValue, M> {
        /// Calculate the slope (Δy/Δx).
        pub fn slope(&self) -> T {
            self.dy() / self.dx()
        }
    }
    ```
    
    ## Breaking changes
    * It is no longer possible to create Coordinate with just `x` and `y` values using implicit tuple constructor. Use `coord!` instead.
    nyurik committed Apr 21, 2022
    Configuration menu
    Copy the full SHA
    d16ca12 View commit details
    Browse the repository at this point in the history
  2. Removed custom Measure and ZCoord traits

    This simplifies the design a bit, by using the same `CoordNum` everywhere. `NoValue` can now be used anywhere, making it possible to define `Coordinate<NoValue>` -- an empty value.
    nyurik committed Apr 21, 2022
    Configuration menu
    Copy the full SHA
    db989f6 View commit details
    Browse the repository at this point in the history

Commits on Apr 22, 2022

  1. Configuration menu
    Copy the full SHA
    fc998b3 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    ec62c59 View commit details
    Browse the repository at this point in the history
  3. fix changes doc

    nyurik committed Apr 22, 2022
    Configuration menu
    Copy the full SHA
    193fc31 View commit details
    Browse the repository at this point in the history

Commits on May 6, 2022

  1. Configuration menu
    Copy the full SHA
    c7832a7 View commit details
    Browse the repository at this point in the history
  2. fix rect build

    nyurik committed May 6, 2022
    Configuration menu
    Copy the full SHA
    b064892 View commit details
    Browse the repository at this point in the history

Commits on Jun 8, 2022

  1. Configuration menu
    Copy the full SHA
    01fc095 View commit details
    Browse the repository at this point in the history

Commits on Jun 22, 2022

  1. Apply suggestions from code review

    Co-authored-by: Corey Farwell <coreyf@rwell.org>
    nyurik and frewsxcv authored Jun 22, 2022
    Configuration menu
    Copy the full SHA
    0ea63b5 View commit details
    Browse the repository at this point in the history