-
Notifications
You must be signed in to change notification settings - Fork 192
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split core geo types into new geo-types crate.
- Loading branch information
Showing
43 changed files
with
441 additions
and
303 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
/target | ||
/Cargo.lock | ||
**/target | ||
**/Cargo.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,2 @@ | ||
[package] | ||
name = "geo" | ||
description = "Geospatial primitives and algorithms" | ||
version = "0.8.2" | ||
authors = ["Corey Farwell <coreyf@rwell.org>"] | ||
license = "MIT/Apache-2.0" | ||
repository = "https://github.com/georust/rust-geo" | ||
documentation = "https://docs.rs/geo/" | ||
readme = "README.md" | ||
keywords = ["gis", "geo", "geography", "geospatial"] | ||
|
||
[badges] | ||
travis-ci = { repository = "georust/rust-geo" } | ||
|
||
[dependencies] | ||
num-traits = "0.2" | ||
serde = "1.0" | ||
serde_derive = "1.0" | ||
spade = "1.3.0" | ||
failure = "0.1.1" | ||
postgis = { version = "0.5", optional = true } | ||
proj-sys = { version = "0.6.1", optional = true } | ||
libc = { version = "0.2.39", optional = true } | ||
|
||
[features] | ||
default = [] | ||
postgis-integration = ["postgis"] | ||
proj = ["proj-sys", "libc"] | ||
|
||
[dev-dependencies] | ||
approx = "0.1.1" | ||
|
||
[package.metadata.docs.rs] | ||
features = ["postgis"] | ||
[workspace] | ||
members = ["geo", "geo-types"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
[package] | ||
name = "geo-types" | ||
version = "0.1.0" | ||
authors = ["Corey Farwell <coreyf@rwell.org>"] | ||
license = "MIT/Apache-2.0" | ||
repository = "https://github.com/georust/rust-geo" | ||
documentation = "https://docs.rs/geo-types/" | ||
readme = "../README.md" | ||
keywords = ["gis", "geo", "geography", "geospatial"] | ||
description = "Geospatial primitive data types" | ||
|
||
[dependencies] | ||
num-traits = "0.2" | ||
serde = { version = "1", optional = true, features = ["derive"] } | ||
spade = { version = "1.3", optional = true } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
// FIXME: everything in this file is copy/paste from the 'geo' crate. ideally we | ||
// wouldn't have this duplication | ||
|
||
use num_traits::{Float, ToPrimitive}; | ||
use ::{Point, Line, CoordinateType}; | ||
|
||
pub trait EuclideanDistance<T, Rhs = Self> { | ||
fn euclidean_distance(&self, rhs: &Rhs) -> T; | ||
} | ||
|
||
fn line_segment_distance<T>(point: &Point<T>, start: &Point<T>, end: &Point<T>) -> T | ||
where | ||
T: Float + ToPrimitive, | ||
{ | ||
if start == end { | ||
return point.euclidean_distance(start); | ||
} | ||
let dx = end.x() - start.x(); | ||
let dy = end.y() - start.y(); | ||
let r = ((point.x() - start.x()) * dx + (point.y() - start.y()) * dy) / (dx.powi(2) + dy.powi(2)); | ||
if r <= T::zero() { | ||
return point.euclidean_distance(start); | ||
} | ||
if r >= T::one() { | ||
return point.euclidean_distance(end); | ||
} | ||
let s = ((start.y() - point.y()) * dx - (start.x() - point.x()) * dy) / (dx * dx + dy * dy); | ||
s.abs() * (dx * dx + dy * dy).sqrt() | ||
} | ||
|
||
impl<T> EuclideanDistance<T, Point<T>> for Point<T> | ||
where | ||
T: Float, | ||
{ | ||
fn euclidean_distance(&self, p: &Point<T>) -> T { | ||
let (dx, dy) = (self.x() - p.x(), self.y() - p.y()); | ||
dx.hypot(dy) | ||
} | ||
} | ||
|
||
impl<T> EuclideanDistance<T, Point<T>> for Line<T> | ||
where | ||
T: Float, | ||
{ | ||
fn euclidean_distance(&self, point: &Point<T>) -> T { | ||
line_segment_distance(point, &self.start, &self.end) | ||
} | ||
} | ||
|
||
|
||
pub trait BoundingBox<T: CoordinateType> { | ||
type Output; | ||
|
||
fn bbox(&self) -> Self::Output; | ||
} | ||
|
||
impl<T> BoundingBox<T> for Line<T> | ||
where | ||
T: CoordinateType, | ||
{ | ||
type Output = Bbox<T>; | ||
|
||
fn bbox(&self) -> Self::Output { | ||
let a = self.start; | ||
let b = self.end; | ||
let (xmin, xmax) = if a.x() <= b.x() { | ||
(a.x(), b.x()) | ||
} else { | ||
(b.x(), a.x()) | ||
}; | ||
let (ymin, ymax) = if a.y() <= b.y() { | ||
(a.y(), b.y()) | ||
} else { | ||
(b.y(), a.y()) | ||
}; | ||
Bbox { | ||
xmin: xmin, | ||
xmax: xmax, | ||
ymin: ymin, | ||
ymax: ymax, | ||
} | ||
} | ||
} | ||
|
||
#[derive(PartialEq, Clone, Copy, Debug)] | ||
pub struct Bbox<T> | ||
where | ||
T: CoordinateType, | ||
{ | ||
pub xmin: T, | ||
pub xmax: T, | ||
pub ymin: T, | ||
pub ymax: T, | ||
} |
Oops, something went wrong.