Skip to content

Commit 2051517

Browse files
authored
feat: Add sedona-geo-traits-ext to sedona-db (#194)
This is part of the forked dependency elimination plan: #165. This PR depends on #193. This PR moves geo-traits-ext from wherobots/geo to sedona-db and renamed it to sedona-geo-traits-ext. Currently, it is a standalone crate and can be compiled using `cd rust/sedona-geo-traits-ext && cargo build`. We'll update the Cargo.toml files in the final step to make it live.
1 parent abcd140 commit 2051517

File tree

19 files changed

+3098
-2
lines changed

19 files changed

+3098
-2
lines changed

Cargo.lock

Lines changed: 8 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
[package]
18+
name = "sedona-geo-traits-ext"
19+
version = "0.2.0"
20+
authors = ["Apache Sedona <[email protected]>"]
21+
license = "Apache-2.0"
22+
homepage = "https://github.com/apache/sedona-db"
23+
repository = "https://github.com/apache/sedona-db"
24+
description = "geo-traits extended for implementing generic algorithms"
25+
readme = "README.md"
26+
edition = "2021"
27+
28+
[workspace]
29+
30+
[dependencies]
31+
geo-traits = "0.3.0"
32+
geo-types = "0.7.17"
33+
num-traits = { version = "0.2", default-features = false, features = ["libm"] }
34+
wkb = "0.9.1"
35+
byteorder = "1"
36+
37+
[dev-dependencies]
38+
wkt = "0.14.0"
39+
rstest = "0.24.0"
40+
41+
[patch.crates-io]
42+
wkb = { git = "https://github.com/georust/wkb.git", rev = "130eb0c2b343bc9299aeafba6d34c2a6e53f3b6a" }
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<!-- Licensed to the Apache Software Foundation (ASF) under one
2+
or more contributor license agreements. See the NOTICE file
3+
distributed with this work for additional information
4+
regarding copyright ownership. The ASF licenses this file
5+
to you under the Apache License, Version 2.0 (the
6+
"License"); you may not use this file except in compliance
7+
with the License. You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing,
12+
software distributed under the License is distributed on an
13+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
KIND, either express or implied. See the License for the
15+
specific language governing permissions and limitations
16+
under the License. -->
17+
18+
# Geo-Traits Extended
19+
20+
This crate extends the `geo-traits` crate with additional traits and
21+
implementations. The goal is to provide a set of traits that are useful for
22+
implementing algorithms in `geo-generic-alg` crate. Most of the methods are
23+
inspired by the `geo-types` crate, but are implemented as traits for the
24+
`geo-traits` types. Some methods returns concrete types defined in `geo-types`,
25+
these methods are only for computing tiny, intermediate results during
26+
algorithm execution. By adding methods in `geo-types` to `geo-traits-ext`,
27+
we can port algorithms in `geo` crate for concrete `geo-types` types to generic
28+
`geo-traits-ext` types more easily.
29+
30+
`geo-traits-ext` traits also has an associated `Tag` type to workaround the
31+
single orphan rule in Rust. For instance, we cannot write blanket `AreaTrait`
32+
implementations for both `LineStringTrait` and `PolygonTrait` because we
33+
cannot show that there would be no type implementing both `LineStringTrait` and
34+
`PolygonTrait`. By adding an associated `Tag` type, we can write blanket
35+
implementations for `AreaTrait<LineStringTag>` and `AreaTrait<PolygonTag>`, since
36+
`AreaTrait<LineStringTag>` and `AreaTrait<PolygonTag>` are different types.
37+
Please refer to the source code of `sedona-geo-generic-alg` for more details.
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
//! Extend CoordTrait traits for the `geo-traits` crate
18+
19+
use geo_traits::{CoordTrait, UnimplementedCoord};
20+
use geo_types::{Coord, CoordNum};
21+
22+
use crate::{CoordTag, GeoTraitExtWithTypeTag};
23+
24+
/// Extension methods that bridge [`CoordTrait`] with concrete `geo-types` helpers.
25+
pub trait CoordTraitExt: CoordTrait + GeoTraitExtWithTypeTag<Tag = CoordTag>
26+
where
27+
<Self as CoordTrait>::T: CoordNum,
28+
{
29+
#[inline]
30+
/// Converts this coordinate into the concrete [`geo_types::Coord`].
31+
fn geo_coord(&self) -> Coord<Self::T> {
32+
Coord {
33+
x: self.x(),
34+
y: self.y(),
35+
}
36+
}
37+
}
38+
39+
impl<T> CoordTraitExt for Coord<T>
40+
where
41+
T: CoordNum,
42+
{
43+
fn geo_coord(&self) -> Coord<T> {
44+
*self
45+
}
46+
}
47+
48+
impl<T: CoordNum> GeoTraitExtWithTypeTag for Coord<T> {
49+
type Tag = CoordTag;
50+
}
51+
52+
impl<T> CoordTraitExt for &Coord<T>
53+
where
54+
T: CoordNum,
55+
{
56+
fn geo_coord(&self) -> Coord<T> {
57+
**self
58+
}
59+
}
60+
61+
impl<T: CoordNum> GeoTraitExtWithTypeTag for &Coord<T> {
62+
type Tag = CoordTag;
63+
}
64+
65+
impl<T> CoordTraitExt for UnimplementedCoord<T> where T: CoordNum {}
66+
67+
impl<T: CoordNum> GeoTraitExtWithTypeTag for UnimplementedCoord<T> {
68+
type Tag = CoordTag;
69+
}

0 commit comments

Comments
 (0)