~ubuntu-branches/ubuntu/warty/xplanet/warty

« back to all changes in this revision

Viewing changes to src/libprojection/ProjectionRectangular.cpp

  • Committer: Bazaar Package Importer
  • Author(s): LaMont Jones
  • Date: 2004-08-24 07:14:00 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20040824071400-2dr4qnjbjmm8z3ia
Tags: 1.0.6-1ubuntu1
Build-depend: libtiff4-dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <cmath>
 
2
using namespace std;
 
3
 
 
4
#include "ProjectionRectangular.h"
 
5
#include "xpUtil.h"
 
6
 
 
7
ProjectionRectangular::ProjectionRectangular(const int f, const int w,
 
8
                                             const int h) 
 
9
    : ProjectionBase (f, w, h),
 
10
      mapBounds_(false)
 
11
{
 
12
    isWrapAround_ = true;
 
13
 
 
14
    startLon_ = -M_PI + centerLon_;
 
15
    startLat_ = M_PI_2;
 
16
 
 
17
    delLat_ = M_PI/height_;
 
18
    delLon_ = TWO_PI/width_;
 
19
}
 
20
 
 
21
ProjectionRectangular::ProjectionRectangular(const int f, const int w, 
 
22
                                             const int h,
 
23
                                             const double startLat,
 
24
                                             const double startLon,
 
25
                                             const double mapHeight,
 
26
                                             const double mapWidth)
 
27
    : ProjectionBase (f, w, h), mapBounds_(true)
 
28
{
 
29
    startLon_ = startLon * f;
 
30
    startLat_ = startLat;
 
31
 
 
32
    delLat_ = mapHeight/height_;
 
33
    delLon_ = mapWidth/width_ * f;
 
34
}
 
35
 
 
36
bool
 
37
ProjectionRectangular::pixelToSpherical(const double x, const double y, 
 
38
                                        double &lon, double &lat)
 
39
{
 
40
    lon = (x + 0.5) * delLon_ + startLon_;
 
41
    lat = startLat_ - (y + 0.5) * delLat_;
 
42
    return(true);
 
43
}
 
44
 
 
45
bool
 
46
ProjectionRectangular::sphericalToPixel(double lon, double lat,
 
47
                                        double &x, double &y) const
 
48
{
 
49
    if (lon > M_PI) lon -= TWO_PI;
 
50
    else if (lon < -M_PI) lon += TWO_PI;
 
51
          
 
52
    x = (lon - startLon_)/delLon_;
 
53
 
 
54
    if (!mapBounds_)
 
55
    {
 
56
        if (x >= width_) 
 
57
            x -= width_;
 
58
        else if (x < 0) 
 
59
            x += width_;
 
60
    }
 
61
 
 
62
    y = (startLat_ - lat)/delLat_;
 
63
 
 
64
    if (!mapBounds_ && y >= height_) y = height_ - 1;
 
65
    
 
66
    return(true);
 
67
}
 
68