$verySmall) { $lev = 0; while($dd < $zoomLevelBreaks[$lev]) { $lev++; } } return $lev; } function dpEncode($points) { global $verySmall; if(count($points) > 2) { $stack[] = array(0, count($points)-1); while(count($stack) > 0) { $current = array_pop($stack); $maxDist = 0; for($i = $current[0]+1; $i < $current[1]; $i++) { $temp = distance($points[$i], $points[$current[0]], $points[$current[1]]); if($temp > $maxDist) { $maxDist = $temp; $maxLoc = $i; if($maxDist > $absMaxDist) { $absMaxDist = $maxDist; } } } if($maxDist > $verySmall) { $dists[$maxLoc] = $maxDist; array_push($stack, array($current[0], $maxLoc)); array_push($stack, array($maxLoc, $current[1])); } } } $encodedPoints = createEncodings($points, $dists); $encodedLevels = encodeLevels($points, $dists, $absMaxDist); $encodedPointsLiteral = str_replace('\\',"\\\\",$encodedPoints); return array($encodedPoints, $encodedLevels, $encodedPointsLiteral); } function distance($p0, $p1, $p2) { if($p1[0] == $p2[0] && $p1[1] == $p2[1]) { $out = sqrt(pow($p2[0]-$p0[0],2) + pow($p2[1]-$p0[1],2)); } else { $u = (($p0[0]-$p1[0])*($p2[0]-$p1[0]) + ($p0[1]-$p1[1]) * ($p2[1]-$p1[1])) / (pow($p2[0]-$p1[0],2) + pow($p2[1]-$p1[1],2)); if($u <= 0) { $out = sqrt(pow($p0[0] - $p1[0],2) + pow($p0[1] - $p1[1],2)); } if($u >= 1) { $out = sqrt(pow($p0[0] - $p2[0],2) + pow($p0[1] - $p2[1],2)); } if(0 < $u && $u < 1) { $out = sqrt(pow($p0[0]-$p1[0]-$u*($p2[0]-$p1[0]),2) + pow($p0[1]-$p1[1]-$u*($p2[1]-$p1[1]),2)); } } return $out; } function encodeSignedNumber($num) { $sgn_num = $num << 1; if ($num < 0) { $sgn_num = ~($sgn_num); } return encodeNumber($sgn_num); } function createEncodings($points, $dists) { for($i=0; $i= 0x20) { $nextValue = (0x20 | ($num & 0x1f)) + 63; $encodeString .= chr($nextValue); $num >>= 5; } $finalValue = $num + 63; $encodeString .= chr($finalValue); return $encodeString; } ?>