/** * @covers MultiMaps\Bounds::__get */ public function test__get() { $point = new Point(123, 456); $this->object->extend(array($point)); $this->assertEquals($this->object->ne, $this->object->sw); $this->assertEquals($this->object->ne, $this->object->center); $this->assertEquals($this->object->ne, $point); $this->assertNull($this->object->tralala); }
/** * Add circle to map * @param string $value * @return boolean */ public function addElementCircle($value) { $return = true; $stringscircle = explode($GLOBALS['egMultiMaps_SeparatorItems'], $value); foreach ($stringscircle as $circlevalue) { if (trim($circlevalue) == '') { continue; } $circle = new Circle(); if (!$circle->parse($circlevalue, $this->classname)) { $return = false; $this->errormessages = array_merge($this->errormessages, $circle->getErrorMessages()); } if (!$circle->isValid()) { continue; } $this->circles[] = $circle; $circlescount = count($circle->pos); for ($index = 0; $index < $circlescount; $index++) { $ne = new Point($circle->pos[$index]->lat, $circle->pos[$index]->lon); $sw = new Point($circle->pos[$index]->lat, $circle->pos[$index]->lon); $ne->move($circle->radiuses[$index], $circle->radiuses[$index]); $sw->move(-$circle->radiuses[$index], -$circle->radiuses[$index]); $this->elementsBounds->extend(array($ne, $sw)); } } return $return; }
/** * Returns an array with data indexed by name. * * @return array */ public function toArray() { $adminLevels = []; foreach ($this->adminLevels as $adminLevel) { $adminLevels[$adminLevel->getLevel()] = ['name' => $adminLevel->getName(), 'code' => $adminLevel->getCode()]; } return array('latitude' => $this->getLatitude(), 'longitude' => $this->getLongitude(), 'bounds' => $this->bounds->toArray(), 'kind' => $this->kind, 'streetNumber' => $this->streetNumber, 'streetName' => $this->streetName, 'postalCode' => $this->postalCode, 'locality' => $this->locality, 'subLocality' => $this->subLocality, 'adminLevels' => $adminLevels, 'country' => $this->country->getName(), 'countryCode' => $this->country->getCode(), 'timezone' => $this->timezone); }
public static function castToBounds($input) { try { return Bounds::normalize($input); } catch (\InvalidArgumentException $e) { } try { $latLng = LatLng::normalize($input); return new Bounds($latLng, $latLng); } catch (\InvalidArgumentException $e) { } throw new \InvalidArgumentException(sprintf('Cannot cast to Bounds from input %s.', json_encode($input))); }
public function testPositiveNegative() { $min_x = -10; $min_y = -10; $max_x = -5; $max_y = -5; $b = new Bounds($max_x, $max_y, $min_x, $min_y); $this->assertEquals($min_x, $b->left); $this->assertEquals($min_y, $b->top); $this->assertEquals($max_x, $b->right); $this->assertEquals($max_y, $b->bottom); $this->assertEquals(5, $b->getWidth()); $this->assertEquals(5, $b->getHeight()); $this->assertTrue($b->contains(-9, -9)); $this->assertTrue($b->contains(-5, -10)); $this->assertFalse($b->contains(-1, 1)); }
function test_creation_from_circle() { $bounds = Bounds::from_point_and_radius(array(32.939829, -96.951176), 2.5); $inside = new LatLng(32.969527, -96.99015900000001); $outside = new LatLng(32.895155, -96.958444); $this->assertTrue($bounds->contains($inside)); $this->assertFalse($bounds->contains($outside)); }
private function extract_bounds_from_options(&$options) { if (array_key_exists('bounds', $options)) { $bounds = $options['bounds']; array_delete($options, 'bounds'); return Bounds::normalize($bounds); } return null; }
/** * @AjaxCallable=TRUE * @AjaxMethod=POST * @AjaxAsync=TRUE */ function load_pois() { $this->load->library('geo/Bounds'); $this->load->library('geo/LatLng'); $this->load->library('geo/Polygon'); $this->load->library('geo/Point'); $this->load->model('POIModel'); $sBounds = filter_input(INPUT_POST, 'bounds', FILTER_VALIDATE_FLOAT, FILTER_REQUIRE_ARRAY); $bounds = Bounds::deserialize($sBounds); return POIModel::load_by_bounds($bounds); }
/** * @param SimpleXMLElement $xml * @return Metadata * @throws InvalidGPXException */ public static function fromXML(SimpleXMLElement $xml) { $metadata = new Metadata(); if (!empty($xml->name)) { $metadata->setName((string) $xml->name[0]); } if (!empty($xml->desc)) { $metadata->setDescription((string) $xml->desc[0]); } if (!empty($xml->author)) { $metadata->setAuthor(Person::fromXML($xml->author[0])); } if (!empty($xml->copyright)) { $metadata->setCopyright(Copyright::fromXML($xml->copyright[0])); } if (!empty($xml->link)) { $links = []; foreach ($xml->link as $link) { array_push($links, Link::fromXML($link)); } $metadata->setLinks($links); } if (!empty($xml->time)) { $metadata->setTime(strtotime((string) $xml->time[0])); } if (!empty($xml->keywords)) { $metadata->setKeywords((string) $xml->keywords[0]); } if (!empty($xml->bounds)) { $metadata->setBounds(Bounds::fromXML($xml->bounds0[0])); } if (!empty($xml->extensions)) { $metadata->setExtensions(Extensions::fromXML($xml->extensions[0])); } return $metadata; }
/** * @param Bounds $bounds * @return Bounds */ public function union(Bounds $bounds) { $newBounds = $this->extend($bounds->getSouthWest()); return $newBounds->extend($bounds->getNorthEast()); }
private static function buildBoundsClause(Bounds $bounds) { $s = $bounds->s(); $w = $bounds->w(); $n = $bounds->n(); $e = $bounds->e(); if ($w > $e) { return "(`lat` < {$n} AND `lat` > {$s} AND (`lng` < {$e} OR `lng` > {$w}))"; } else { return "(`lat` < {$n} AND `lat` > {$s} AND `lng` < {$e} AND `lng` > {$w})"; } }
public function testNormalizeShouldThrowExceptionForInvalidObjectInput() { $this->setExpectedException('\\InvalidArgumentException', 'Cannot normalize Bounds from input {}.'); Bounds::normalize(new \stdClass()); }