本文整理汇总了PHP中Point类的典型用法代码示例。如果您正苦于以下问题:PHP Point类的具体用法?PHP Point怎么用?PHP Point使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Point类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: parseCoordinates
/**
* Filling property 'coordinates'
* @global string $egMultiMaps_CoordinatesSeparator
* @param string $coordinates
* @param string $service Name of map service
* @return boolean
*/
protected function parseCoordinates($coordinates, $service = null)
{
global $egMultiMaps_CoordinatesSeparator;
$array = explode($egMultiMaps_CoordinatesSeparator, $coordinates);
if ($service == 'leaflet' && count($array) == 1) {
$value = $array[0];
$coord = Geocoders::getCoordinates($value, $service, array('polygon' => true));
if ($coord !== false && is_array($coord['polygon'])) {
$this->coordinates = $coord['polygon'];
} else {
$this->errormessages[] = \wfMessage('multimaps-unable-parse-coordinates', $value)->escaped();
return false;
}
} else {
foreach ($array as $value) {
$point = new Point();
if ($point->parse($value, $service)) {
$this->coordinates[] = $point;
} else {
$this->errormessages[] = \wfMessage('multimaps-unable-parse-coordinates', $value)->escaped();
return false;
}
}
}
return true;
}
示例2: testInfinity
public function testInfinity()
{
$point = new Point(1, 2);
$this->assertFalse($point->isInfinity());
$point = new Point(PointInterface::INFINITY, PointInterface::INFINITY);
$this->assertTrue($point->isInfinity());
}
示例3: draw
/**
* draw line on map
*
* @param Map $map
*/
public function draw(Map $map)
{
$image = $map->getImage();
$startPointInPixels = $map->getPixelPointFromCoordinates($this->_startPoint->getLon(), $this->_startPoint->getLat());
$endPointInPixels = $map->getPixelPointFromCoordinates($this->_endPoint->getLon(), $this->_endPoint->getLat());
$this->_drawLine($image, $startPointInPixels['x'], $startPointInPixels['y'], $endPointInPixels['x'], $endPointInPixels['y']);
}
示例4: testShouldAssignXYCoordinates
/**
* @covers Imagine\Image\Point::getX
* @covers Imagine\Image\Point::getY
* @covers Imagine\Image\Point::in
*
* @dataProvider getCoordinates
*
* @param integer $x
* @param integer $y
* @param BoxInterface $box
* @param Boolean $expected
*/
public function testShouldAssignXYCoordinates($x, $y, BoxInterface $box, $expected)
{
$coordinate = new Point($x, $y);
$this->assertEquals($x, $coordinate->getX());
$this->assertEquals($y, $coordinate->getY());
$this->assertEquals($expected, $coordinate->in($box));
}
示例5: contains
/**
* @param Point $point
* @return bool
*/
public function contains(Point $point)
{
$vertices = $this->points->getPoints();
// Check if the point is inside the polygon or on the boundary
$intersections = 0;
for ($i = 1; $i < $this->points->getPoints()->count(); $i++) {
$vertex1 = $vertices->offsetGet($i - 1);
$vertex2 = $vertices->offsetGet($i);
// Check if point is on an horizontal polygon boundary
if ($vertex1->getY() == $vertex2->getY() && $vertex1->getY() == $point->getY() && $point->getX() > min($vertex1->getX(), $vertex2->getX()) && $point->getX() < max($vertex1->getX(), $vertex2->getX())) {
return true;
}
if ($point->getY() > min($vertex1->getY(), $vertex2->getY()) && $point->getY() <= max($vertex1->getY(), $vertex2->getY()) && $point->getX() <= max($vertex1->getX(), $vertex2->getX()) and $vertex1->getY() != $vertex2->getY()) {
$xinters = ($point->getY() - $vertex1->getY()) * ($vertex2->getX() - $vertex1->getX()) / ($vertex2->getY() - $vertex1->getY()) + $vertex1->getX();
// Check if point is on the polygon boundary (other than horizontal)
if ($xinters == $point->getX()) {
return true;
}
if ($vertex1->getX() == $vertex2->getX() || $point->getX() <= $xinters) {
$intersections++;
}
}
}
// If the number of edges we passed through is odd, then it's in the polygon.
if ($intersections % 2 != 0) {
return true;
} else {
return false;
}
}
示例6: testShouldMoveByGivenAmount
/**
* @covers Imagine\Image\Point::getX
* @covers Imagine\Image\Point::getY
* @covers Imagine\Image\Point::move
*
* @dataProvider getMoves
*
* @param integer $x
* @param integer $y
* @param integer $move
* @param integer $x1
* @param integer $y1
*/
public function testShouldMoveByGivenAmount($x, $y, $move, $x1, $y1)
{
$point = new Point($x, $y);
$shift = $point->move($move);
$this->assertEquals($x1, $shift->getX());
$this->assertEquals($y1, $shift->getY());
}
示例7: createFromCenterAndDistance
/**
* @param Point $center
* @param Distance $distance
*
* @return BoundingBox
* @author Maximilian Ruta <mr@xtain.net>
*/
public static function createFromCenterAndDistance(Point $center, Distance $distance)
{
$distanceInDegrees = $distance->getInGeographicDegrees() / 2;
$sw = new Point($center->getLatitude() - $distanceInDegrees, $center->getLongitude() - $distanceInDegrees);
$ne = new Point($center->getLatitude() + $distanceInDegrees, $center->getLongitude() + $distanceInDegrees);
return new BoundingBox($sw, $ne);
}
示例8: testInvalidPointY
/**
* test using an invalid y
**/
public function testInvalidPointY()
{
$point = new Point($this->VALID_X, $this->INVALID_Y);
// simply use the $INVALID_IP and an exception will be thrown
$point->setX($this->VALID_X);
$point->setY($this->INVALID_Y);
}
示例9: distance
/**
* @param Point $place1
* @param Point $place2
*
* @return Distance
* @author Maximilian Ruta <mr@xtain.net>
*/
public static function distance(Point $place1, Point $place2)
{
$theta = $place1->getLongitude() - $place2->getLongitude();
$dist = sin(deg2rad($place1->getLatitude())) * sin(deg2rad($place2->getLatitude())) + cos(deg2rad($place1->getLatitude())) * cos(deg2rad($place2->getLatitude())) * cos(deg2rad($theta));
$dist = acos($dist);
$dist = rad2deg($dist);
return new Distance($dist);
}
示例10: testSetGetPoint
public function testSetGetPoint()
{
$point = new Point();
$point->setLat("-23.529366");
$point->setLng("-47.467117");
$this->place->setPoint($point);
$this->assertEquals("-23.529366,-47.467117", (string) $this->place->getPoint());
}
示例11: testSubstract_SubstractPointIsGreaterThanMyPoint
/**
* @test
*/
public function testSubstract_SubstractPointIsGreaterThanMyPoint()
{
$substractPoint = 11;
try {
$point = new Point(10);
$point->substract($substractPoint);
} catch (Exception $ex) {
return;
}
$this->fail('例外が発生しなかったよー');
}
示例12: __construct
/**
* Constructor.
*
* @param float[][]|Point[] $positions
* @param CoordinateResolutionSystem|BoundingBox $arg,...
*/
public function __construct(array $positions)
{
$this->coordinates = array_map(function ($point) {
if (!$point instanceof Point) {
$point = new Point($point);
}
return $point->getCoordinates();
}, $positions);
if (func_num_args() > 1) {
$this->setOptionalConstructorArgs(array_slice(func_get_args(), 1));
}
}
示例13: add
/**
* 添加一个楼盘到数据库
* @param $premises Array(name, type, description, project_id, state, area, structure, lng, lat, zoom)
* @return bool 是否成功
*/
public function add($premises)
{
$ret = false;
$point = new Point();
$point_id = (int) $point->add($premises['lng'], $premises['lat'], $premises['zoom']);
$mysql = new MysqlAccess();
if ($point_id > 0) {
$sql = "insert into premises(`name`, `description`, `point_id`, `project_id`) " . "values('{$premises['name']}', '{$premises['description']}', {$point_id}, " . "{$premises['project_id']})";
$mysql->runSql($sql);
$ret = true;
}
return $ret;
}
示例14: getCartographicDistance
/**
* @param Point $point
* @return float
*
* thanks to http://stackoverflow.com/questions/7672759/how-to-calculate-distance-from-lat-long-in-php
*/
public function getCartographicDistance(Point $point)
{
$earthRadius = 3958.75;
$dLat = deg2rad($point->getLatitude() - $this->latitude);
$dLng = deg2rad($point->getLongitude() - $this->longitude);
$a = sin($dLat / 2) * sin($dLat / 2) + cos(deg2rad($this->latitude)) * cos(deg2rad($point->getLatitude())) * sin($dLng / 2) * sin($dLng / 2);
$c = 2 * atan2(sqrt($a), sqrt(1 - $a));
$dist = $earthRadius * $c;
// from miles to km
$meterConversion = 1.609344;
$geopointDistance = $dist * $meterConversion;
return round($geopointDistance, 0);
}
示例15: add
/**
* 添加person
*/
public function add($person)
{
$ret = false;
$point = new Point();
$now_id = (int) $point->add($person['now']['lng'], $person['now']['lat'], $person['now']['zoom']);
$want_id = (int) $point->add($person['want']['lng'], $person['want']['lat'], $person['want']['zoom']);
$mysql = new MysqlAccess();
if ($now_id > 0 && $want_id > 0) {
$sql = "insert into person(`name`, `now`, `want`, `state`, `description`) values " . "('{$person['name']}', {$now_id}, {$want_id}, '{$person['state']}', '{$person['description']}')";
$mysql->runSql($sql);
$ret = true;
}
return $ret;
}