/** * Test rounding issues report by issue #10 * * @return NULL */ public function testRounding() { $originalPoints = array(48.000006, 2.000004, 48.00001, 2.0); $encoded = Polyline::encode($originalPoints); $this->assertEquals('a_~cH_seK??', $encoded); $decodedPoints = Polyline::decode($encoded); $this->assertTrue($decodedPoints[0] === $decodedPoints[2]); $this->assertTrue($decodedPoints[1] === $decodedPoints[3]); }
/** * Decode string and generate a full SVG document. * * @param string $encoded - Encoded polyline * * @return string - SVG document * * @uses DOMDocument */ public static function decodeToSVG($encoded) { // Create list of points $points = parent::decode($encoded); // Grab first pair list($x, $y) = self::_shiftPoint($points); // Path will need to start by moving to first coordinate. $path = sprintf('M %f %f L ', $x, $y); // Init bounding box's min & max. $minX = $maxX = $x; $minY = $maxY = $y; while ($points) { // This can be simplified with php-5.5's generators. list($x, $y) = self::_shiftPoint($points); $path .= sprintf('%f %f, ', $x, $y); // Grow MBR if ($x < $minX) { $minX = $x; } if ($y < $minY) { $minY = $y; } if ($x > $maxX) { $maxX = $x; } if ($y > $maxY) { $maxY = $y; } } // Close poylgon $path = rtrim($path, ', '); $path .= ' Z'; // Create viewBox from MBR points $mbr = sprintf("%f %f %f %f", $minX, $minY, abs($maxX - $minX), abs($maxY - $minY)); return self::_generateSVG($path, $mbr); }
/** * Test decoding of string to points * * @covers Polyline::decode * * @return NULL */ public function testDecode() { $expected = count($this->points) * 2; $this->assertCount($expected, Polyline::decode($this->encoded)); }