Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,7 @@ harness = false
[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "docsrs"]

[patch.crates-io]
geo-types = { git = "https://github.com/georust/geo", branch = "main", package = "geo-types" }
geo-traits = { git = "https://github.com/georust/geo", branch = "main", package = "geo-traits" }
37 changes: 17 additions & 20 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,7 @@ use std::default::Default;
use std::fmt;
use std::str::FromStr;

use geo_traits::{
GeometryCollectionTrait, GeometryTrait, LineStringTrait, MultiLineStringTrait, MultiPointTrait,
MultiPolygonTrait, PointTrait, PolygonTrait,
};
use geo_traits::GeometryTrait;
use num_traits::{Float, Num, NumCast};

use crate::to_wkt::write_geometry;
Expand Down Expand Up @@ -474,13 +471,13 @@ impl<T: WktNum> GeometryTrait for Wkt<T> {

fn dim(&self) -> geo_traits::Dimensions {
match self {
Wkt::Point(geom) => PointTrait::dim(geom),
Wkt::LineString(geom) => LineStringTrait::dim(geom),
Wkt::Polygon(geom) => PolygonTrait::dim(geom),
Wkt::MultiPoint(geom) => MultiPointTrait::dim(geom),
Wkt::MultiLineString(geom) => MultiLineStringTrait::dim(geom),
Wkt::MultiPolygon(geom) => MultiPolygonTrait::dim(geom),
Wkt::GeometryCollection(geom) => GeometryCollectionTrait::dim(geom),
Wkt::Point(geom) => geom.dim(),
Wkt::LineString(geom) => geom.dim(),
Wkt::Polygon(geom) => geom.dim(),
Wkt::MultiPoint(geom) => geom.dim(),
Wkt::MultiLineString(geom) => geom.dim(),
Wkt::MultiPolygon(geom) => geom.dim(),
Wkt::GeometryCollection(geom) => geom.dim(),
}
}

Expand Down Expand Up @@ -556,13 +553,13 @@ impl<T: WktNum> GeometryTrait for &Wkt<T> {

fn dim(&self) -> geo_traits::Dimensions {
match self {
Wkt::Point(geom) => PointTrait::dim(geom),
Wkt::LineString(geom) => LineStringTrait::dim(geom),
Wkt::Polygon(geom) => PolygonTrait::dim(geom),
Wkt::MultiPoint(geom) => MultiPointTrait::dim(geom),
Wkt::MultiLineString(geom) => MultiLineStringTrait::dim(geom),
Wkt::MultiPolygon(geom) => MultiPolygonTrait::dim(geom),
Wkt::GeometryCollection(geom) => GeometryCollectionTrait::dim(geom),
Wkt::Point(geom) => geom.dim(),
Wkt::LineString(geom) => geom.dim(),
Wkt::Polygon(geom) => geom.dim(),
Wkt::MultiPoint(geom) => geom.dim(),
Wkt::MultiLineString(geom) => geom.dim(),
Wkt::MultiPolygon(geom) => geom.dim(),
Wkt::GeometryCollection(geom) => geom.dim(),
}
}

Expand Down Expand Up @@ -641,7 +638,7 @@ macro_rules! impl_specialization {
Self: 'b;

fn dim(&self) -> geo_traits::Dimensions {
geo_traits::Dimensions::Xy
self.dim.into()
}

fn as_type(
Expand Down Expand Up @@ -707,7 +704,7 @@ macro_rules! impl_specialization {
Self: 'b;

fn dim(&self) -> geo_traits::Dimensions {
geo_traits::Dimensions::Xy
self.dim.into()
}

fn as_type(
Expand Down
10 changes: 0 additions & 10 deletions src/types/geometrycollection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,16 +130,11 @@ where
}

impl<T: WktNum> GeometryCollectionTrait for GeometryCollection<T> {
type T = T;
type GeometryType<'a>
= &'a Wkt<T>
where
Self: 'a;

fn dim(&self) -> geo_traits::Dimensions {
self.dim.into()
}

fn num_geometries(&self) -> usize {
self.geoms.len()
}
Expand All @@ -150,16 +145,11 @@ impl<T: WktNum> GeometryCollectionTrait for GeometryCollection<T> {
}

impl<T: WktNum> GeometryCollectionTrait for &GeometryCollection<T> {
type T = T;
type GeometryType<'a>
= &'a Wkt<T>
where
Self: 'a;

fn dim(&self) -> geo_traits::Dimensions {
self.dim.into()
}

fn num_geometries(&self) -> usize {
self.geoms.len()
}
Expand Down
16 changes: 3 additions & 13 deletions src/types/linestring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,16 +108,11 @@ where
}

impl<T: WktNum> LineStringTrait for LineString<T> {
type T = T;
type CoordType<'a>
= &'a Coord<T>
where
Self: 'a;

fn dim(&self) -> geo_traits::Dimensions {
self.dim.into()
}

fn num_coords(&self) -> usize {
self.coords.len()
}
Expand All @@ -127,16 +122,11 @@ impl<T: WktNum> LineStringTrait for LineString<T> {
}
}

impl<T: WktNum> LineStringTrait for &LineString<T> {
type T = T;
type CoordType<'a>
impl<'a, T: WktNum> LineStringTrait for &'a LineString<T> {
type CoordType<'b>
= &'a Coord<T>
where
Self: 'a;

fn dim(&self) -> geo_traits::Dimensions {
self.dim.into()
}
Self: 'b;

fn num_coords(&self) -> usize {
self.coords.len()
Expand Down
18 changes: 4 additions & 14 deletions src/types/multilinestring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,41 +114,31 @@ where
}

impl<T: WktNum> MultiLineStringTrait for MultiLineString<T> {
type T = T;
type LineStringType<'a>
type InnerLineStringType<'a>
= &'a LineString<T>
where
Self: 'a;

fn dim(&self) -> geo_traits::Dimensions {
self.dim.into()
}

fn num_line_strings(&self) -> usize {
self.line_strings.len()
}

unsafe fn line_string_unchecked(&self, i: usize) -> Self::LineStringType<'_> {
unsafe fn line_string_unchecked(&self, i: usize) -> Self::InnerLineStringType<'_> {
self.line_strings.get_unchecked(i)
}
}

impl<T: WktNum> MultiLineStringTrait for &MultiLineString<T> {
type T = T;
type LineStringType<'a>
type InnerLineStringType<'a>
= &'a LineString<T>
where
Self: 'a;

fn dim(&self) -> geo_traits::Dimensions {
self.dim.into()
}

fn num_line_strings(&self) -> usize {
self.line_strings.len()
}

unsafe fn line_string_unchecked(&self, i: usize) -> Self::LineStringType<'_> {
unsafe fn line_string_unchecked(&self, i: usize) -> Self::InnerLineStringType<'_> {
self.line_strings.get_unchecked(i)
}
}
Expand Down
18 changes: 4 additions & 14 deletions src/types/multipoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,41 +112,31 @@ where
}

impl<T: WktNum> MultiPointTrait for MultiPoint<T> {
type T = T;
type PointType<'a>
type InnerPointType<'a>
= &'a Point<T>
where
Self: 'a;

fn dim(&self) -> geo_traits::Dimensions {
self.dim.into()
}

fn num_points(&self) -> usize {
self.points.len()
}

unsafe fn point_unchecked(&self, i: usize) -> Self::PointType<'_> {
unsafe fn point_unchecked(&self, i: usize) -> Self::InnerPointType<'_> {
self.points.get_unchecked(i)
}
}

impl<T: WktNum> MultiPointTrait for &MultiPoint<T> {
type T = T;
type PointType<'a>
type InnerPointType<'a>
= &'a Point<T>
where
Self: 'a;

fn dim(&self) -> geo_traits::Dimensions {
self.dim.into()
}

fn num_points(&self) -> usize {
self.points.len()
}

unsafe fn point_unchecked(&self, i: usize) -> Self::PointType<'_> {
unsafe fn point_unchecked(&self, i: usize) -> Self::InnerPointType<'_> {
self.points.get_unchecked(i)
}
}
Expand Down
18 changes: 4 additions & 14 deletions src/types/multipolygon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,41 +112,31 @@ where
}

impl<T: WktNum> MultiPolygonTrait for MultiPolygon<T> {
type T = T;
type PolygonType<'a>
type InnerPolygonType<'a>
= &'a Polygon<T>
where
Self: 'a;

fn dim(&self) -> geo_traits::Dimensions {
self.dim.into()
}

fn num_polygons(&self) -> usize {
self.polygons.len()
}

unsafe fn polygon_unchecked(&self, i: usize) -> Self::PolygonType<'_> {
unsafe fn polygon_unchecked(&self, i: usize) -> Self::InnerPolygonType<'_> {
self.polygons.get_unchecked(i)
}
}

impl<T: WktNum> MultiPolygonTrait for &MultiPolygon<T> {
type T = T;
type PolygonType<'a>
type InnerPolygonType<'a>
= &'a Polygon<T>
where
Self: 'a;

fn dim(&self) -> geo_traits::Dimensions {
self.dim.into()
}

fn num_polygons(&self) -> usize {
self.polygons.len()
}

unsafe fn polygon_unchecked(&self, i: usize) -> Self::PolygonType<'_> {
unsafe fn polygon_unchecked(&self, i: usize) -> Self::InnerPolygonType<'_> {
self.polygons.get_unchecked(i)
}
}
Expand Down
17 changes: 4 additions & 13 deletions src/types/point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,36 +102,27 @@ where
}

impl<T: WktNum> PointTrait for Point<T> {
type T = T;
type CoordType<'a>
= &'a Coord<T>
where
Self: 'a;

fn dim(&self) -> geo_traits::Dimensions {
self.dim.into()
}

fn coord(&self) -> Option<Self::CoordType<'_>> {
self.coord.as_ref()
}
}

impl<T: WktNum> PointTrait for &Point<T> {
type T = T;
type CoordType<'a>
impl<'a, T: WktNum> PointTrait for &'a Point<T> {
type CoordType<'b>
= &'a Coord<T>
where
Self: 'a;

fn dim(&self) -> geo_traits::Dimensions {
self.dim.into()
}
Self: 'b;

fn coord(&self) -> Option<Self::CoordType<'_>> {
self.coord.as_ref()
}
}

#[cfg(test)]
mod tests {
use super::{Coord, Point};
Expand Down
13 changes: 1 addition & 12 deletions src/types/polygon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ use geo_traits::PolygonTrait;

use crate::to_wkt::write_polygon;
use crate::tokenizer::PeekableTokens;
use crate::types::linestring::LineString;
use crate::types::Dimension;
use crate::types::{Dimension, LineString};
use crate::{FromTokens, Wkt, WktNum};
use std::fmt;
use std::str::FromStr;
Expand Down Expand Up @@ -114,16 +113,11 @@ where
}

impl<T: WktNum> PolygonTrait for Polygon<T> {
type T = T;
type RingType<'a>
= &'a LineString<T>
where
Self: 'a;

fn dim(&self) -> geo_traits::Dimensions {
self.dim.into()
}

fn exterior(&self) -> Option<Self::RingType<'_>> {
self.rings.first()
}
Expand All @@ -138,16 +132,11 @@ impl<T: WktNum> PolygonTrait for Polygon<T> {
}

impl<T: WktNum> PolygonTrait for &Polygon<T> {
type T = T;
type RingType<'a>
= &'a LineString<T>
where
Self: 'a;

fn dim(&self) -> geo_traits::Dimensions {
self.dim.into()
}

fn exterior(&self) -> Option<Self::RingType<'_>> {
self.rings.first()
}
Expand Down
Loading