11use std:: ops:: Add ;
22
33use crate :: geo_traits:: {
4- GeometryCollectionTrait , GeometryTrait , GeometryType , LineStringTrait , MultiLineStringTrait ,
5- MultiPointTrait , MultiPolygonTrait , PointTrait , PolygonTrait , RectTrait ,
4+ CoordTrait , GeometryCollectionTrait , GeometryTrait , GeometryType , LineStringTrait ,
5+ MultiLineStringTrait , MultiPointTrait , MultiPolygonTrait , PointTrait , PolygonTrait , RectTrait ,
66} ;
77use geo:: { Coord , Rect } ;
88
@@ -61,10 +61,10 @@ impl BoundingRect {
6161 }
6262 }
6363
64- pub fn add_point ( & mut self , point : & impl PointTrait < T = f64 > ) {
65- let x = point . x ( ) ;
66- let y = point . y ( ) ;
67- let z = point . nth ( 2 ) ;
64+ pub fn add_coord ( & mut self , coord : & impl CoordTrait < T = f64 > ) {
65+ let x = coord . x ( ) ;
66+ let y = coord . y ( ) ;
67+ let z = coord . nth ( 2 ) ;
6868
6969 if x < self . minx {
7070 self . minx = x;
@@ -91,9 +91,15 @@ impl BoundingRect {
9191 }
9292 }
9393
94+ pub fn add_point ( & mut self , point : & impl PointTrait < T = f64 > ) {
95+ if let Some ( coord) = point. coord ( ) {
96+ self . add_coord ( & coord) ;
97+ }
98+ }
99+
94100 pub fn add_line_string ( & mut self , line_string : & impl LineStringTrait < T = f64 > ) {
95- for coord in line_string. points ( ) {
96- self . add_point ( & coord) ;
101+ for coord in line_string. coords ( ) {
102+ self . add_coord ( & coord) ;
97103 }
98104 }
99105
@@ -129,15 +135,18 @@ impl BoundingRect {
129135 }
130136
131137 pub fn add_geometry ( & mut self , geometry : & impl GeometryTrait < T = f64 > ) {
138+ use GeometryType :: * ;
139+
132140 match geometry. as_type ( ) {
133- GeometryType :: Point ( g) => self . add_point ( g) ,
134- GeometryType :: LineString ( g) => self . add_line_string ( g) ,
135- GeometryType :: Polygon ( g) => self . add_polygon ( g) ,
136- GeometryType :: MultiPoint ( g) => self . add_multi_point ( g) ,
137- GeometryType :: MultiLineString ( g) => self . add_multi_line_string ( g) ,
138- GeometryType :: MultiPolygon ( g) => self . add_multi_polygon ( g) ,
139- GeometryType :: GeometryCollection ( g) => self . add_geometry_collection ( g) ,
140- GeometryType :: Rect ( g) => self . add_rect ( g) ,
141+ Point ( g) => self . add_point ( g) ,
142+ LineString ( g) => self . add_line_string ( g) ,
143+ Polygon ( g) => self . add_polygon ( g) ,
144+ MultiPoint ( g) => self . add_multi_point ( g) ,
145+ MultiLineString ( g) => self . add_multi_line_string ( g) ,
146+ MultiPolygon ( g) => self . add_multi_polygon ( g) ,
147+ GeometryCollection ( g) => self . add_geometry_collection ( g) ,
148+ Rect ( g) => self . add_rect ( g) ,
149+ Triangle ( _) | Line ( _) => todo ! ( ) ,
141150 }
142151 }
143152
@@ -151,8 +160,8 @@ impl BoundingRect {
151160 }
152161
153162 pub fn add_rect ( & mut self , rect : & impl RectTrait < T = f64 > ) {
154- self . add_point ( & rect. lower ( ) ) ;
155- self . add_point ( & rect. upper ( ) ) ;
163+ self . add_coord ( & rect. min ( ) ) ;
164+ self . add_coord ( & rect. max ( ) ) ;
156165 }
157166
158167 pub fn update ( & mut self , other : & BoundingRect ) {
@@ -183,24 +192,24 @@ impl Add for BoundingRect {
183192
184193impl RectTrait for BoundingRect {
185194 type T = f64 ;
186- type ItemType < ' a > = Coord ;
195+ type CoordType < ' a > = Coord ;
187196
188- fn dim ( & self ) -> crate :: geo_traits:: Dimension {
197+ fn dim ( & self ) -> crate :: geo_traits:: Dimensions {
189198 if self . minz ( ) . is_some ( ) && self . maxz ( ) . is_some ( ) {
190- crate :: geo_traits:: Dimension :: XYZ
199+ crate :: geo_traits:: Dimensions :: Xyz
191200 } else {
192- crate :: geo_traits:: Dimension :: XY
201+ crate :: geo_traits:: Dimensions :: Xy
193202 }
194203 }
195204
196- fn lower ( & self ) -> Self :: ItemType < ' _ > {
205+ fn min ( & self ) -> Self :: CoordType < ' _ > {
197206 Coord {
198207 x : self . minx ,
199208 y : self . miny ,
200209 }
201210 }
202211
203- fn upper ( & self ) -> Self :: ItemType < ' _ > {
212+ fn max ( & self ) -> Self :: CoordType < ' _ > {
204213 Coord {
205214 x : self . maxx ,
206215 y : self . maxy ,
0 commit comments