@@ -376,6 +376,51 @@ fn get_meta(path: &PathBuf) -> Result<Meta, FileError> {
376
376
} )
377
377
}
378
378
379
+ fn get_extent (
380
+ transformation : Option < & [ f64 ] > ,
381
+ origin : Option < & [ f64 ] > ,
382
+ full_resolution : & [ f64 ] ,
383
+ ( full_width_pixel, full_height_pixel) : ( u32 , u32 ) ,
384
+ path : & Path ,
385
+ ) -> Result < [ f64 ; 4 ] , CogError > {
386
+ if let Some ( matrix) = transformation {
387
+ let corners = [
388
+ [ 0 , 0 ] ,
389
+ [ 0 , full_height_pixel] ,
390
+ [ full_width_pixel, 0 ] ,
391
+ [ full_width_pixel, full_height_pixel] ,
392
+ ] ;
393
+ let transed = corners. map ( |pixel| {
394
+ let i = f64:: from ( pixel[ 0 ] ) ;
395
+ let j = f64:: from ( pixel[ 1 ] ) ;
396
+ let x = matrix[ 3 ] + ( matrix[ 0 ] * i) + ( matrix[ 1 ] * j) ;
397
+ let y = matrix[ 7 ] + ( matrix[ 4 ] * i) + ( matrix[ 5 ] * j) ;
398
+ ( x, y)
399
+ } ) ;
400
+ let mut min_x = transed[ 0 ] . 0 ;
401
+ let mut min_y = transed[ 1 ] . 1 ;
402
+ let mut max_x = transed[ 0 ] . 0 ;
403
+ let mut max_y = transed[ 1 ] . 1 ;
404
+ for ( x, y) in transed {
405
+ if x <= min_x {
406
+ min_x = x;
407
+ }
408
+ if y <= min_y {
409
+ min_y = y;
410
+ }
411
+ if x >= max_x {
412
+ max_x = x;
413
+ }
414
+ if y >= max_y {
415
+ max_y = y;
416
+ }
417
+ }
418
+ return Ok ( [ min_x, min_y, max_x, max_y] ) ;
419
+ } else {
420
+ return Err ( CogError :: GetExtentFailed ( path. to_path_buf ( ) ) ) ;
421
+ }
422
+ }
423
+
379
424
fn get_full_resolution (
380
425
pixel_scale : Option < & [ f64 ] > ,
381
426
transformation : Option < & [ f64 ] > ,
0 commit comments