]> git.street.me.uk Git - andy/gpx.git/blame - src/libgpx/bounds.php
Fix: PeakStream fails to function correctly after the first file
[andy/gpx.git] / src / libgpx / bounds.php
CommitLineData
88564339
AS
1<?php
2/**
3 * bounds.php
4 *
5 * Copyright 2018 Andy Street <andy@street.me.uk>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
20 * MA 02110-1301, USA.
21 *
22 *
23 */
24
25namespace libgpx;
26
27/**
28 * A 2D rectangular bounding box.
29 *
30 * @author Andy Street <andy@street.me.uk>
31 */
32class Bounds
33{
34
35 /**
36 * Minimum latitude.
37 *
38 * @var float
39 */
40 protected $minlat;
41
42 /**
43 * Minimum longitude.
44 *
45 * @var float
46 */
47 protected $minlon;
48
49 /**
50 * Maximum latitude.
51 *
52 * @var float
53 */
54 protected $maxlat;
55
56 /**
57 * Maxumum longitude.
58 *
59 * @var float
60 */
61 protected $maxlon;
62
63 /**
64 * Create a new bounding box.
65 *
66 * @param float $minlat Minimum latitude.
67 * @param float $minlon Minimum longitude.
68 * @param float $maxlat Maximum latitude.
69 * @param float $maxlon Maximum longitude.
70 */
71 public function __construct(
72 float $minlat,
73 float $minlon,
74 float $maxlat,
75 float $maxlon
76 ) {
77 $this->minlat = $minlat;
78 $this->minlon = $minlon;
79 $this->maxlat = $maxlat;
80 $this->maxlon = $maxlon;
81 }
82
83 /**
84 * Fetch minimum latitude.
85 *
86 * @return float
87 */
88 public function getMinLat()
89 {
90 return $this->minlat;
91 }
92
93 /**
94 * Fetch minimum longitude.
95 *
96 * @return float
97 */
98 public function getMinLon()
99 {
100 return $this->minlon;
101 }
102
103 /**
104 * Fetch maximum latitude.
105 *
106 * @return float
107 */
108 public function getMaxLat()
109 {
110 return $this->maxlat;
111 }
112
113 /**
114 * Fetch maximum longitude.
115 *
116 * @return float
117 */
118 public function getMaxLon()
119 {
120 return $this->maxlon;
121 }
122
123 /**
124 * Extend bounding box to cover another bounding box.
125 *
126 * @param Bounds $bounds The bounding box to cover.
127 * @return void
128 */
129 public function extend(Bounds $bounds)
130 {
131 if ($bounds->minlat < $this->minlat) $this->minlat = $bounds->minlat;
132 if ($bounds->minlon < $this->minlon) $this->minlon = $bounds->minlon;
133 if ($bounds->maxlat > $this->maxlat) $this->maxlat = $bounds->maxlat;
134 if ($bounds->maxlon > $this->maxlon) $this->maxlon = $bounds->maxlon;
135 }
136
137}