]> git.street.me.uk Git - andy/gpx.git/blob - src/libgpx/tracksegment.php
Add ability to read track types
[andy/gpx.git] / src / libgpx / tracksegment.php
1 <?php
2 /**
3  * tracksegment.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
25 namespace libgpx;
26
27 /**
28  * A GPX trkseg type.
29  *
30  * @author Andy Street <andy@street.me.uk>
31  */
32 class TrackSegment implements Geographic
33 {
34
35   /**
36    * A list of track points.
37    *
38    * @var TypedDoublyLinkedList (Point)
39    */
40   protected $points;
41
42   /**
43    * A list of XML snippets describing unsupported data.
44    *
45    * @var TypedDoublyLinkedList (string)
46    */
47   protected $extensions;
48
49   /**
50    * Fetch an ordered list of points that defines this track segment.
51    *
52    * @param boolean $create Create the list if it does not already exist.
53    * @return TypedDoublyLinkedList|null A list points.
54    */
55   public function getPoints(bool $create = true)
56   {
57     if ($create && $this->points === null)
58       $this->points = new TypedDoublyLinkedList('libgpx\Point');
59     return $this->points;
60   }
61
62   /**
63    * Fetch a list of XML strings that describe unsupported elements.
64    *
65    * @param boolean $create Create the list if it does not already exist.
66    * @return TypedDoublyLinkedList|null A list of XML strings.
67    */
68   public function getExtensions(bool $create = true)
69   {
70     if ($create && $this->extensions === null)
71       $this->extensions = new TypedDoublyLinkedList('string');
72     return $this->extensions;
73   }
74
75   /**
76    * Fetch a bounding box that covers the feature.
77    *
78    * @return Bounds|null A bounding box covering the extent of the feature or
79    *         null if not applicable.
80    */
81   public function getBounds()
82   {
83     $result = null;
84     if ($this->points !== null) {
85       foreach ($this->points as $point) {
86         $bounds = $point->getBounds();
87         $result = ($result === null ? $bounds : $result->extend($bounds));
88       }
89     }
90     return $result;
91   }
92
93 }