Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 38 additions & 0 deletions rust/sedona-geo-traits-ext/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
[package]
name = "sedona-geo-traits-ext"
version = "0.2.0"
authors = ["Apache Sedona <[email protected]>"]
license = "Apache-2.0"
homepage = "https://github.com/apache/sedona-db"
repository = "https://github.com/apache/sedona-db"
description = "geo-traits extended for implementing generic algorithms"
readme = "README.md"
edition = "2021"

[workspace]

[dependencies]
geo-traits = "0.3.0"
geo-types = "0.7.17"
num-traits = { version = "0.2", default-features = false, features = ["libm"] }
wkb = "0.9.1"
byteorder = "1"

[patch.crates-io]
wkb = { git = "https://github.com/georust/wkb.git", rev = "130eb0c2b343bc9299aeafba6d34c2a6e53f3b6a" }
37 changes: 37 additions & 0 deletions rust/sedona-geo-traits-ext/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<!-- Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License. -->

# Geo-Traits Extended

This crate extends the `geo-traits` crate with additional traits and
implementations. The goal is to provide a set of traits that are useful for
implementing algorithms in `geo-generic-alg` crate. Most of the methods are
inspired by the `geo-types` crate, but are implemented as traits for the
`geo-traits` types. Some methods returns concrete types defined in `geo-types`,
these methods are only for computing tiny, intermediate results during
algorithm execution. By adding methods in `geo-types` to `geo-traits-ext`,
we can port algorithms in `geo` crate for concrete `geo-types` types to generic
`geo-traits-ext` types more easily.

`geo-traits-ext` traits also has an associated `Tag` type to workaround the
single orphan rule in Rust. For instance, we cannot write blanket `AreaTrait`
implementations for both `LineStringTrait` and `PolygonTrait` because we
cannot show that there would be no type implementing both `LineStringTrait` and
`PolygonTrait`. By adding an associated `Tag` type, we can write blanket
implementations for `AreaTrait<LineStringTag>` and `AreaTrait<PolygonTag>`, since
`AreaTrait<LineStringTag>` and `AreaTrait<PolygonTag>` are different types.
Please refer to the source code of `geo-generic-alg` for more details.
69 changes: 69 additions & 0 deletions rust/sedona-geo-traits-ext/src/coord.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
//! Extend CoordTrait traits for the `geo-traits` crate

use geo_traits::{CoordTrait, UnimplementedCoord};
use geo_types::{Coord, CoordNum};

use crate::{CoordTag, GeoTraitExtWithTypeTag};

/// Extension methods that bridge [`CoordTrait`] with concrete `geo-types` helpers.
pub trait CoordTraitExt: CoordTrait + GeoTraitExtWithTypeTag<Tag = CoordTag>
where
<Self as CoordTrait>::T: CoordNum,
{
#[inline]
/// Converts this coordinate into the concrete [`geo_types::Coord`].
fn geo_coord(&self) -> Coord<Self::T> {
Coord {
x: self.x(),
y: self.y(),
}
}
}

impl<T> CoordTraitExt for Coord<T>
where
T: CoordNum,
{
fn geo_coord(&self) -> Coord<T> {
*self
}
}

impl<T: CoordNum> GeoTraitExtWithTypeTag for Coord<T> {
type Tag = CoordTag;
}

impl<T> CoordTraitExt for &Coord<T>
where
T: CoordNum,
{
fn geo_coord(&self) -> Coord<T> {
**self
}
}

impl<T: CoordNum> GeoTraitExtWithTypeTag for &Coord<T> {
type Tag = CoordTag;
}

impl<T> CoordTraitExt for UnimplementedCoord<T> where T: CoordNum {}

impl<T: CoordNum> GeoTraitExtWithTypeTag for UnimplementedCoord<T> {
type Tag = CoordTag;
}
Loading
Loading