/** * Release ownership of the loops of this polygon by appending them to the * given list. Resets the polygon to be empty. */ public function release(&$loops) { $loops = array_merge($loops, $this->loops); $this->loops = []; $bound = S2LatLngRect::emptya(); $this->hasHoles = false; $this->numVertices = 0; }
public function getRectBound() { if ($this->isEmpty()) { return S2LatLngRect::emptya(); } // Convert the axis to a (lat,lng) pair, and compute the cap angle. $axisLatLng = new S2LatLng($this->axis); $capAngle = $this->angle()->radians(); $allLongitudes = false; $lat = array(); $lng = array(); $lng[0] = -S2::M_PI; $lng[1] = S2::M_PI; // Check whether cap includes the south pole. $lat[0] = $axisLatLng->lat()->radians() - $capAngle; if ($lat[0] <= -S2::M_PI_2) { $lat[0] = -S2::M_PI_2; $allLongitudes = true; } // Check whether cap includes the north pole. $lat[1] = $axisLatLng->lat()->radians() + $capAngle; if ($lat[1] >= S2::M_PI_2) { $lat[1] = S2::M_PI_2; $allLongitudes = true; } if (!$allLongitudes) { // Compute the range of longitudes covered by the cap. We use the law // of sines for spherical triangles. Consider the triangle ABC where // A is the north pole, B is the center of the cap, and C is the point // of tangency between the cap boundary and a line of longitude. Then // C is a right angle, and letting a,b,c denote the sides opposite A,B,C, // we have sin(a)/sin(A) = sin(c)/sin(C), or sin(A) = sin(a)/sin(c). // Here "a" is the cap angle, and "c" is the colatitude (90 degrees // minus the latitude). This formula also works for negative latitudes. // // The formula for sin(a) follows from the relationship h = 1 - cos(a). $sinA = sqrt($this->height * (2 - $this->height)); $sinC = cos($axisLatLng->lat()->radians()); if ($sinA <= $sinC) { $angleA = asin($sinA / $sinC); $lng[0] = S2::IEEEremainder($axisLatLng->lng()->radians() - $angleA, 2 * S2::M_PI); $lng[1] = S2::IEEEremainder($axisLatLng->lng()->radians() + $angleA, 2 * S2::M_PI); } } return new S2LatLngRect(new R1Interval($lat[0], $lat[1]), new S1Interval($lng[0], $lng[1])); }