11extern crate geo;
22
3- use self :: geo:: { Bbox , LineString , Point } ;
3+ use self :: geo:: { Coordinate , LineString , Point , Rect } ;
44use fallible_iterator:: FallibleIterator ;
55use postgres_protocol:: types;
66use std:: error:: Error ;
@@ -26,23 +26,21 @@ impl ToSql for Point<f64> {
2626 to_sql_checked ! ( ) ;
2727}
2828
29- impl < ' a > FromSql < ' a > for Bbox < f64 > {
29+ impl < ' a > FromSql < ' a > for Rect < f64 > {
3030 fn from_sql ( _: & Type , raw : & [ u8 ] ) -> Result < Self , Box < Error + Sync + Send > > {
31- let bbox = types:: box_from_sql ( raw) ?;
32- Ok ( Bbox {
33- xmin : bbox. lower_left ( ) . x ( ) ,
34- xmax : bbox. upper_right ( ) . x ( ) ,
35- ymin : bbox. lower_left ( ) . y ( ) ,
36- ymax : bbox. upper_right ( ) . y ( ) ,
31+ let rect = types:: box_from_sql ( raw) ?;
32+ Ok ( Rect {
33+ min : Coordinate { x : rect. lower_left ( ) . x ( ) , y : rect. lower_left ( ) . y ( ) , } ,
34+ max : Coordinate { x : rect. upper_right ( ) . x ( ) , y : rect. upper_right ( ) . y ( ) , } ,
3735 } )
3836 }
3937
4038 accepts ! ( BOX ) ;
4139}
4240
43- impl ToSql for Bbox < f64 > {
41+ impl ToSql for Rect < f64 > {
4442 fn to_sql ( & self , _: & Type , out : & mut Vec < u8 > ) -> Result < IsNull , Box < Error + Sync + Send > > {
45- types:: box_to_sql ( self . xmin , self . ymin , self . xmax , self . ymax , out) ;
43+ types:: box_to_sql ( self . min . x , self . min . y , self . max . x , self . max . y , out) ;
4644 Ok ( IsNull :: No )
4745 }
4846
@@ -53,7 +51,7 @@ impl ToSql for Bbox<f64> {
5351impl < ' a > FromSql < ' a > for LineString < f64 > {
5452 fn from_sql ( _: & Type , raw : & [ u8 ] ) -> Result < Self , Box < Error + Sync + Send > > {
5553 let path = types:: path_from_sql ( raw) ?;
56- let points = path. points ( ) . map ( |p| Point :: new ( p. x ( ) , p. y ( ) ) ) . collect ( ) ?;
54+ let points = path. points ( ) . map ( |p| Coordinate { x : p. x ( ) , y : p. y ( ) } ) . collect ( ) ?;
5755 Ok ( LineString ( points) )
5856 }
5957
@@ -63,7 +61,7 @@ impl<'a> FromSql<'a> for LineString<f64> {
6361impl ToSql for LineString < f64 > {
6462 fn to_sql ( & self , _: & Type , out : & mut Vec < u8 > ) -> Result < IsNull , Box < Error + Sync + Send > > {
6563 let closed = false ; // always encode an open path from LineString
66- types:: path_to_sql ( closed, self . 0 . iter ( ) . map ( |p| ( p. x ( ) , p. y ( ) ) ) , out) ?;
64+ types:: path_to_sql ( closed, self . 0 . iter ( ) . map ( |p| ( p. x , p. y ) ) , out) ?;
6765 Ok ( IsNull :: No )
6866 }
6967
0 commit comments