diff --git a/src/ewkb.rs b/src/ewkb.rs index ae325d6..147d5e9 100644 --- a/src/ewkb.rs +++ b/src/ewkb.rs @@ -15,14 +15,14 @@ use std::slice::Iter; // --- Structs for reading PostGIS geometries into -#[derive(PartialEq, Clone, Copy, Debug)] +#[derive(PartialEq, Clone, Copy, Debug, Default)] pub struct Point { pub x: f64, pub y: f64, pub srid: Option, } -#[derive(PartialEq, Clone, Copy, Debug)] +#[derive(PartialEq, Clone, Copy, Debug, Default)] pub struct PointZ { pub x: f64, pub y: f64, @@ -30,7 +30,7 @@ pub struct PointZ { pub srid: Option, } -#[derive(PartialEq, Clone, Copy, Debug)] +#[derive(PartialEq, Clone, Copy, Debug, Default)] pub struct PointM { pub x: f64, pub y: f64, @@ -38,7 +38,7 @@ pub struct PointM { pub srid: Option, } -#[derive(PartialEq, Clone, Copy, Debug)] +#[derive(PartialEq, Clone, Copy, Debug, Default)] pub struct PointZM { pub x: f64, pub y: f64, @@ -185,6 +185,12 @@ impl Point { } } +impl From<(f64, f64)> for Point { + fn from((x, y): (f64, f64)) -> Self { + Self::new(x, y, None) + } +} + impl postgis::Point for Point { fn x(&self) -> f64 { self.x @@ -214,6 +220,12 @@ impl PointZ { } } +impl From<(f64, f64, f64)> for PointZ { + fn from((x, y, z): (f64, f64, f64)) -> Self { + Self::new(x, y, z, None) + } +} + impl postgis::Point for PointZ { fn x(&self) -> f64 { self.x @@ -246,6 +258,12 @@ impl PointM { } } +impl From<(f64, f64, f64)> for PointM { + fn from((x, y, m): (f64, f64, f64)) -> Self { + Self::new(x, y, m, None) + } +} + impl postgis::Point for PointM { fn x(&self) -> f64 { self.x @@ -279,6 +297,12 @@ impl PointZM { } } +impl From<(f64, f64, f64, f64)> for PointZM { + fn from((x, y, z, m): (f64, f64, f64, f64)) -> Self { + Self::new(x, y, z, m, None) + } +} + impl postgis::Point for PointZM { fn x(&self) -> f64 { self.x diff --git a/src/twkb.rs b/src/twkb.rs index 9e9faf2..4254076 100644 --- a/src/twkb.rs +++ b/src/twkb.rs @@ -24,7 +24,7 @@ use std::io::prelude::*; use std::slice::Iter; use std::u8; -#[derive(PartialEq, Clone, Copy, Debug)] +#[derive(PartialEq, Clone, Copy, Debug, Default)] pub struct Point { pub x: f64, pub y: f64, // TODO: support for z, m @@ -200,7 +200,13 @@ fn read_varint64_as_f64(raw: &mut R, precision: i8) -> Result, _m: Option) -> Self { - Point { x: x, y: y } + Self { x: x, y: y } + } +} + +impl From<(f64, f64)> for Point { + fn from((x, y): (f64, f64)) -> Self { + Self { x, y } } }