Bounds.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4. * This file is part of the Geocoder package.
  5. * For the full copyright and license information, please view the LICENSE
  6. * file that was distributed with this source code.
  7. *
  8. * @license MIT License
  9. */
  10. namespace Geocoder\Model;
  11. use Geocoder\Assert;
  12. /**
  13. * @author William Durand <william.durand1@gmail.com>
  14. */
  15. final class Bounds
  16. {
  17. /**
  18. * @var float
  19. */
  20. private $south;
  21. /**
  22. * @var float
  23. */
  24. private $west;
  25. /**
  26. * @var float
  27. */
  28. private $north;
  29. /**
  30. * @var float
  31. */
  32. private $east;
  33. /**
  34. * @param float $south South bound, also min latitude
  35. * @param float $west West bound, also min longitude
  36. * @param float $north North bound, also max latitude
  37. * @param float $east East bound, also max longitude
  38. */
  39. public function __construct($south, $west, $north, $east)
  40. {
  41. Assert::notNull($south);
  42. Assert::notNull($west);
  43. Assert::notNull($north);
  44. Assert::notNull($east);
  45. $south = (float) $south;
  46. $north = (float) $north;
  47. $west = (float) $west;
  48. $east = (float) $east;
  49. Assert::latitude($south);
  50. Assert::latitude($north);
  51. Assert::longitude($west);
  52. Assert::longitude($east);
  53. $this->south = $south;
  54. $this->west = $west;
  55. $this->north = $north;
  56. $this->east = $east;
  57. }
  58. /**
  59. * Returns the south bound.
  60. *
  61. * @return float
  62. */
  63. public function getSouth(): float
  64. {
  65. return $this->south;
  66. }
  67. /**
  68. * Returns the west bound.
  69. *
  70. * @return float
  71. */
  72. public function getWest(): float
  73. {
  74. return $this->west;
  75. }
  76. /**
  77. * Returns the north bound.
  78. *
  79. * @return float
  80. */
  81. public function getNorth(): float
  82. {
  83. return $this->north;
  84. }
  85. /**
  86. * Returns the east bound.
  87. *
  88. * @return float
  89. */
  90. public function getEast(): float
  91. {
  92. return $this->east;
  93. }
  94. /**
  95. * Returns an array with bounds.
  96. *
  97. * @return array
  98. */
  99. public function toArray(): array
  100. {
  101. return [
  102. 'south' => $this->getSouth(),
  103. 'west' => $this->getWest(),
  104. 'north' => $this->getNorth(),
  105. 'east' => $this->getEast(),
  106. ];
  107. }
  108. }