コード例 #1
0
 public function test_bounding_box_for_radius()
 {
     // Helsinki-Malmi airport (EFHF)
     $efhf = new midgardmvc_helper_location_spot(60.254558, 25.042828);
     // Get 20km bounding box
     $bbox = midgardmvc_helper_location_utils::get_bounding_box_for_radius($efhf, 20);
     $this->assertTrue(is_array($bbox));
     $this->assertEquals(count($bbox), 2);
     // Ensure the box limits are in right directions
     $this->assertEquals(midgardmvc_helper_location_utils::get_bearing($efhf, $bbox[0]), 'SW');
     $this->assertEquals(midgardmvc_helper_location_utils::get_bearing($efhf, $bbox[1]), 'NE');
     // Check that the distance to a corner is correct.
     // Note: using 2D trigonometry on 3D globe so numbers are not exact
     $distance1 = midgardmvc_helper_location_utils::get_distance($bbox[0], $efhf);
     $this->assertEquals(round($distance1), round(sqrt(pow(20, 2) + pow(20, 2))));
 }