~ubuntu-branches/ubuntu/saucy/fgfs-atlas/saucy

« back to all changes in this revision

Viewing changes to src/FlightTrack.cxx

  • Committer: Bazaar Package Importer
  • Author(s): Ove Kaaven
  • Date: 2006-03-31 13:37:25 UTC
  • Revision ID: james.westby@ubuntu.com-20060331133725-h671cls8c2a2vpwv
Tags: upstream-0.3.0
ImportĀ upstreamĀ versionĀ 0.3.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*-------------------------------------------------------------------------
 
2
  FlightTrack.cxx
 
3
 
 
4
  Written by Per Liedman, started July 2000.
 
5
 
 
6
  Copyright (C) 2000 Per Liedman, liedman@home.se
 
7
 
 
8
  This program is free software; you can redistribute it and/or modify
 
9
  it under the terms of the GNU General Public License as published by
 
10
  the Free Software Foundation; either version 2 of the License, or
 
11
  (at your option) any later version.
 
12
 
 
13
  This program is distributed in the hope that it will be useful,
 
14
  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
  GNU General Public License for more details.
 
17
 
 
18
  You should have received a copy of the GNU General Public License
 
19
  along with this program; if not, write to the Free Software
 
20
  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
21
  ---------------------------------------------------------------------------*/
 
22
 
 
23
#include "FlightTrack.hxx"
 
24
#include <math.h>
 
25
 
 
26
FlightTrack::FlightTrack( unsigned int max_buffer ) : 
 
27
  max_buffer(max_buffer) {
 
28
  // Nothing here yet.
 
29
}
 
30
 
 
31
FlightTrack::~FlightTrack() {
 
32
  for (list<FlightData*>::iterator i = track.begin(); i != track.end(); i++) {
 
33
    delete *i;
 
34
  }
 
35
}
 
36
 
 
37
void FlightTrack::clear() {
 
38
  while (!track.empty()) {
 
39
    delete *(track.begin());
 
40
    track.pop_front();
 
41
  }
 
42
}
 
43
 
 
44
void FlightTrack::addPoint( FlightData *data ) {
 
45
  // TOLERANCE is set to 1 arc second
 
46
  static const float TOLERANCE = SG_DEGREES_TO_RADIANS / 3600.0f;
 
47
 
 
48
  float lastlat, lastlon;
 
49
 
 
50
  if (!track.empty()) {
 
51
    FlightData *last;
 
52
    last = track.back();
 
53
    lastlat = last->lat;
 
54
    lastlon = last->lon;
 
55
  } else {
 
56
    lastlat = -99.0f;
 
57
    lastlon = -99.0f;
 
58
  }
 
59
 
 
60
  if (fabs(lastlat - data->lat) > TOLERANCE || 
 
61
      fabs(lastlon - data->lon) > TOLERANCE) {
 
62
    if (track.size() > max_buffer) {
 
63
      delete track.front();
 
64
      track.pop_front();
 
65
    }
 
66
 
 
67
    track.push_back(data);
 
68
  }
 
69
}
 
70
 
 
71
void FlightTrack::firstPoint() {
 
72
  track_pos = track.begin();
 
73
}
 
74
 
 
75
FlightData *FlightTrack::getNextPoint() {
 
76
  if (track_pos != track.end()) {
 
77
    return *(track_pos++);
 
78
  } else {
 
79
    return NULL;
 
80
  }
 
81
}